aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acpi/Kconfig36
-rw-r--r--drivers/acpi/Makefile5
-rw-r--r--drivers/acpi/acpi_lpss.c94
-rw-r--r--drivers/acpi/acpica/acglobal.h1
-rw-r--r--drivers/acpi/acpica/aclocal.h4
-rw-r--r--drivers/acpi/acpica/evgpe.c9
-rw-r--r--drivers/acpi/acpica/hwgpe.c53
-rw-r--r--drivers/acpi/acpica/utresrc.c2
-rw-r--r--drivers/acpi/acpica/utxface.c4
-rw-r--r--drivers/acpi/acpica/utxfinit.c11
-rw-r--r--drivers/acpi/battery.c4
-rw-r--r--drivers/acpi/device_pm.c4
-rw-r--r--drivers/acpi/internal.h6
-rw-r--r--drivers/acpi/osl.c8
-rw-r--r--drivers/acpi/pmic/intel_pmic.c354
-rw-r--r--drivers/acpi/pmic/intel_pmic.h25
-rw-r--r--drivers/acpi/pmic/intel_pmic_crc.c211
-rw-r--r--drivers/acpi/pmic/intel_pmic_xpower.c268
-rw-r--r--drivers/acpi/processor_idle.c14
-rw-r--r--drivers/acpi/property.c551
-rw-r--r--drivers/acpi/scan.c214
-rw-r--r--drivers/acpi/sleep.c2
-rw-r--r--drivers/acpi/tables.c68
-rw-r--r--drivers/acpi/utils.c5
-rw-r--r--drivers/acpi/video.c18
-rw-r--r--drivers/ata/ahci.c4
-rw-r--r--drivers/ata/sata_fsl.c2
-rw-r--r--drivers/atm/solos-pci.c2
-rw-r--r--drivers/base/Makefile2
-rw-r--r--drivers/base/power/clock_ops.c85
-rw-r--r--drivers/base/power/domain.c113
-rw-r--r--drivers/base/power/opp.c196
-rw-r--r--drivers/base/property.c431
-rw-r--r--drivers/clk/at91/clk-usb.c35
-rw-r--r--drivers/clk/clk-divider.c18
-rw-r--r--drivers/clk/pxa/clk-pxa27x.c4
-rw-r--r--drivers/clk/qcom/mmcc-apq8084.c2
-rw-r--r--drivers/clk/rockchip/clk.c4
-rw-r--r--drivers/clocksource/sun4i_timer.c12
-rw-r--r--drivers/dma/dw/core.c11
-rw-r--r--drivers/dma/pl330.c23
-rw-r--r--drivers/dma/sun6i-dma.c61
-rw-r--r--drivers/gpio/devres.c32
-rw-r--r--drivers/gpio/gpio-sch.c293
-rw-r--r--drivers/gpio/gpiolib-acpi.c117
-rw-r--r--drivers/gpio/gpiolib.c85
-rw-r--r--drivers/gpio/gpiolib.h7
-rw-r--r--drivers/gpu/drm/i915/i915_dma.c10
-rw-r--r--drivers/gpu/drm/i915/intel_display.c6
-rw-r--r--drivers/gpu/drm/i915/intel_dp.c1
-rw-r--r--drivers/gpu/drm/i915/intel_lvds.c22
-rw-r--r--drivers/gpu/drm/i915/intel_pm.c5
-rw-r--r--drivers/gpu/drm/nouveau/core/engine/device/nvc0.c1
-rw-r--r--drivers/gpu/drm/nouveau/core/engine/fifo/nv04.c2
-rw-r--r--drivers/gpu/drm/nouveau/core/engine/fifo/nvc0.c4
-rw-r--r--drivers/gpu/drm/nouveau/core/engine/fifo/nve0.c2
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_drm.c2
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_fence.c92
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_fence.h4
-rw-r--r--drivers/gpu/drm/radeon/r600_dpm.c2
-rw-r--r--drivers/gpu/drm/radeon/radeon_connectors.c19
-rw-r--r--drivers/gpu/drm/radeon/radeon_cs.c17
-rw-r--r--drivers/gpu/drm/radeon/radeon_encoders.c3
-rw-r--r--drivers/gpu/drm/radeon/radeon_irq_kms.c10
-rw-r--r--drivers/gpu/drm/radeon/radeon_kms.c2
-rw-r--r--drivers/gpu/drm/radeon/radeon_object.c7
-rw-r--r--drivers/hwmon/g762.c6
-rw-r--r--drivers/i2c/busses/i2c-cadence.c11
-rw-r--r--drivers/i2c/busses/i2c-davinci.c8
-rw-r--r--drivers/i2c/busses/i2c-designware-core.c2
-rw-r--r--drivers/i2c/busses/i2c-omap.c10
-rw-r--r--drivers/i2c/i2c-core.c1
-rw-r--r--drivers/iio/accel/bmc150-accel.c40
-rw-r--r--drivers/iio/accel/kxcjk-1013.c2
-rw-r--r--drivers/iio/adc/Kconfig8
-rw-r--r--drivers/iio/adc/Makefile1
-rw-r--r--drivers/iio/adc/axp288_adc.c261
-rw-r--r--drivers/iio/adc/men_z188_adc.c1
-rw-r--r--drivers/iio/gyro/bmg160.c53
-rw-r--r--drivers/infiniband/ulp/isert/ib_isert.c44
-rw-r--r--drivers/infiniband/ulp/srpt/ib_srpt.c8
-rw-r--r--drivers/input/evdev.c2
-rw-r--r--drivers/input/joystick/xpad.c16
-rw-r--r--drivers/input/keyboard/gpio_keys_polled.c112
-rw-r--r--drivers/input/mouse/elantech.c10
-rw-r--r--drivers/input/mouse/synaptics.c4
-rw-r--r--drivers/irqchip/irq-atmel-aic-common.c6
-rw-r--r--drivers/irqchip/irq-bcm7120-l2.c4
-rw-r--r--drivers/irqchip/irq-brcmstb-l2.c4
-rw-r--r--drivers/leds/leds-gpio.c150
-rw-r--r--drivers/media/i2c/smiapp/smiapp-core.c2
-rw-r--r--drivers/media/pci/cx23885/cx23885-core.c6
-rw-r--r--drivers/media/pci/solo6x10/solo6x10-core.c10
-rw-r--r--drivers/media/rc/ir-rc6-decoder.c2
-rw-r--r--drivers/media/usb/s2255/s2255drv.c2
-rw-r--r--drivers/mfd/Kconfig3
-rw-r--r--drivers/mfd/axp20x.c364
-rw-r--r--drivers/mfd/intel_soc_pmic_crc.c3
-rw-r--r--drivers/misc/eeprom/at25.c34
-rw-r--r--drivers/net/bonding/bond_main.c3
-rw-r--r--drivers/net/bonding/bond_netlink.c7
-rw-r--r--drivers/net/can/dev.c4
-rw-r--r--drivers/net/can/m_can/Kconfig1
-rw-r--r--drivers/net/can/m_can/m_can.c219
-rw-r--r--drivers/net/can/rcar_can.c1
-rw-r--r--drivers/net/can/sja1000/kvaser_pci.c5
-rw-r--r--drivers/net/can/usb/ems_usb.c3
-rw-r--r--drivers/net/can/usb/esd_usb2.c3
-rw-r--r--drivers/net/can/usb/gs_usb.c1
-rw-r--r--drivers/net/can/xilinx_can.c4
-rw-r--r--drivers/net/dsa/bcm_sf2.c58
-rw-r--r--drivers/net/ethernet/broadcom/tg3.c3
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/cxgb4_dcb.c2
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c8
-rw-r--r--drivers/net/ethernet/emulex/benet/be_main.c11
-rw-r--r--drivers/net/ethernet/intel/igb/igb_main.c23
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_main.c17
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/en_netdev.c13
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/resource_tracker.c2
-rw-r--r--drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c6
-rw-r--r--drivers/net/ethernet/renesas/sh_eth.c96
-rw-r--r--drivers/net/ethernet/renesas/sh_eth.h5
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c27
-rw-r--r--drivers/net/ethernet/ti/cpsw.c6
-rw-r--r--drivers/net/ieee802154/fakehard.c13
-rw-r--r--drivers/net/ppp/pptp.c4
-rw-r--r--drivers/net/usb/qmi_wwan.c1
-rw-r--r--drivers/net/virtio_net.c37
-rw-r--r--drivers/net/vxlan.c10
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_phy.c13
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.c13
-rw-r--r--drivers/net/wireless/ath/ath9k/main.c9
-rw-r--r--drivers/net/wireless/b43/phy_common.c4
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/of.c4
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/pcie.c2
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/usb.c6
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c6
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-fw.h2
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/mac80211.c12
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/scan.c20
-rw-r--r--drivers/net/wireless/iwlwifi/pcie/trans.c3
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00queue.c50
-rw-r--r--drivers/net/wireless/rtlwifi/pci.c39
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192se/hw.c7
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192se/phy.c2
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192se/sw.c16
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8821ae/hw.c5
-rw-r--r--drivers/net/xen-netback/xenbus.c15
-rw-r--r--drivers/net/xen-netfront.c5
-rw-r--r--drivers/of/address.c19
-rw-r--r--drivers/of/base.c33
-rw-r--r--drivers/of/dynamic.c2
-rw-r--r--drivers/of/fdt.c4
-rw-r--r--drivers/of/selftest.c11
-rw-r--r--drivers/pci/access.c2
-rw-r--r--drivers/pci/host/pci-tegra.c28
-rw-r--r--drivers/pci/host/pci-xgene.c7
-rw-r--r--drivers/pci/msi.c26
-rw-r--r--drivers/pci/pci.h2
-rw-r--r--drivers/pci/probe.c30
-rw-r--r--drivers/powercap/Kconfig2
-rw-r--r--drivers/powercap/intel_rapl.c264
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_fcoe.c7
-rw-r--r--drivers/scsi/cxgbi/cxgb4i/cxgb4i.c2
-rw-r--r--drivers/scsi/cxgbi/libcxgbi.c2
-rw-r--r--drivers/scsi/scsi_devinfo.c1
-rw-r--r--drivers/scsi/ufs/ufshcd-pltfrm.c15
-rw-r--r--drivers/scsi/ufs/ufshcd.c104
-rw-r--r--drivers/scsi/ufs/ufshcd.h2
-rw-r--r--drivers/spi/spi-dw.c6
-rw-r--r--drivers/spi/spi-sirf.c4
-rw-r--r--drivers/spi/spi.c6
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_cmd.c22
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_mlme_ext.c12
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_wlan_util.c2
-rw-r--r--drivers/staging/rtl8188eu/os_dep/usb_intf.c1
-rw-r--r--drivers/target/iscsi/iscsi_target.c2
-rw-r--r--drivers/target/target_core_pr.c9
-rw-r--r--drivers/target/target_core_transport.c2
-rw-r--r--drivers/thermal/cpu_cooling.c37
-rw-r--r--drivers/thermal/samsung/exynos_thermal_common.c9
-rw-r--r--drivers/thermal/st/st_thermal.c3
-rw-r--r--drivers/tty/serial/of_serial.c27
-rw-r--r--drivers/usb/core/quirks.c3
-rw-r--r--drivers/usb/dwc3/ep0.c8
-rw-r--r--drivers/usb/host/xhci-hub.c5
-rw-r--r--drivers/usb/host/xhci-pci.c2
-rw-r--r--drivers/usb/host/xhci-plat.c10
-rw-r--r--drivers/usb/host/xhci-ring.c43
-rw-r--r--drivers/usb/host/xhci.c107
-rw-r--r--drivers/usb/host/xhci.h2
-rw-r--r--drivers/usb/serial/cp210x.c1
-rw-r--r--drivers/usb/serial/ftdi_sio.c33
-rw-r--r--drivers/usb/serial/ftdi_sio_ids.h39
-rw-r--r--drivers/usb/serial/keyspan.c97
-rw-r--r--drivers/usb/serial/ssu100.c11
-rw-r--r--drivers/usb/storage/unusual_uas.h7
-rw-r--r--drivers/vhost/scsi.c24
-rw-r--r--drivers/watchdog/s3c2410_wdt.c2
199 files changed, 5291 insertions, 1545 deletions
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index b23fe37f67c0..8951cefb0a96 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -360,15 +360,14 @@ config ACPI_BGRT
360config ACPI_REDUCED_HARDWARE_ONLY 360config ACPI_REDUCED_HARDWARE_ONLY
361 bool "Hardware-reduced ACPI support only" if EXPERT 361 bool "Hardware-reduced ACPI support only" if EXPERT
362 def_bool n 362 def_bool n
363 depends on ACPI
364 help 363 help
365 This config item changes the way the ACPI code is built. When this 364 This config item changes the way the ACPI code is built. When this
366 option is selected, the kernel will use a specialized version of 365 option is selected, the kernel will use a specialized version of
367 ACPICA that ONLY supports the ACPI "reduced hardware" mode. The 366 ACPICA that ONLY supports the ACPI "reduced hardware" mode. The
368 resulting kernel will be smaller but it will also be restricted to 367 resulting kernel will be smaller but it will also be restricted to
369 running in ACPI reduced hardware mode ONLY. 368 running in ACPI reduced hardware mode ONLY.
370 369
371 If you are unsure what to do, do not enable this option. 370 If you are unsure what to do, do not enable this option.
372 371
373source "drivers/acpi/apei/Kconfig" 372source "drivers/acpi/apei/Kconfig"
374 373
@@ -394,4 +393,27 @@ config ACPI_EXTLOG
394 driver adds support for that functionality with corresponding 393 driver adds support for that functionality with corresponding
395 tracepoint which carries that information to userspace. 394 tracepoint which carries that information to userspace.
396 395
396menuconfig PMIC_OPREGION
397 bool "PMIC (Power Management Integrated Circuit) operation region support"
398 help
399 Select this option to enable support for ACPI operation
400 region of the PMIC chip. The operation region can be used
401 to control power rails and sensor reading/writing on the
402 PMIC chip.
403
404if PMIC_OPREGION
405config CRC_PMIC_OPREGION
406 bool "ACPI operation region support for CrystalCove PMIC"
407 depends on INTEL_SOC_PMIC
408 help
409 This config adds ACPI operation region support for CrystalCove PMIC.
410
411config XPOWER_PMIC_OPREGION
412 bool "ACPI operation region support for XPower AXP288 PMIC"
413 depends on AXP288_ADC = y
414 help
415 This config adds ACPI operation region support for XPower AXP288 PMIC.
416
417endif
418
397endif # ACPI 419endif # ACPI
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index c3b2fcb729f3..f74317cc1ca9 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -47,6 +47,7 @@ acpi-y += int340x_thermal.o
47acpi-y += power.o 47acpi-y += power.o
48acpi-y += event.o 48acpi-y += event.o
49acpi-y += sysfs.o 49acpi-y += sysfs.o
50acpi-y += property.o
50acpi-$(CONFIG_X86) += acpi_cmos_rtc.o 51acpi-$(CONFIG_X86) += acpi_cmos_rtc.o
51acpi-$(CONFIG_DEBUG_FS) += debugfs.o 52acpi-$(CONFIG_DEBUG_FS) += debugfs.o
52acpi-$(CONFIG_ACPI_NUMA) += numa.o 53acpi-$(CONFIG_ACPI_NUMA) += numa.o
@@ -87,3 +88,7 @@ obj-$(CONFIG_ACPI_PROCESSOR_AGGREGATOR) += acpi_pad.o
87obj-$(CONFIG_ACPI_APEI) += apei/ 88obj-$(CONFIG_ACPI_APEI) += apei/
88 89
89obj-$(CONFIG_ACPI_EXTLOG) += acpi_extlog.o 90obj-$(CONFIG_ACPI_EXTLOG) += acpi_extlog.o
91
92obj-$(CONFIG_PMIC_OPREGION) += pmic/intel_pmic.o
93obj-$(CONFIG_CRC_PMIC_OPREGION) += pmic/intel_pmic_crc.o
94obj-$(CONFIG_XPOWER_PMIC_OPREGION) += pmic/intel_pmic_xpower.o
diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
index 93d160661f4c..d1dd0ada14b7 100644
--- a/drivers/acpi/acpi_lpss.c
+++ b/drivers/acpi/acpi_lpss.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * ACPI support for Intel Lynxpoint LPSS. 2 * ACPI support for Intel Lynxpoint LPSS.
3 * 3 *
4 * Copyright (C) 2013, Intel Corporation 4 * Copyright (C) 2013, 2014, Intel Corporation
5 * Authors: Mika Westerberg <mika.westerberg@linux.intel.com> 5 * Authors: Mika Westerberg <mika.westerberg@linux.intel.com>
6 * Rafael J. Wysocki <rafael.j.wysocki@intel.com> 6 * Rafael J. Wysocki <rafael.j.wysocki@intel.com>
7 * 7 *
@@ -60,6 +60,8 @@ ACPI_MODULE_NAME("acpi_lpss");
60#define LPSS_CLK_DIVIDER BIT(2) 60#define LPSS_CLK_DIVIDER BIT(2)
61#define LPSS_LTR BIT(3) 61#define LPSS_LTR BIT(3)
62#define LPSS_SAVE_CTX BIT(4) 62#define LPSS_SAVE_CTX BIT(4)
63#define LPSS_DEV_PROXY BIT(5)
64#define LPSS_PROXY_REQ BIT(6)
63 65
64struct lpss_private_data; 66struct lpss_private_data;
65 67
@@ -70,8 +72,10 @@ struct lpss_device_desc {
70 void (*setup)(struct lpss_private_data *pdata); 72 void (*setup)(struct lpss_private_data *pdata);
71}; 73};
72 74
75static struct device *proxy_device;
76
73static struct lpss_device_desc lpss_dma_desc = { 77static struct lpss_device_desc lpss_dma_desc = {
74 .flags = LPSS_CLK, 78 .flags = LPSS_CLK | LPSS_PROXY_REQ,
75}; 79};
76 80
77struct lpss_private_data { 81struct lpss_private_data {
@@ -146,22 +150,24 @@ static struct lpss_device_desc byt_pwm_dev_desc = {
146}; 150};
147 151
148static struct lpss_device_desc byt_uart_dev_desc = { 152static struct lpss_device_desc byt_uart_dev_desc = {
149 .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_SAVE_CTX, 153 .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_SAVE_CTX |
154 LPSS_DEV_PROXY,
150 .prv_offset = 0x800, 155 .prv_offset = 0x800,
151 .setup = lpss_uart_setup, 156 .setup = lpss_uart_setup,
152}; 157};
153 158
154static struct lpss_device_desc byt_spi_dev_desc = { 159static struct lpss_device_desc byt_spi_dev_desc = {
155 .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_SAVE_CTX, 160 .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_SAVE_CTX |
161 LPSS_DEV_PROXY,
156 .prv_offset = 0x400, 162 .prv_offset = 0x400,
157}; 163};
158 164
159static struct lpss_device_desc byt_sdio_dev_desc = { 165static struct lpss_device_desc byt_sdio_dev_desc = {
160 .flags = LPSS_CLK, 166 .flags = LPSS_CLK | LPSS_DEV_PROXY,
161}; 167};
162 168
163static struct lpss_device_desc byt_i2c_dev_desc = { 169static struct lpss_device_desc byt_i2c_dev_desc = {
164 .flags = LPSS_CLK | LPSS_SAVE_CTX, 170 .flags = LPSS_CLK | LPSS_SAVE_CTX | LPSS_DEV_PROXY,
165 .prv_offset = 0x800, 171 .prv_offset = 0x800,
166 .setup = byt_i2c_setup, 172 .setup = byt_i2c_setup,
167}; 173};
@@ -368,6 +374,8 @@ static int acpi_lpss_create_device(struct acpi_device *adev,
368 adev->driver_data = pdata; 374 adev->driver_data = pdata;
369 pdev = acpi_create_platform_device(adev); 375 pdev = acpi_create_platform_device(adev);
370 if (!IS_ERR_OR_NULL(pdev)) { 376 if (!IS_ERR_OR_NULL(pdev)) {
377 if (!proxy_device && dev_desc->flags & LPSS_DEV_PROXY)
378 proxy_device = &pdev->dev;
371 return 1; 379 return 1;
372 } 380 }
373 381
@@ -499,14 +507,15 @@ static void acpi_lpss_set_ltr(struct device *dev, s32 val)
499/** 507/**
500 * acpi_lpss_save_ctx() - Save the private registers of LPSS device 508 * acpi_lpss_save_ctx() - Save the private registers of LPSS device
501 * @dev: LPSS device 509 * @dev: LPSS device
510 * @pdata: pointer to the private data of the LPSS device
502 * 511 *
503 * Most LPSS devices have private registers which may loose their context when 512 * Most LPSS devices have private registers which may loose their context when
504 * the device is powered down. acpi_lpss_save_ctx() saves those registers into 513 * the device is powered down. acpi_lpss_save_ctx() saves those registers into
505 * prv_reg_ctx array. 514 * prv_reg_ctx array.
506 */ 515 */
507static void acpi_lpss_save_ctx(struct device *dev) 516static void acpi_lpss_save_ctx(struct device *dev,
517 struct lpss_private_data *pdata)
508{ 518{
509 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
510 unsigned int i; 519 unsigned int i;
511 520
512 for (i = 0; i < LPSS_PRV_REG_COUNT; i++) { 521 for (i = 0; i < LPSS_PRV_REG_COUNT; i++) {
@@ -521,12 +530,13 @@ static void acpi_lpss_save_ctx(struct device *dev)
521/** 530/**
522 * acpi_lpss_restore_ctx() - Restore the private registers of LPSS device 531 * acpi_lpss_restore_ctx() - Restore the private registers of LPSS device
523 * @dev: LPSS device 532 * @dev: LPSS device
533 * @pdata: pointer to the private data of the LPSS device
524 * 534 *
525 * Restores the registers that were previously stored with acpi_lpss_save_ctx(). 535 * Restores the registers that were previously stored with acpi_lpss_save_ctx().
526 */ 536 */
527static void acpi_lpss_restore_ctx(struct device *dev) 537static void acpi_lpss_restore_ctx(struct device *dev,
538 struct lpss_private_data *pdata)
528{ 539{
529 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
530 unsigned int i; 540 unsigned int i;
531 541
532 /* 542 /*
@@ -549,23 +559,31 @@ static void acpi_lpss_restore_ctx(struct device *dev)
549#ifdef CONFIG_PM_SLEEP 559#ifdef CONFIG_PM_SLEEP
550static int acpi_lpss_suspend_late(struct device *dev) 560static int acpi_lpss_suspend_late(struct device *dev)
551{ 561{
552 int ret = pm_generic_suspend_late(dev); 562 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
563 int ret;
553 564
565 ret = pm_generic_suspend_late(dev);
554 if (ret) 566 if (ret)
555 return ret; 567 return ret;
556 568
557 acpi_lpss_save_ctx(dev); 569 if (pdata->dev_desc->flags & LPSS_SAVE_CTX)
570 acpi_lpss_save_ctx(dev, pdata);
571
558 return acpi_dev_suspend_late(dev); 572 return acpi_dev_suspend_late(dev);
559} 573}
560 574
561static int acpi_lpss_resume_early(struct device *dev) 575static int acpi_lpss_resume_early(struct device *dev)
562{ 576{
563 int ret = acpi_dev_resume_early(dev); 577 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
578 int ret;
564 579
580 ret = acpi_dev_resume_early(dev);
565 if (ret) 581 if (ret)
566 return ret; 582 return ret;
567 583
568 acpi_lpss_restore_ctx(dev); 584 if (pdata->dev_desc->flags & LPSS_SAVE_CTX)
585 acpi_lpss_restore_ctx(dev, pdata);
586
569 return pm_generic_resume_early(dev); 587 return pm_generic_resume_early(dev);
570} 588}
571#endif /* CONFIG_PM_SLEEP */ 589#endif /* CONFIG_PM_SLEEP */
@@ -573,23 +591,44 @@ static int acpi_lpss_resume_early(struct device *dev)
573#ifdef CONFIG_PM_RUNTIME 591#ifdef CONFIG_PM_RUNTIME
574static int acpi_lpss_runtime_suspend(struct device *dev) 592static int acpi_lpss_runtime_suspend(struct device *dev)
575{ 593{
576 int ret = pm_generic_runtime_suspend(dev); 594 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
595 int ret;
577 596
597 ret = pm_generic_runtime_suspend(dev);
578 if (ret) 598 if (ret)
579 return ret; 599 return ret;
580 600
581 acpi_lpss_save_ctx(dev); 601 if (pdata->dev_desc->flags & LPSS_SAVE_CTX)
582 return acpi_dev_runtime_suspend(dev); 602 acpi_lpss_save_ctx(dev, pdata);
603
604 ret = acpi_dev_runtime_suspend(dev);
605 if (ret)
606 return ret;
607
608 if (pdata->dev_desc->flags & LPSS_PROXY_REQ && proxy_device)
609 return pm_runtime_put_sync_suspend(proxy_device);
610
611 return 0;
583} 612}
584 613
585static int acpi_lpss_runtime_resume(struct device *dev) 614static int acpi_lpss_runtime_resume(struct device *dev)
586{ 615{
587 int ret = acpi_dev_runtime_resume(dev); 616 struct lpss_private_data *pdata = acpi_driver_data(ACPI_COMPANION(dev));
617 int ret;
618
619 if (pdata->dev_desc->flags & LPSS_PROXY_REQ && proxy_device) {
620 ret = pm_runtime_get_sync(proxy_device);
621 if (ret)
622 return ret;
623 }
588 624
625 ret = acpi_dev_runtime_resume(dev);
589 if (ret) 626 if (ret)
590 return ret; 627 return ret;
591 628
592 acpi_lpss_restore_ctx(dev); 629 if (pdata->dev_desc->flags & LPSS_SAVE_CTX)
630 acpi_lpss_restore_ctx(dev, pdata);
631
593 return pm_generic_runtime_resume(dev); 632 return pm_generic_runtime_resume(dev);
594} 633}
595#endif /* CONFIG_PM_RUNTIME */ 634#endif /* CONFIG_PM_RUNTIME */
@@ -631,30 +670,27 @@ static int acpi_lpss_platform_notify(struct notifier_block *nb,
631 return 0; 670 return 0;
632 671
633 pdata = acpi_driver_data(adev); 672 pdata = acpi_driver_data(adev);
634 if (!pdata || !pdata->mmio_base) 673 if (!pdata)
635 return 0; 674 return 0;
636 675
637 if (pdata->mmio_size < pdata->dev_desc->prv_offset + LPSS_LTR_SIZE) { 676 if (pdata->mmio_base &&
677 pdata->mmio_size < pdata->dev_desc->prv_offset + LPSS_LTR_SIZE) {
638 dev_err(&pdev->dev, "MMIO size insufficient to access LTR\n"); 678 dev_err(&pdev->dev, "MMIO size insufficient to access LTR\n");
639 return 0; 679 return 0;
640 } 680 }
641 681
642 switch (action) { 682 switch (action) {
643 case BUS_NOTIFY_BOUND_DRIVER:
644 if (pdata->dev_desc->flags & LPSS_SAVE_CTX)
645 pdev->dev.pm_domain = &acpi_lpss_pm_domain;
646 break;
647 case BUS_NOTIFY_UNBOUND_DRIVER:
648 if (pdata->dev_desc->flags & LPSS_SAVE_CTX)
649 pdev->dev.pm_domain = NULL;
650 break;
651 case BUS_NOTIFY_ADD_DEVICE: 683 case BUS_NOTIFY_ADD_DEVICE:
684 pdev->dev.pm_domain = &acpi_lpss_pm_domain;
652 if (pdata->dev_desc->flags & LPSS_LTR) 685 if (pdata->dev_desc->flags & LPSS_LTR)
653 return sysfs_create_group(&pdev->dev.kobj, 686 return sysfs_create_group(&pdev->dev.kobj,
654 &lpss_attr_group); 687 &lpss_attr_group);
688 break;
655 case BUS_NOTIFY_DEL_DEVICE: 689 case BUS_NOTIFY_DEL_DEVICE:
656 if (pdata->dev_desc->flags & LPSS_LTR) 690 if (pdata->dev_desc->flags & LPSS_LTR)
657 sysfs_remove_group(&pdev->dev.kobj, &lpss_attr_group); 691 sysfs_remove_group(&pdev->dev.kobj, &lpss_attr_group);
692 pdev->dev.pm_domain = NULL;
693 break;
658 default: 694 default:
659 break; 695 break;
660 } 696 }
diff --git a/drivers/acpi/acpica/acglobal.h b/drivers/acpi/acpica/acglobal.h
index ebf02cc10a43..7f60582d0c8c 100644
--- a/drivers/acpi/acpica/acglobal.h
+++ b/drivers/acpi/acpica/acglobal.h
@@ -305,6 +305,7 @@ ACPI_INIT_GLOBAL(u8, acpi_gbl_db_output_flags, ACPI_DB_CONSOLE_OUTPUT);
305 305
306ACPI_INIT_GLOBAL(u8, acpi_gbl_no_resource_disassembly, FALSE); 306ACPI_INIT_GLOBAL(u8, acpi_gbl_no_resource_disassembly, FALSE);
307ACPI_INIT_GLOBAL(u8, acpi_gbl_ignore_noop_operator, FALSE); 307ACPI_INIT_GLOBAL(u8, acpi_gbl_ignore_noop_operator, FALSE);
308ACPI_INIT_GLOBAL(u8, acpi_gbl_cstyle_disassembly, TRUE);
308 309
309ACPI_GLOBAL(u8, acpi_gbl_db_opt_disasm); 310ACPI_GLOBAL(u8, acpi_gbl_db_opt_disasm);
310ACPI_GLOBAL(u8, acpi_gbl_db_opt_verbose); 311ACPI_GLOBAL(u8, acpi_gbl_db_opt_verbose);
diff --git a/drivers/acpi/acpica/aclocal.h b/drivers/acpi/acpica/aclocal.h
index c00e7e41ad75..680d23bbae7c 100644
--- a/drivers/acpi/acpica/aclocal.h
+++ b/drivers/acpi/acpica/aclocal.h
@@ -454,6 +454,7 @@ struct acpi_gpe_register_info {
454 u16 base_gpe_number; /* Base GPE number for this register */ 454 u16 base_gpe_number; /* Base GPE number for this register */
455 u8 enable_for_wake; /* GPEs to keep enabled when sleeping */ 455 u8 enable_for_wake; /* GPEs to keep enabled when sleeping */
456 u8 enable_for_run; /* GPEs to keep enabled when running */ 456 u8 enable_for_run; /* GPEs to keep enabled when running */
457 u8 enable_mask; /* Current mask of enabled GPEs */
457}; 458};
458 459
459/* 460/*
@@ -722,6 +723,7 @@ union acpi_parse_value {
722 ACPI_DISASM_ONLY_MEMBERS (\ 723 ACPI_DISASM_ONLY_MEMBERS (\
723 u8 disasm_flags; /* Used during AML disassembly */\ 724 u8 disasm_flags; /* Used during AML disassembly */\
724 u8 disasm_opcode; /* Subtype used for disassembly */\ 725 u8 disasm_opcode; /* Subtype used for disassembly */\
726 char *operator_symbol;/* Used for C-style operator name strings */\
725 char aml_op_name[16]) /* Op name (debug only) */ 727 char aml_op_name[16]) /* Op name (debug only) */
726 728
727/* Flags for disasm_flags field above */ 729/* Flags for disasm_flags field above */
@@ -827,6 +829,8 @@ struct acpi_parse_state {
827#define ACPI_PARSEOP_EMPTY_TERMLIST 0x04 829#define ACPI_PARSEOP_EMPTY_TERMLIST 0x04
828#define ACPI_PARSEOP_PREDEF_CHECKED 0x08 830#define ACPI_PARSEOP_PREDEF_CHECKED 0x08
829#define ACPI_PARSEOP_SPECIAL 0x10 831#define ACPI_PARSEOP_SPECIAL 0x10
832#define ACPI_PARSEOP_COMPOUND 0x20
833#define ACPI_PARSEOP_ASSIGNMENT 0x40
830 834
831/***************************************************************************** 835/*****************************************************************************
832 * 836 *
diff --git a/drivers/acpi/acpica/evgpe.c b/drivers/acpi/acpica/evgpe.c
index 2095dfb72bcb..aa70154cf4fa 100644
--- a/drivers/acpi/acpica/evgpe.c
+++ b/drivers/acpi/acpica/evgpe.c
@@ -134,7 +134,7 @@ acpi_status acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info)
134 134
135 /* Enable the requested GPE */ 135 /* Enable the requested GPE */
136 136
137 status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_ENABLE); 137 status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_ENABLE_SAVE);
138 return_ACPI_STATUS(status); 138 return_ACPI_STATUS(status);
139} 139}
140 140
@@ -213,7 +213,7 @@ acpi_ev_remove_gpe_reference(struct acpi_gpe_event_info *gpe_event_info)
213 if (ACPI_SUCCESS(status)) { 213 if (ACPI_SUCCESS(status)) {
214 status = 214 status =
215 acpi_hw_low_set_gpe(gpe_event_info, 215 acpi_hw_low_set_gpe(gpe_event_info,
216 ACPI_GPE_DISABLE); 216 ACPI_GPE_DISABLE_SAVE);
217 } 217 }
218 218
219 if (ACPI_FAILURE(status)) { 219 if (ACPI_FAILURE(status)) {
@@ -616,8 +616,11 @@ static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context)
616static void ACPI_SYSTEM_XFACE acpi_ev_asynch_enable_gpe(void *context) 616static void ACPI_SYSTEM_XFACE acpi_ev_asynch_enable_gpe(void *context)
617{ 617{
618 struct acpi_gpe_event_info *gpe_event_info = context; 618 struct acpi_gpe_event_info *gpe_event_info = context;
619 acpi_cpu_flags flags;
619 620
621 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
620 (void)acpi_ev_finish_gpe(gpe_event_info); 622 (void)acpi_ev_finish_gpe(gpe_event_info);
623 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
621 624
622 ACPI_FREE(gpe_event_info); 625 ACPI_FREE(gpe_event_info);
623 return; 626 return;
@@ -655,7 +658,7 @@ acpi_status acpi_ev_finish_gpe(struct acpi_gpe_event_info * gpe_event_info)
655 658
656 /* 659 /*
657 * Enable this GPE, conditionally. This means that the GPE will 660 * Enable this GPE, conditionally. This means that the GPE will
658 * only be physically enabled if the enable_for_run bit is set 661 * only be physically enabled if the enable_mask bit is set
659 * in the event_info. 662 * in the event_info.
660 */ 663 */
661 (void)acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_CONDITIONAL_ENABLE); 664 (void)acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_CONDITIONAL_ENABLE);
diff --git a/drivers/acpi/acpica/hwgpe.c b/drivers/acpi/acpica/hwgpe.c
index 48ac7b7b59cd..494027f5c067 100644
--- a/drivers/acpi/acpica/hwgpe.c
+++ b/drivers/acpi/acpica/hwgpe.c
@@ -115,12 +115,12 @@ acpi_hw_low_set_gpe(struct acpi_gpe_event_info *gpe_event_info, u32 action)
115 /* Set or clear just the bit that corresponds to this GPE */ 115 /* Set or clear just the bit that corresponds to this GPE */
116 116
117 register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info); 117 register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info);
118 switch (action) { 118 switch (action & ~ACPI_GPE_SAVE_MASK) {
119 case ACPI_GPE_CONDITIONAL_ENABLE: 119 case ACPI_GPE_CONDITIONAL_ENABLE:
120 120
121 /* Only enable if the enable_for_run bit is set */ 121 /* Only enable if the corresponding enable_mask bit is set */
122 122
123 if (!(register_bit & gpe_register_info->enable_for_run)) { 123 if (!(register_bit & gpe_register_info->enable_mask)) {
124 return (AE_BAD_PARAMETER); 124 return (AE_BAD_PARAMETER);
125 } 125 }
126 126
@@ -145,6 +145,9 @@ acpi_hw_low_set_gpe(struct acpi_gpe_event_info *gpe_event_info, u32 action)
145 /* Write the updated enable mask */ 145 /* Write the updated enable mask */
146 146
147 status = acpi_hw_write(enable_mask, &gpe_register_info->enable_address); 147 status = acpi_hw_write(enable_mask, &gpe_register_info->enable_address);
148 if (ACPI_SUCCESS(status) && (action & ACPI_GPE_SAVE_MASK)) {
149 gpe_register_info->enable_mask = enable_mask;
150 }
148 return (status); 151 return (status);
149} 152}
150 153
@@ -262,6 +265,32 @@ acpi_hw_get_gpe_status(struct acpi_gpe_event_info * gpe_event_info,
262 265
263/****************************************************************************** 266/******************************************************************************
264 * 267 *
268 * FUNCTION: acpi_hw_gpe_enable_write
269 *
270 * PARAMETERS: enable_mask - Bit mask to write to the GPE register
271 * gpe_register_info - Gpe Register info
272 *
273 * RETURN: Status
274 *
275 * DESCRIPTION: Write the enable mask byte to the given GPE register.
276 *
277 ******************************************************************************/
278
279static acpi_status
280acpi_hw_gpe_enable_write(u8 enable_mask,
281 struct acpi_gpe_register_info *gpe_register_info)
282{
283 acpi_status status;
284
285 status = acpi_hw_write(enable_mask, &gpe_register_info->enable_address);
286 if (ACPI_SUCCESS(status)) {
287 gpe_register_info->enable_mask = enable_mask;
288 }
289 return (status);
290}
291
292/******************************************************************************
293 *
265 * FUNCTION: acpi_hw_disable_gpe_block 294 * FUNCTION: acpi_hw_disable_gpe_block
266 * 295 *
267 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info 296 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
@@ -287,8 +316,8 @@ acpi_hw_disable_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
287 /* Disable all GPEs in this register */ 316 /* Disable all GPEs in this register */
288 317
289 status = 318 status =
290 acpi_hw_write(0x00, 319 acpi_hw_gpe_enable_write(0x00,
291 &gpe_block->register_info[i].enable_address); 320 &gpe_block->register_info[i]);
292 if (ACPI_FAILURE(status)) { 321 if (ACPI_FAILURE(status)) {
293 return (status); 322 return (status);
294 } 323 }
@@ -355,21 +384,23 @@ acpi_hw_enable_runtime_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
355{ 384{
356 u32 i; 385 u32 i;
357 acpi_status status; 386 acpi_status status;
387 struct acpi_gpe_register_info *gpe_register_info;
358 388
359 /* NOTE: assumes that all GPEs are currently disabled */ 389 /* NOTE: assumes that all GPEs are currently disabled */
360 390
361 /* Examine each GPE Register within the block */ 391 /* Examine each GPE Register within the block */
362 392
363 for (i = 0; i < gpe_block->register_count; i++) { 393 for (i = 0; i < gpe_block->register_count; i++) {
364 if (!gpe_block->register_info[i].enable_for_run) { 394 gpe_register_info = &gpe_block->register_info[i];
395 if (!gpe_register_info->enable_for_run) {
365 continue; 396 continue;
366 } 397 }
367 398
368 /* Enable all "runtime" GPEs in this register */ 399 /* Enable all "runtime" GPEs in this register */
369 400
370 status = 401 status =
371 acpi_hw_write(gpe_block->register_info[i].enable_for_run, 402 acpi_hw_gpe_enable_write(gpe_register_info->enable_for_run,
372 &gpe_block->register_info[i].enable_address); 403 gpe_register_info);
373 if (ACPI_FAILURE(status)) { 404 if (ACPI_FAILURE(status)) {
374 return (status); 405 return (status);
375 } 406 }
@@ -399,10 +430,12 @@ acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
399{ 430{
400 u32 i; 431 u32 i;
401 acpi_status status; 432 acpi_status status;
433 struct acpi_gpe_register_info *gpe_register_info;
402 434
403 /* Examine each GPE Register within the block */ 435 /* Examine each GPE Register within the block */
404 436
405 for (i = 0; i < gpe_block->register_count; i++) { 437 for (i = 0; i < gpe_block->register_count; i++) {
438 gpe_register_info = &gpe_block->register_info[i];
406 439
407 /* 440 /*
408 * Enable all "wake" GPEs in this register and disable the 441 * Enable all "wake" GPEs in this register and disable the
@@ -410,8 +443,8 @@ acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
410 */ 443 */
411 444
412 status = 445 status =
413 acpi_hw_write(gpe_block->register_info[i].enable_for_wake, 446 acpi_hw_gpe_enable_write(gpe_register_info->enable_for_wake,
414 &gpe_block->register_info[i].enable_address); 447 gpe_register_info);
415 if (ACPI_FAILURE(status)) { 448 if (ACPI_FAILURE(status)) {
416 return (status); 449 return (status);
417 } 450 }
diff --git a/drivers/acpi/acpica/utresrc.c b/drivers/acpi/acpica/utresrc.c
index 5cd017c7ac0e..bc1ff820c7dd 100644
--- a/drivers/acpi/acpica/utresrc.c
+++ b/drivers/acpi/acpica/utresrc.c
@@ -263,7 +263,7 @@ const char *acpi_gbl_bpb_decode[] = {
263/* UART serial bus stop bits */ 263/* UART serial bus stop bits */
264 264
265const char *acpi_gbl_sb_decode[] = { 265const char *acpi_gbl_sb_decode[] = {
266 "StopBitsNone", 266 "StopBitsZero",
267 "StopBitsOne", 267 "StopBitsOne",
268 "StopBitsOnePlusHalf", 268 "StopBitsOnePlusHalf",
269 "StopBitsTwo" 269 "StopBitsTwo"
diff --git a/drivers/acpi/acpica/utxface.c b/drivers/acpi/acpica/utxface.c
index 502a8492dc83..49c873c68756 100644
--- a/drivers/acpi/acpica/utxface.c
+++ b/drivers/acpi/acpica/utxface.c
@@ -531,7 +531,9 @@ acpi_decode_pld_buffer(u8 *in_buffer,
531 ACPI_MOVE_32_TO_32(&dword, &buffer[0]); 531 ACPI_MOVE_32_TO_32(&dword, &buffer[0]);
532 pld_info->revision = ACPI_PLD_GET_REVISION(&dword); 532 pld_info->revision = ACPI_PLD_GET_REVISION(&dword);
533 pld_info->ignore_color = ACPI_PLD_GET_IGNORE_COLOR(&dword); 533 pld_info->ignore_color = ACPI_PLD_GET_IGNORE_COLOR(&dword);
534 pld_info->color = ACPI_PLD_GET_COLOR(&dword); 534 pld_info->red = ACPI_PLD_GET_RED(&dword);
535 pld_info->green = ACPI_PLD_GET_GREEN(&dword);
536 pld_info->blue = ACPI_PLD_GET_BLUE(&dword);
535 537
536 /* Second 32-bit DWord */ 538 /* Second 32-bit DWord */
537 539
diff --git a/drivers/acpi/acpica/utxfinit.c b/drivers/acpi/acpica/utxfinit.c
index 13380d818462..b1fd6886e439 100644
--- a/drivers/acpi/acpica/utxfinit.c
+++ b/drivers/acpi/acpica/utxfinit.c
@@ -53,6 +53,9 @@
53#define _COMPONENT ACPI_UTILITIES 53#define _COMPONENT ACPI_UTILITIES
54ACPI_MODULE_NAME("utxfinit") 54ACPI_MODULE_NAME("utxfinit")
55 55
56/* For acpi_exec only */
57void ae_do_object_overrides(void);
58
56/******************************************************************************* 59/*******************************************************************************
57 * 60 *
58 * FUNCTION: acpi_initialize_subsystem 61 * FUNCTION: acpi_initialize_subsystem
@@ -65,6 +68,7 @@ ACPI_MODULE_NAME("utxfinit")
65 * called, so any early initialization belongs here. 68 * called, so any early initialization belongs here.
66 * 69 *
67 ******************************************************************************/ 70 ******************************************************************************/
71
68acpi_status __init acpi_initialize_subsystem(void) 72acpi_status __init acpi_initialize_subsystem(void)
69{ 73{
70 acpi_status status; 74 acpi_status status;
@@ -275,6 +279,13 @@ acpi_status __init acpi_initialize_objects(u32 flags)
275 return_ACPI_STATUS(status); 279 return_ACPI_STATUS(status);
276 } 280 }
277 } 281 }
282#ifdef ACPI_EXEC_APP
283 /*
284 * This call implements the "initialization file" option for acpi_exec.
285 * This is the precise point that we want to perform the overrides.
286 */
287 ae_do_object_overrides();
288#endif
278 289
279 /* 290 /*
280 * Execute any module-level code that was detected during the table load 291 * Execute any module-level code that was detected during the table load
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 8ec8a89a20ab..d98ba4355819 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -1180,6 +1180,10 @@ static int acpi_battery_add(struct acpi_device *device)
1180 1180
1181 if (!device) 1181 if (!device)
1182 return -EINVAL; 1182 return -EINVAL;
1183
1184 if (device->dep_unmet)
1185 return -EPROBE_DEFER;
1186
1183 battery = kzalloc(sizeof(struct acpi_battery), GFP_KERNEL); 1187 battery = kzalloc(sizeof(struct acpi_battery), GFP_KERNEL);
1184 if (!battery) 1188 if (!battery)
1185 return -ENOMEM; 1189 return -ENOMEM;
diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
index 143ec6ea1468..076af8149566 100644
--- a/drivers/acpi/device_pm.c
+++ b/drivers/acpi/device_pm.c
@@ -201,7 +201,7 @@ int acpi_device_set_power(struct acpi_device *device, int state)
201 * Transition Power 201 * Transition Power
202 * ---------------- 202 * ----------------
203 * In accordance with the ACPI specification first apply power (via 203 * In accordance with the ACPI specification first apply power (via
204 * power resources) and then evalute _PSx. 204 * power resources) and then evaluate _PSx.
205 */ 205 */
206 if (device->power.flags.power_resources) { 206 if (device->power.flags.power_resources) {
207 result = acpi_power_transition(device, state); 207 result = acpi_power_transition(device, state);
@@ -878,7 +878,7 @@ int acpi_dev_suspend_late(struct device *dev)
878 return 0; 878 return 0;
879 879
880 target_state = acpi_target_system_state(); 880 target_state = acpi_target_system_state();
881 wakeup = device_may_wakeup(dev); 881 wakeup = device_may_wakeup(dev) && acpi_device_can_wakeup(adev);
882 error = acpi_device_wakeup(adev, target_state, wakeup); 882 error = acpi_device_wakeup(adev, target_state, wakeup);
883 if (wakeup && error) 883 if (wakeup && error)
884 return error; 884 return error;
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
index 447f6d679b29..163e82f536fa 100644
--- a/drivers/acpi/internal.h
+++ b/drivers/acpi/internal.h
@@ -173,4 +173,10 @@ static inline void suspend_nvs_restore(void) {}
173bool acpi_osi_is_win8(void); 173bool acpi_osi_is_win8(void);
174#endif 174#endif
175 175
176/*--------------------------------------------------------------------------
177 Device properties
178 -------------------------------------------------------------------------- */
179void acpi_init_properties(struct acpi_device *adev);
180void acpi_free_properties(struct acpi_device *adev);
181
176#endif /* _ACPI_INTERNAL_H_ */ 182#endif /* _ACPI_INTERNAL_H_ */
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index 9964f70be98d..f9eeae871593 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -436,7 +436,7 @@ static void acpi_os_drop_map_ref(struct acpi_ioremap *map)
436static void acpi_os_map_cleanup(struct acpi_ioremap *map) 436static void acpi_os_map_cleanup(struct acpi_ioremap *map)
437{ 437{
438 if (!map->refcount) { 438 if (!map->refcount) {
439 synchronize_rcu(); 439 synchronize_rcu_expedited();
440 acpi_unmap(map->phys, map->virt); 440 acpi_unmap(map->phys, map->virt);
441 kfree(map); 441 kfree(map);
442 } 442 }
@@ -1188,6 +1188,12 @@ EXPORT_SYMBOL(acpi_os_execute);
1188 1188
1189void acpi_os_wait_events_complete(void) 1189void acpi_os_wait_events_complete(void)
1190{ 1190{
1191 /*
1192 * Make sure the GPE handler or the fixed event handler is not used
1193 * on another CPU after removal.
1194 */
1195 if (acpi_irq_handler)
1196 synchronize_hardirq(acpi_gbl_FADT.sci_interrupt);
1191 flush_workqueue(kacpid_wq); 1197 flush_workqueue(kacpid_wq);
1192 flush_workqueue(kacpi_notify_wq); 1198 flush_workqueue(kacpi_notify_wq);
1193} 1199}
diff --git a/drivers/acpi/pmic/intel_pmic.c b/drivers/acpi/pmic/intel_pmic.c
new file mode 100644
index 000000000000..a732e5d7e322
--- /dev/null
+++ b/drivers/acpi/pmic/intel_pmic.c
@@ -0,0 +1,354 @@
1/*
2 * intel_pmic.c - Intel PMIC operation region driver
3 *
4 * Copyright (C) 2014 Intel Corporation. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#include <linux/module.h>
17#include <linux/acpi.h>
18#include <linux/regmap.h>
19#include "intel_pmic.h"
20
21#define PMIC_POWER_OPREGION_ID 0x8d
22#define PMIC_THERMAL_OPREGION_ID 0x8c
23
24struct acpi_lpat {
25 int temp;
26 int raw;
27};
28
29struct intel_pmic_opregion {
30 struct mutex lock;
31 struct acpi_lpat *lpat;
32 int lpat_count;
33 struct regmap *regmap;
34 struct intel_pmic_opregion_data *data;
35};
36
37static int pmic_get_reg_bit(int address, struct pmic_table *table,
38 int count, int *reg, int *bit)
39{
40 int i;
41
42 for (i = 0; i < count; i++) {
43 if (table[i].address == address) {
44 *reg = table[i].reg;
45 if (bit)
46 *bit = table[i].bit;
47 return 0;
48 }
49 }
50 return -ENOENT;
51}
52
53/**
54 * raw_to_temp(): Return temperature from raw value through LPAT table
55 *
56 * @lpat: the temperature_raw mapping table
57 * @count: the count of the above mapping table
58 * @raw: the raw value, used as a key to get the temerature from the
59 * above mapping table
60 *
61 * A positive value will be returned on success, a negative errno will
62 * be returned in error cases.
63 */
64static int raw_to_temp(struct acpi_lpat *lpat, int count, int raw)
65{
66 int i, delta_temp, delta_raw, temp;
67
68 for (i = 0; i < count - 1; i++) {
69 if ((raw >= lpat[i].raw && raw <= lpat[i+1].raw) ||
70 (raw <= lpat[i].raw && raw >= lpat[i+1].raw))
71 break;
72 }
73
74 if (i == count - 1)
75 return -ENOENT;
76
77 delta_temp = lpat[i+1].temp - lpat[i].temp;
78 delta_raw = lpat[i+1].raw - lpat[i].raw;
79 temp = lpat[i].temp + (raw - lpat[i].raw) * delta_temp / delta_raw;
80
81 return temp;
82}
83
84/**
85 * temp_to_raw(): Return raw value from temperature through LPAT table
86 *
87 * @lpat: the temperature_raw mapping table
88 * @count: the count of the above mapping table
89 * @temp: the temperature, used as a key to get the raw value from the
90 * above mapping table
91 *
92 * A positive value will be returned on success, a negative errno will
93 * be returned in error cases.
94 */
95static int temp_to_raw(struct acpi_lpat *lpat, int count, int temp)
96{
97 int i, delta_temp, delta_raw, raw;
98
99 for (i = 0; i < count - 1; i++) {
100 if (temp >= lpat[i].temp && temp <= lpat[i+1].temp)
101 break;
102 }
103
104 if (i == count - 1)
105 return -ENOENT;
106
107 delta_temp = lpat[i+1].temp - lpat[i].temp;
108 delta_raw = lpat[i+1].raw - lpat[i].raw;
109 raw = lpat[i].raw + (temp - lpat[i].temp) * delta_raw / delta_temp;
110
111 return raw;
112}
113
114static void pmic_thermal_lpat(struct intel_pmic_opregion *opregion,
115 acpi_handle handle, struct device *dev)
116{
117 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
118 union acpi_object *obj_p, *obj_e;
119 int *lpat, i;
120 acpi_status status;
121
122 status = acpi_evaluate_object(handle, "LPAT", NULL, &buffer);
123 if (ACPI_FAILURE(status))
124 return;
125
126 obj_p = (union acpi_object *)buffer.pointer;
127 if (!obj_p || (obj_p->type != ACPI_TYPE_PACKAGE) ||
128 (obj_p->package.count % 2) || (obj_p->package.count < 4))
129 goto out;
130
131 lpat = devm_kmalloc(dev, sizeof(int) * obj_p->package.count,
132 GFP_KERNEL);
133 if (!lpat)
134 goto out;
135
136 for (i = 0; i < obj_p->package.count; i++) {
137 obj_e = &obj_p->package.elements[i];
138 if (obj_e->type != ACPI_TYPE_INTEGER) {
139 devm_kfree(dev, lpat);
140 goto out;
141 }
142 lpat[i] = (s64)obj_e->integer.value;
143 }
144
145 opregion->lpat = (struct acpi_lpat *)lpat;
146 opregion->lpat_count = obj_p->package.count / 2;
147
148out:
149 kfree(buffer.pointer);
150}
151
152static acpi_status intel_pmic_power_handler(u32 function,
153 acpi_physical_address address, u32 bits, u64 *value64,
154 void *handler_context, void *region_context)
155{
156 struct intel_pmic_opregion *opregion = region_context;
157 struct regmap *regmap = opregion->regmap;
158 struct intel_pmic_opregion_data *d = opregion->data;
159 int reg, bit, result;
160
161 if (bits != 32 || !value64)
162 return AE_BAD_PARAMETER;
163
164 if (function == ACPI_WRITE && !(*value64 == 0 || *value64 == 1))
165 return AE_BAD_PARAMETER;
166
167 result = pmic_get_reg_bit(address, d->power_table,
168 d->power_table_count, &reg, &bit);
169 if (result == -ENOENT)
170 return AE_BAD_PARAMETER;
171
172 mutex_lock(&opregion->lock);
173
174 result = function == ACPI_READ ?
175 d->get_power(regmap, reg, bit, value64) :
176 d->update_power(regmap, reg, bit, *value64 == 1);
177
178 mutex_unlock(&opregion->lock);
179
180 return result ? AE_ERROR : AE_OK;
181}
182
183static int pmic_read_temp(struct intel_pmic_opregion *opregion,
184 int reg, u64 *value)
185{
186 int raw_temp, temp;
187
188 if (!opregion->data->get_raw_temp)
189 return -ENXIO;
190
191 raw_temp = opregion->data->get_raw_temp(opregion->regmap, reg);
192 if (raw_temp < 0)
193 return raw_temp;
194
195 if (!opregion->lpat) {
196 *value = raw_temp;
197 return 0;
198 }
199
200 temp = raw_to_temp(opregion->lpat, opregion->lpat_count, raw_temp);
201 if (temp < 0)
202 return temp;
203
204 *value = temp;
205 return 0;
206}
207
208static int pmic_thermal_temp(struct intel_pmic_opregion *opregion, int reg,
209 u32 function, u64 *value)
210{
211 return function == ACPI_READ ?
212 pmic_read_temp(opregion, reg, value) : -EINVAL;
213}
214
215static int pmic_thermal_aux(struct intel_pmic_opregion *opregion, int reg,
216 u32 function, u64 *value)
217{
218 int raw_temp;
219
220 if (function == ACPI_READ)
221 return pmic_read_temp(opregion, reg, value);
222
223 if (!opregion->data->update_aux)
224 return -ENXIO;
225
226 if (opregion->lpat) {
227 raw_temp = temp_to_raw(opregion->lpat, opregion->lpat_count,
228 *value);
229 if (raw_temp < 0)
230 return raw_temp;
231 } else {
232 raw_temp = *value;
233 }
234
235 return opregion->data->update_aux(opregion->regmap, reg, raw_temp);
236}
237
238static int pmic_thermal_pen(struct intel_pmic_opregion *opregion, int reg,
239 u32 function, u64 *value)
240{
241 struct intel_pmic_opregion_data *d = opregion->data;
242 struct regmap *regmap = opregion->regmap;
243
244 if (!d->get_policy || !d->update_policy)
245 return -ENXIO;
246
247 if (function == ACPI_READ)
248 return d->get_policy(regmap, reg, value);
249
250 if (*value != 0 && *value != 1)
251 return -EINVAL;
252
253 return d->update_policy(regmap, reg, *value);
254}
255
256static bool pmic_thermal_is_temp(int address)
257{
258 return (address <= 0x3c) && !(address % 12);
259}
260
261static bool pmic_thermal_is_aux(int address)
262{
263 return (address >= 4 && address <= 0x40 && !((address - 4) % 12)) ||
264 (address >= 8 && address <= 0x44 && !((address - 8) % 12));
265}
266
267static bool pmic_thermal_is_pen(int address)
268{
269 return address >= 0x48 && address <= 0x5c;
270}
271
272static acpi_status intel_pmic_thermal_handler(u32 function,
273 acpi_physical_address address, u32 bits, u64 *value64,
274 void *handler_context, void *region_context)
275{
276 struct intel_pmic_opregion *opregion = region_context;
277 struct intel_pmic_opregion_data *d = opregion->data;
278 int reg, result;
279
280 if (bits != 32 || !value64)
281 return AE_BAD_PARAMETER;
282
283 result = pmic_get_reg_bit(address, d->thermal_table,
284 d->thermal_table_count, &reg, NULL);
285 if (result == -ENOENT)
286 return AE_BAD_PARAMETER;
287
288 mutex_lock(&opregion->lock);
289
290 if (pmic_thermal_is_temp(address))
291 result = pmic_thermal_temp(opregion, reg, function, value64);
292 else if (pmic_thermal_is_aux(address))
293 result = pmic_thermal_aux(opregion, reg, function, value64);
294 else if (pmic_thermal_is_pen(address))
295 result = pmic_thermal_pen(opregion, reg, function, value64);
296 else
297 result = -EINVAL;
298
299 mutex_unlock(&opregion->lock);
300
301 if (result < 0) {
302 if (result == -EINVAL)
303 return AE_BAD_PARAMETER;
304 else
305 return AE_ERROR;
306 }
307
308 return AE_OK;
309}
310
311int intel_pmic_install_opregion_handler(struct device *dev, acpi_handle handle,
312 struct regmap *regmap,
313 struct intel_pmic_opregion_data *d)
314{
315 acpi_status status;
316 struct intel_pmic_opregion *opregion;
317
318 if (!dev || !regmap || !d)
319 return -EINVAL;
320
321 if (!handle)
322 return -ENODEV;
323
324 opregion = devm_kzalloc(dev, sizeof(*opregion), GFP_KERNEL);
325 if (!opregion)
326 return -ENOMEM;
327
328 mutex_init(&opregion->lock);
329 opregion->regmap = regmap;
330 pmic_thermal_lpat(opregion, handle, dev);
331
332 status = acpi_install_address_space_handler(handle,
333 PMIC_POWER_OPREGION_ID,
334 intel_pmic_power_handler,
335 NULL, opregion);
336 if (ACPI_FAILURE(status))
337 return -ENODEV;
338
339 status = acpi_install_address_space_handler(handle,
340 PMIC_THERMAL_OPREGION_ID,
341 intel_pmic_thermal_handler,
342 NULL, opregion);
343 if (ACPI_FAILURE(status)) {
344 acpi_remove_address_space_handler(handle, PMIC_POWER_OPREGION_ID,
345 intel_pmic_power_handler);
346 return -ENODEV;
347 }
348
349 opregion->data = d;
350 return 0;
351}
352EXPORT_SYMBOL_GPL(intel_pmic_install_opregion_handler);
353
354MODULE_LICENSE("GPL");
diff --git a/drivers/acpi/pmic/intel_pmic.h b/drivers/acpi/pmic/intel_pmic.h
new file mode 100644
index 000000000000..d4e90af8f0dd
--- /dev/null
+++ b/drivers/acpi/pmic/intel_pmic.h
@@ -0,0 +1,25 @@
1#ifndef __INTEL_PMIC_H
2#define __INTEL_PMIC_H
3
4struct pmic_table {
5 int address; /* operation region address */
6 int reg; /* corresponding thermal register */
7 int bit; /* control bit for power */
8};
9
10struct intel_pmic_opregion_data {
11 int (*get_power)(struct regmap *r, int reg, int bit, u64 *value);
12 int (*update_power)(struct regmap *r, int reg, int bit, bool on);
13 int (*get_raw_temp)(struct regmap *r, int reg);
14 int (*update_aux)(struct regmap *r, int reg, int raw_temp);
15 int (*get_policy)(struct regmap *r, int reg, u64 *value);
16 int (*update_policy)(struct regmap *r, int reg, int enable);
17 struct pmic_table *power_table;
18 int power_table_count;
19 struct pmic_table *thermal_table;
20 int thermal_table_count;
21};
22
23int intel_pmic_install_opregion_handler(struct device *dev, acpi_handle handle, struct regmap *regmap, struct intel_pmic_opregion_data *d);
24
25#endif
diff --git a/drivers/acpi/pmic/intel_pmic_crc.c b/drivers/acpi/pmic/intel_pmic_crc.c
new file mode 100644
index 000000000000..ef7d8ff95abe
--- /dev/null
+++ b/drivers/acpi/pmic/intel_pmic_crc.c
@@ -0,0 +1,211 @@
1/*
2 * intel_pmic_crc.c - Intel CrystalCove PMIC operation region driver
3 *
4 * Copyright (C) 2014 Intel Corporation. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#include <linux/module.h>
17#include <linux/acpi.h>
18#include <linux/mfd/intel_soc_pmic.h>
19#include <linux/regmap.h>
20#include <linux/platform_device.h>
21#include "intel_pmic.h"
22
23#define PWR_SOURCE_SELECT BIT(1)
24
25#define PMIC_A0LOCK_REG 0xc5
26
27static struct pmic_table power_table[] = {
28 {
29 .address = 0x24,
30 .reg = 0x66,
31 .bit = 0x00,
32 },
33 {
34 .address = 0x48,
35 .reg = 0x5d,
36 .bit = 0x00,
37 },
38};
39
40static struct pmic_table thermal_table[] = {
41 {
42 .address = 0x00,
43 .reg = 0x75
44 },
45 {
46 .address = 0x04,
47 .reg = 0x95
48 },
49 {
50 .address = 0x08,
51 .reg = 0x97
52 },
53 {
54 .address = 0x0c,
55 .reg = 0x77
56 },
57 {
58 .address = 0x10,
59 .reg = 0x9a
60 },
61 {
62 .address = 0x14,
63 .reg = 0x9c
64 },
65 {
66 .address = 0x18,
67 .reg = 0x79
68 },
69 {
70 .address = 0x1c,
71 .reg = 0x9f
72 },
73 {
74 .address = 0x20,
75 .reg = 0xa1
76 },
77 {
78 .address = 0x48,
79 .reg = 0x94
80 },
81 {
82 .address = 0x4c,
83 .reg = 0x99
84 },
85 {
86 .address = 0x50,
87 .reg = 0x9e
88 },
89};
90
91static int intel_crc_pmic_get_power(struct regmap *regmap, int reg,
92 int bit, u64 *value)
93{
94 int data;
95
96 if (regmap_read(regmap, reg, &data))
97 return -EIO;
98
99 *value = (data & PWR_SOURCE_SELECT) && (data & BIT(bit)) ? 1 : 0;
100 return 0;
101}
102
103static int intel_crc_pmic_update_power(struct regmap *regmap, int reg,
104 int bit, bool on)
105{
106 int data;
107
108 if (regmap_read(regmap, reg, &data))
109 return -EIO;
110
111 if (on) {
112 data |= PWR_SOURCE_SELECT | BIT(bit);
113 } else {
114 data &= ~BIT(bit);
115 data |= PWR_SOURCE_SELECT;
116 }
117
118 if (regmap_write(regmap, reg, data))
119 return -EIO;
120 return 0;
121}
122
123static int intel_crc_pmic_get_raw_temp(struct regmap *regmap, int reg)
124{
125 int temp_l, temp_h;
126
127 /*
128 * Raw temperature value is 10bits: 8bits in reg
129 * and 2bits in reg-1: bit0,1
130 */
131 if (regmap_read(regmap, reg, &temp_l) ||
132 regmap_read(regmap, reg - 1, &temp_h))
133 return -EIO;
134
135 return temp_l | (temp_h & 0x3) << 8;
136}
137
138static int intel_crc_pmic_update_aux(struct regmap *regmap, int reg, int raw)
139{
140 return regmap_write(regmap, reg, raw) ||
141 regmap_update_bits(regmap, reg - 1, 0x3, raw >> 8) ? -EIO : 0;
142}
143
144static int intel_crc_pmic_get_policy(struct regmap *regmap, int reg, u64 *value)
145{
146 int pen;
147
148 if (regmap_read(regmap, reg, &pen))
149 return -EIO;
150 *value = pen >> 7;
151 return 0;
152}
153
154static int intel_crc_pmic_update_policy(struct regmap *regmap,
155 int reg, int enable)
156{
157 int alert0;
158
159 /* Update to policy enable bit requires unlocking a0lock */
160 if (regmap_read(regmap, PMIC_A0LOCK_REG, &alert0))
161 return -EIO;
162
163 if (regmap_update_bits(regmap, PMIC_A0LOCK_REG, 0x01, 0))
164 return -EIO;
165
166 if (regmap_update_bits(regmap, reg, 0x80, enable << 7))
167 return -EIO;
168
169 /* restore alert0 */
170 if (regmap_write(regmap, PMIC_A0LOCK_REG, alert0))
171 return -EIO;
172
173 return 0;
174}
175
176static struct intel_pmic_opregion_data intel_crc_pmic_opregion_data = {
177 .get_power = intel_crc_pmic_get_power,
178 .update_power = intel_crc_pmic_update_power,
179 .get_raw_temp = intel_crc_pmic_get_raw_temp,
180 .update_aux = intel_crc_pmic_update_aux,
181 .get_policy = intel_crc_pmic_get_policy,
182 .update_policy = intel_crc_pmic_update_policy,
183 .power_table = power_table,
184 .power_table_count= ARRAY_SIZE(power_table),
185 .thermal_table = thermal_table,
186 .thermal_table_count = ARRAY_SIZE(thermal_table),
187};
188
189static int intel_crc_pmic_opregion_probe(struct platform_device *pdev)
190{
191 struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent);
192 return intel_pmic_install_opregion_handler(&pdev->dev,
193 ACPI_HANDLE(pdev->dev.parent), pmic->regmap,
194 &intel_crc_pmic_opregion_data);
195}
196
197static struct platform_driver intel_crc_pmic_opregion_driver = {
198 .probe = intel_crc_pmic_opregion_probe,
199 .driver = {
200 .name = "crystal_cove_pmic",
201 },
202};
203
204static int __init intel_crc_pmic_opregion_driver_init(void)
205{
206 return platform_driver_register(&intel_crc_pmic_opregion_driver);
207}
208module_init(intel_crc_pmic_opregion_driver_init);
209
210MODULE_DESCRIPTION("CrystalCove ACPI opration region driver");
211MODULE_LICENSE("GPL");
diff --git a/drivers/acpi/pmic/intel_pmic_xpower.c b/drivers/acpi/pmic/intel_pmic_xpower.c
new file mode 100644
index 000000000000..6a082d4de12c
--- /dev/null
+++ b/drivers/acpi/pmic/intel_pmic_xpower.c
@@ -0,0 +1,268 @@
1/*
2 * intel_pmic_xpower.c - XPower AXP288 PMIC operation region driver
3 *
4 * Copyright (C) 2014 Intel Corporation. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#include <linux/module.h>
17#include <linux/acpi.h>
18#include <linux/mfd/axp20x.h>
19#include <linux/regmap.h>
20#include <linux/platform_device.h>
21#include <linux/iio/consumer.h>
22#include "intel_pmic.h"
23
24#define XPOWER_GPADC_LOW 0x5b
25
26static struct pmic_table power_table[] = {
27 {
28 .address = 0x00,
29 .reg = 0x13,
30 .bit = 0x05,
31 },
32 {
33 .address = 0x04,
34 .reg = 0x13,
35 .bit = 0x06,
36 },
37 {
38 .address = 0x08,
39 .reg = 0x13,
40 .bit = 0x07,
41 },
42 {
43 .address = 0x0c,
44 .reg = 0x12,
45 .bit = 0x03,
46 },
47 {
48 .address = 0x10,
49 .reg = 0x12,
50 .bit = 0x04,
51 },
52 {
53 .address = 0x14,
54 .reg = 0x12,
55 .bit = 0x05,
56 },
57 {
58 .address = 0x18,
59 .reg = 0x12,
60 .bit = 0x06,
61 },
62 {
63 .address = 0x1c,
64 .reg = 0x12,
65 .bit = 0x00,
66 },
67 {
68 .address = 0x20,
69 .reg = 0x12,
70 .bit = 0x01,
71 },
72 {
73 .address = 0x24,
74 .reg = 0x12,
75 .bit = 0x02,
76 },
77 {
78 .address = 0x28,
79 .reg = 0x13,
80 .bit = 0x02,
81 },
82 {
83 .address = 0x2c,
84 .reg = 0x13,
85 .bit = 0x03,
86 },
87 {
88 .address = 0x30,
89 .reg = 0x13,
90 .bit = 0x04,
91 },
92 {
93 .address = 0x38,
94 .reg = 0x10,
95 .bit = 0x03,
96 },
97 {
98 .address = 0x3c,
99 .reg = 0x10,
100 .bit = 0x06,
101 },
102 {
103 .address = 0x40,
104 .reg = 0x10,
105 .bit = 0x05,
106 },
107 {
108 .address = 0x44,
109 .reg = 0x10,
110 .bit = 0x04,
111 },
112 {
113 .address = 0x48,
114 .reg = 0x10,
115 .bit = 0x01,
116 },
117 {
118 .address = 0x4c,
119 .reg = 0x10,
120 .bit = 0x00
121 },
122};
123
124/* TMP0 - TMP5 are the same, all from GPADC */
125static struct pmic_table thermal_table[] = {
126 {
127 .address = 0x00,
128 .reg = XPOWER_GPADC_LOW
129 },
130 {
131 .address = 0x0c,
132 .reg = XPOWER_GPADC_LOW
133 },
134 {
135 .address = 0x18,
136 .reg = XPOWER_GPADC_LOW
137 },
138 {
139 .address = 0x24,
140 .reg = XPOWER_GPADC_LOW
141 },
142 {
143 .address = 0x30,
144 .reg = XPOWER_GPADC_LOW
145 },
146 {
147 .address = 0x3c,
148 .reg = XPOWER_GPADC_LOW
149 },
150};
151
152static int intel_xpower_pmic_get_power(struct regmap *regmap, int reg,
153 int bit, u64 *value)
154{
155 int data;
156
157 if (regmap_read(regmap, reg, &data))
158 return -EIO;
159
160 *value = (data & BIT(bit)) ? 1 : 0;
161 return 0;
162}
163
164static int intel_xpower_pmic_update_power(struct regmap *regmap, int reg,
165 int bit, bool on)
166{
167 int data;
168
169 if (regmap_read(regmap, reg, &data))
170 return -EIO;
171
172 if (on)
173 data |= BIT(bit);
174 else
175 data &= ~BIT(bit);
176
177 if (regmap_write(regmap, reg, data))
178 return -EIO;
179
180 return 0;
181}
182
183/**
184 * intel_xpower_pmic_get_raw_temp(): Get raw temperature reading from the PMIC
185 *
186 * @regmap: regmap of the PMIC device
187 * @reg: register to get the reading
188 *
189 * We could get the sensor value by manipulating the HW regs here, but since
190 * the axp288 IIO driver may also access the same regs at the same time, the
191 * APIs provided by IIO subsystem are used here instead to avoid problems. As
192 * a result, the two passed in params are of no actual use.
193 *
194 * Return a positive value on success, errno on failure.
195 */
196static int intel_xpower_pmic_get_raw_temp(struct regmap *regmap, int reg)
197{
198 struct iio_channel *gpadc_chan;
199 int ret, val;
200
201 gpadc_chan = iio_channel_get(NULL, "axp288-system-temp");
202 if (IS_ERR_OR_NULL(gpadc_chan))
203 return -EACCES;
204
205 ret = iio_read_channel_raw(gpadc_chan, &val);
206 if (ret < 0)
207 val = ret;
208
209 iio_channel_release(gpadc_chan);
210 return val;
211}
212
213static struct intel_pmic_opregion_data intel_xpower_pmic_opregion_data = {
214 .get_power = intel_xpower_pmic_get_power,
215 .update_power = intel_xpower_pmic_update_power,
216 .get_raw_temp = intel_xpower_pmic_get_raw_temp,
217 .power_table = power_table,
218 .power_table_count = ARRAY_SIZE(power_table),
219 .thermal_table = thermal_table,
220 .thermal_table_count = ARRAY_SIZE(thermal_table),
221};
222
223static acpi_status intel_xpower_pmic_gpio_handler(u32 function,
224 acpi_physical_address address, u32 bit_width, u64 *value,
225 void *handler_context, void *region_context)
226{
227 return AE_OK;
228}
229
230static int intel_xpower_pmic_opregion_probe(struct platform_device *pdev)
231{
232 struct device *parent = pdev->dev.parent;
233 struct axp20x_dev *axp20x = dev_get_drvdata(parent);
234 acpi_status status;
235 int result;
236
237 status = acpi_install_address_space_handler(ACPI_HANDLE(parent),
238 ACPI_ADR_SPACE_GPIO, intel_xpower_pmic_gpio_handler,
239 NULL, NULL);
240 if (ACPI_FAILURE(status))
241 return -ENODEV;
242
243 result = intel_pmic_install_opregion_handler(&pdev->dev,
244 ACPI_HANDLE(parent), axp20x->regmap,
245 &intel_xpower_pmic_opregion_data);
246 if (result)
247 acpi_remove_address_space_handler(ACPI_HANDLE(parent),
248 ACPI_ADR_SPACE_GPIO,
249 intel_xpower_pmic_gpio_handler);
250
251 return result;
252}
253
254static struct platform_driver intel_xpower_pmic_opregion_driver = {
255 .probe = intel_xpower_pmic_opregion_probe,
256 .driver = {
257 .name = "axp288_pmic_acpi",
258 },
259};
260
261static int __init intel_xpower_pmic_opregion_driver_init(void)
262{
263 return platform_driver_register(&intel_xpower_pmic_opregion_driver);
264}
265module_init(intel_xpower_pmic_opregion_driver_init);
266
267MODULE_DESCRIPTION("XPower AXP288 ACPI operation region driver");
268MODULE_LICENSE("GPL");
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index 17f9ec501972..38472fd5d104 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -334,10 +334,10 @@ static int acpi_processor_get_power_info_default(struct acpi_processor *pr)
334 334
335static int acpi_processor_get_power_info_cst(struct acpi_processor *pr) 335static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
336{ 336{
337 acpi_status status = 0; 337 acpi_status status;
338 u64 count; 338 u64 count;
339 int current_count; 339 int current_count;
340 int i; 340 int i, ret = 0;
341 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 341 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
342 union acpi_object *cst; 342 union acpi_object *cst;
343 343
@@ -358,7 +358,7 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
358 /* There must be at least 2 elements */ 358 /* There must be at least 2 elements */
359 if (!cst || (cst->type != ACPI_TYPE_PACKAGE) || cst->package.count < 2) { 359 if (!cst || (cst->type != ACPI_TYPE_PACKAGE) || cst->package.count < 2) {
360 printk(KERN_ERR PREFIX "not enough elements in _CST\n"); 360 printk(KERN_ERR PREFIX "not enough elements in _CST\n");
361 status = -EFAULT; 361 ret = -EFAULT;
362 goto end; 362 goto end;
363 } 363 }
364 364
@@ -367,7 +367,7 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
367 /* Validate number of power states. */ 367 /* Validate number of power states. */
368 if (count < 1 || count != cst->package.count - 1) { 368 if (count < 1 || count != cst->package.count - 1) {
369 printk(KERN_ERR PREFIX "count given by _CST is not valid\n"); 369 printk(KERN_ERR PREFIX "count given by _CST is not valid\n");
370 status = -EFAULT; 370 ret = -EFAULT;
371 goto end; 371 goto end;
372 } 372 }
373 373
@@ -489,12 +489,12 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
489 489
490 /* Validate number of power states discovered */ 490 /* Validate number of power states discovered */
491 if (current_count < 2) 491 if (current_count < 2)
492 status = -EFAULT; 492 ret = -EFAULT;
493 493
494 end: 494 end:
495 kfree(buffer.pointer); 495 kfree(buffer.pointer);
496 496
497 return status; 497 return ret;
498} 498}
499 499
500static void acpi_processor_power_verify_c3(struct acpi_processor *pr, 500static void acpi_processor_power_verify_c3(struct acpi_processor *pr,
@@ -1111,7 +1111,7 @@ static int acpi_processor_registered;
1111 1111
1112int acpi_processor_power_init(struct acpi_processor *pr) 1112int acpi_processor_power_init(struct acpi_processor *pr)
1113{ 1113{
1114 acpi_status status = 0; 1114 acpi_status status;
1115 int retval; 1115 int retval;
1116 struct cpuidle_device *dev; 1116 struct cpuidle_device *dev;
1117 static int first_run; 1117 static int first_run;
diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
new file mode 100644
index 000000000000..0d083736e25b
--- /dev/null
+++ b/drivers/acpi/property.c
@@ -0,0 +1,551 @@
1/*
2 * ACPI device specific properties support.
3 *
4 * Copyright (C) 2014, Intel Corporation
5 * All rights reserved.
6 *
7 * Authors: Mika Westerberg <mika.westerberg@linux.intel.com>
8 * Darren Hart <dvhart@linux.intel.com>
9 * Rafael J. Wysocki <rafael.j.wysocki@intel.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15
16#include <linux/acpi.h>
17#include <linux/device.h>
18#include <linux/export.h>
19
20#include "internal.h"
21
22/* ACPI _DSD device properties UUID: daffd814-6eba-4d8c-8a91-bc9bbf4aa301 */
23static const u8 prp_uuid[16] = {
24 0x14, 0xd8, 0xff, 0xda, 0xba, 0x6e, 0x8c, 0x4d,
25 0x8a, 0x91, 0xbc, 0x9b, 0xbf, 0x4a, 0xa3, 0x01
26};
27
28static bool acpi_property_value_ok(const union acpi_object *value)
29{
30 int j;
31
32 /*
33 * The value must be an integer, a string, a reference, or a package
34 * whose every element must be an integer, a string, or a reference.
35 */
36 switch (value->type) {
37 case ACPI_TYPE_INTEGER:
38 case ACPI_TYPE_STRING:
39 case ACPI_TYPE_LOCAL_REFERENCE:
40 return true;
41
42 case ACPI_TYPE_PACKAGE:
43 for (j = 0; j < value->package.count; j++)
44 switch (value->package.elements[j].type) {
45 case ACPI_TYPE_INTEGER:
46 case ACPI_TYPE_STRING:
47 case ACPI_TYPE_LOCAL_REFERENCE:
48 continue;
49
50 default:
51 return false;
52 }
53
54 return true;
55 }
56 return false;
57}
58
59static bool acpi_properties_format_valid(const union acpi_object *properties)
60{
61 int i;
62
63 for (i = 0; i < properties->package.count; i++) {
64 const union acpi_object *property;
65
66 property = &properties->package.elements[i];
67 /*
68 * Only two elements allowed, the first one must be a string and
69 * the second one has to satisfy certain conditions.
70 */
71 if (property->package.count != 2
72 || property->package.elements[0].type != ACPI_TYPE_STRING
73 || !acpi_property_value_ok(&property->package.elements[1]))
74 return false;
75 }
76 return true;
77}
78
79static void acpi_init_of_compatible(struct acpi_device *adev)
80{
81 const union acpi_object *of_compatible;
82 struct acpi_hardware_id *hwid;
83 bool acpi_of = false;
84 int ret;
85
86 /*
87 * Check if the special PRP0001 ACPI ID is present and in that
88 * case we fill in Device Tree compatible properties for this
89 * device.
90 */
91 list_for_each_entry(hwid, &adev->pnp.ids, list) {
92 if (!strcmp(hwid->id, "PRP0001")) {
93 acpi_of = true;
94 break;
95 }
96 }
97
98 if (!acpi_of)
99 return;
100
101 ret = acpi_dev_get_property_array(adev, "compatible", ACPI_TYPE_STRING,
102 &of_compatible);
103 if (ret) {
104 ret = acpi_dev_get_property(adev, "compatible",
105 ACPI_TYPE_STRING, &of_compatible);
106 if (ret) {
107 acpi_handle_warn(adev->handle,
108 "PRP0001 requires compatible property\n");
109 return;
110 }
111 }
112 adev->data.of_compatible = of_compatible;
113}
114
115void acpi_init_properties(struct acpi_device *adev)
116{
117 struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER };
118 const union acpi_object *desc;
119 acpi_status status;
120 int i;
121
122 status = acpi_evaluate_object_typed(adev->handle, "_DSD", NULL, &buf,
123 ACPI_TYPE_PACKAGE);
124 if (ACPI_FAILURE(status))
125 return;
126
127 desc = buf.pointer;
128 if (desc->package.count % 2)
129 goto fail;
130
131 /* Look for the device properties UUID. */
132 for (i = 0; i < desc->package.count; i += 2) {
133 const union acpi_object *uuid, *properties;
134
135 uuid = &desc->package.elements[i];
136 properties = &desc->package.elements[i + 1];
137
138 /*
139 * The first element must be a UUID and the second one must be
140 * a package.
141 */
142 if (uuid->type != ACPI_TYPE_BUFFER || uuid->buffer.length != 16
143 || properties->type != ACPI_TYPE_PACKAGE)
144 break;
145
146 if (memcmp(uuid->buffer.pointer, prp_uuid, sizeof(prp_uuid)))
147 continue;
148
149 /*
150 * We found the matching UUID. Now validate the format of the
151 * package immediately following it.
152 */
153 if (!acpi_properties_format_valid(properties))
154 break;
155
156 adev->data.pointer = buf.pointer;
157 adev->data.properties = properties;
158
159 acpi_init_of_compatible(adev);
160 return;
161 }
162
163 fail:
164 dev_warn(&adev->dev, "Returned _DSD data is not valid, skipping\n");
165 ACPI_FREE(buf.pointer);
166}
167
168void acpi_free_properties(struct acpi_device *adev)
169{
170 ACPI_FREE((void *)adev->data.pointer);
171 adev->data.of_compatible = NULL;
172 adev->data.pointer = NULL;
173 adev->data.properties = NULL;
174}
175
176/**
177 * acpi_dev_get_property - return an ACPI property with given name
178 * @adev: ACPI device to get property
179 * @name: Name of the property
180 * @type: Expected property type
181 * @obj: Location to store the property value (if not %NULL)
182 *
183 * Look up a property with @name and store a pointer to the resulting ACPI
184 * object at the location pointed to by @obj if found.
185 *
186 * Callers must not attempt to free the returned objects. These objects will be
187 * freed by the ACPI core automatically during the removal of @adev.
188 *
189 * Return: %0 if property with @name has been found (success),
190 * %-EINVAL if the arguments are invalid,
191 * %-ENODATA if the property doesn't exist,
192 * %-EPROTO if the property value type doesn't match @type.
193 */
194int acpi_dev_get_property(struct acpi_device *adev, const char *name,
195 acpi_object_type type, const union acpi_object **obj)
196{
197 const union acpi_object *properties;
198 int i;
199
200 if (!adev || !name)
201 return -EINVAL;
202
203 if (!adev->data.pointer || !adev->data.properties)
204 return -ENODATA;
205
206 properties = adev->data.properties;
207 for (i = 0; i < properties->package.count; i++) {
208 const union acpi_object *propname, *propvalue;
209 const union acpi_object *property;
210
211 property = &properties->package.elements[i];
212
213 propname = &property->package.elements[0];
214 propvalue = &property->package.elements[1];
215
216 if (!strcmp(name, propname->string.pointer)) {
217 if (type != ACPI_TYPE_ANY && propvalue->type != type)
218 return -EPROTO;
219 else if (obj)
220 *obj = propvalue;
221
222 return 0;
223 }
224 }
225 return -ENODATA;
226}
227EXPORT_SYMBOL_GPL(acpi_dev_get_property);
228
229/**
230 * acpi_dev_get_property_array - return an ACPI array property with given name
231 * @adev: ACPI device to get property
232 * @name: Name of the property
233 * @type: Expected type of array elements
234 * @obj: Location to store a pointer to the property value (if not NULL)
235 *
236 * Look up an array property with @name and store a pointer to the resulting
237 * ACPI object at the location pointed to by @obj if found.
238 *
239 * Callers must not attempt to free the returned objects. Those objects will be
240 * freed by the ACPI core automatically during the removal of @adev.
241 *
242 * Return: %0 if array property (package) with @name has been found (success),
243 * %-EINVAL if the arguments are invalid,
244 * %-ENODATA if the property doesn't exist,
245 * %-EPROTO if the property is not a package or the type of its elements
246 * doesn't match @type.
247 */
248int acpi_dev_get_property_array(struct acpi_device *adev, const char *name,
249 acpi_object_type type,
250 const union acpi_object **obj)
251{
252 const union acpi_object *prop;
253 int ret, i;
254
255 ret = acpi_dev_get_property(adev, name, ACPI_TYPE_PACKAGE, &prop);
256 if (ret)
257 return ret;
258
259 if (type != ACPI_TYPE_ANY) {
260 /* Check that all elements are of correct type. */
261 for (i = 0; i < prop->package.count; i++)
262 if (prop->package.elements[i].type != type)
263 return -EPROTO;
264 }
265 if (obj)
266 *obj = prop;
267
268 return 0;
269}
270EXPORT_SYMBOL_GPL(acpi_dev_get_property_array);
271
272/**
273 * acpi_dev_get_property_reference - returns handle to the referenced object
274 * @adev: ACPI device to get property
275 * @name: Name of the property
276 * @index: Index of the reference to return
277 * @args: Location to store the returned reference with optional arguments
278 *
279 * Find property with @name, verifify that it is a package containing at least
280 * one object reference and if so, store the ACPI device object pointer to the
281 * target object in @args->adev. If the reference includes arguments, store
282 * them in the @args->args[] array.
283 *
284 * If there's more than one reference in the property value package, @index is
285 * used to select the one to return.
286 *
287 * Return: %0 on success, negative error code on failure.
288 */
289int acpi_dev_get_property_reference(struct acpi_device *adev,
290 const char *name, size_t index,
291 struct acpi_reference_args *args)
292{
293 const union acpi_object *element, *end;
294 const union acpi_object *obj;
295 struct acpi_device *device;
296 int ret, idx = 0;
297
298 ret = acpi_dev_get_property(adev, name, ACPI_TYPE_ANY, &obj);
299 if (ret)
300 return ret;
301
302 /*
303 * The simplest case is when the value is a single reference. Just
304 * return that reference then.
305 */
306 if (obj->type == ACPI_TYPE_LOCAL_REFERENCE) {
307 if (index)
308 return -EINVAL;
309
310 ret = acpi_bus_get_device(obj->reference.handle, &device);
311 if (ret)
312 return ret;
313
314 args->adev = device;
315 args->nargs = 0;
316 return 0;
317 }
318
319 /*
320 * If it is not a single reference, then it is a package of
321 * references followed by number of ints as follows:
322 *
323 * Package () { REF, INT, REF, INT, INT }
324 *
325 * The index argument is then used to determine which reference
326 * the caller wants (along with the arguments).
327 */
328 if (obj->type != ACPI_TYPE_PACKAGE || index >= obj->package.count)
329 return -EPROTO;
330
331 element = obj->package.elements;
332 end = element + obj->package.count;
333
334 while (element < end) {
335 u32 nargs, i;
336
337 if (element->type != ACPI_TYPE_LOCAL_REFERENCE)
338 return -EPROTO;
339
340 ret = acpi_bus_get_device(element->reference.handle, &device);
341 if (ret)
342 return -ENODEV;
343
344 element++;
345 nargs = 0;
346
347 /* assume following integer elements are all args */
348 for (i = 0; element + i < end; i++) {
349 int type = element[i].type;
350
351 if (type == ACPI_TYPE_INTEGER)
352 nargs++;
353 else if (type == ACPI_TYPE_LOCAL_REFERENCE)
354 break;
355 else
356 return -EPROTO;
357 }
358
359 if (idx++ == index) {
360 args->adev = device;
361 args->nargs = nargs;
362 for (i = 0; i < nargs; i++)
363 args->args[i] = element[i].integer.value;
364
365 return 0;
366 }
367
368 element += nargs;
369 }
370
371 return -EPROTO;
372}
373EXPORT_SYMBOL_GPL(acpi_dev_get_property_reference);
374
375int acpi_dev_prop_get(struct acpi_device *adev, const char *propname,
376 void **valptr)
377{
378 return acpi_dev_get_property(adev, propname, ACPI_TYPE_ANY,
379 (const union acpi_object **)valptr);
380}
381
382int acpi_dev_prop_read_single(struct acpi_device *adev, const char *propname,
383 enum dev_prop_type proptype, void *val)
384{
385 const union acpi_object *obj;
386 int ret;
387
388 if (!val)
389 return -EINVAL;
390
391 if (proptype >= DEV_PROP_U8 && proptype <= DEV_PROP_U64) {
392 ret = acpi_dev_get_property(adev, propname, ACPI_TYPE_INTEGER, &obj);
393 if (ret)
394 return ret;
395
396 switch (proptype) {
397 case DEV_PROP_U8:
398 if (obj->integer.value > U8_MAX)
399 return -EOVERFLOW;
400 *(u8 *)val = obj->integer.value;
401 break;
402 case DEV_PROP_U16:
403 if (obj->integer.value > U16_MAX)
404 return -EOVERFLOW;
405 *(u16 *)val = obj->integer.value;
406 break;
407 case DEV_PROP_U32:
408 if (obj->integer.value > U32_MAX)
409 return -EOVERFLOW;
410 *(u32 *)val = obj->integer.value;
411 break;
412 default:
413 *(u64 *)val = obj->integer.value;
414 break;
415 }
416 } else if (proptype == DEV_PROP_STRING) {
417 ret = acpi_dev_get_property(adev, propname, ACPI_TYPE_STRING, &obj);
418 if (ret)
419 return ret;
420
421 *(char **)val = obj->string.pointer;
422 } else {
423 ret = -EINVAL;
424 }
425 return ret;
426}
427
428static int acpi_copy_property_array_u8(const union acpi_object *items, u8 *val,
429 size_t nval)
430{
431 int i;
432
433 for (i = 0; i < nval; i++) {
434 if (items[i].type != ACPI_TYPE_INTEGER)
435 return -EPROTO;
436 if (items[i].integer.value > U8_MAX)
437 return -EOVERFLOW;
438
439 val[i] = items[i].integer.value;
440 }
441 return 0;
442}
443
444static int acpi_copy_property_array_u16(const union acpi_object *items,
445 u16 *val, size_t nval)
446{
447 int i;
448
449 for (i = 0; i < nval; i++) {
450 if (items[i].type != ACPI_TYPE_INTEGER)
451 return -EPROTO;
452 if (items[i].integer.value > U16_MAX)
453 return -EOVERFLOW;
454
455 val[i] = items[i].integer.value;
456 }
457 return 0;
458}
459
460static int acpi_copy_property_array_u32(const union acpi_object *items,
461 u32 *val, size_t nval)
462{
463 int i;
464
465 for (i = 0; i < nval; i++) {
466 if (items[i].type != ACPI_TYPE_INTEGER)
467 return -EPROTO;
468 if (items[i].integer.value > U32_MAX)
469 return -EOVERFLOW;
470
471 val[i] = items[i].integer.value;
472 }
473 return 0;
474}
475
476static int acpi_copy_property_array_u64(const union acpi_object *items,
477 u64 *val, size_t nval)
478{
479 int i;
480
481 for (i = 0; i < nval; i++) {
482 if (items[i].type != ACPI_TYPE_INTEGER)
483 return -EPROTO;
484
485 val[i] = items[i].integer.value;
486 }
487 return 0;
488}
489
490static int acpi_copy_property_array_string(const union acpi_object *items,
491 char **val, size_t nval)
492{
493 int i;
494
495 for (i = 0; i < nval; i++) {
496 if (items[i].type != ACPI_TYPE_STRING)
497 return -EPROTO;
498
499 val[i] = items[i].string.pointer;
500 }
501 return 0;
502}
503
504int acpi_dev_prop_read(struct acpi_device *adev, const char *propname,
505 enum dev_prop_type proptype, void *val, size_t nval)
506{
507 const union acpi_object *obj;
508 const union acpi_object *items;
509 int ret;
510
511 if (val && nval == 1) {
512 ret = acpi_dev_prop_read_single(adev, propname, proptype, val);
513 if (!ret)
514 return ret;
515 }
516
517 ret = acpi_dev_get_property_array(adev, propname, ACPI_TYPE_ANY, &obj);
518 if (ret)
519 return ret;
520
521 if (!val)
522 return obj->package.count;
523 else if (nval <= 0)
524 return -EINVAL;
525
526 if (nval > obj->package.count)
527 return -EOVERFLOW;
528
529 items = obj->package.elements;
530 switch (proptype) {
531 case DEV_PROP_U8:
532 ret = acpi_copy_property_array_u8(items, (u8 *)val, nval);
533 break;
534 case DEV_PROP_U16:
535 ret = acpi_copy_property_array_u16(items, (u16 *)val, nval);
536 break;
537 case DEV_PROP_U32:
538 ret = acpi_copy_property_array_u32(items, (u32 *)val, nval);
539 break;
540 case DEV_PROP_U64:
541 ret = acpi_copy_property_array_u64(items, (u64 *)val, nval);
542 break;
543 case DEV_PROP_STRING:
544 ret = acpi_copy_property_array_string(items, (char **)val, nval);
545 break;
546 default:
547 ret = -EINVAL;
548 break;
549 }
550 return ret;
551}
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 0476e90b2091..1b1cf558d3d3 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -36,6 +36,8 @@ bool acpi_force_hot_remove;
36 36
37static const char *dummy_hid = "device"; 37static const char *dummy_hid = "device";
38 38
39static LIST_HEAD(acpi_dep_list);
40static DEFINE_MUTEX(acpi_dep_list_lock);
39static LIST_HEAD(acpi_bus_id_list); 41static LIST_HEAD(acpi_bus_id_list);
40static DEFINE_MUTEX(acpi_scan_lock); 42static DEFINE_MUTEX(acpi_scan_lock);
41static LIST_HEAD(acpi_scan_handlers_list); 43static LIST_HEAD(acpi_scan_handlers_list);
@@ -43,6 +45,12 @@ DEFINE_MUTEX(acpi_device_lock);
43LIST_HEAD(acpi_wakeup_device_list); 45LIST_HEAD(acpi_wakeup_device_list);
44static DEFINE_MUTEX(acpi_hp_context_lock); 46static DEFINE_MUTEX(acpi_hp_context_lock);
45 47
48struct acpi_dep_data {
49 struct list_head node;
50 acpi_handle master;
51 acpi_handle slave;
52};
53
46struct acpi_device_bus_id{ 54struct acpi_device_bus_id{
47 char bus_id[15]; 55 char bus_id[15];
48 unsigned int instance_no; 56 unsigned int instance_no;
@@ -124,17 +132,56 @@ static int create_modalias(struct acpi_device *acpi_dev, char *modalias,
124 if (list_empty(&acpi_dev->pnp.ids)) 132 if (list_empty(&acpi_dev->pnp.ids))
125 return 0; 133 return 0;
126 134
127 len = snprintf(modalias, size, "acpi:"); 135 /*
128 size -= len; 136 * If the device has PRP0001 we expose DT compatible modalias
129 137 * instead in form of of:NnameTCcompatible.
130 list_for_each_entry(id, &acpi_dev->pnp.ids, list) { 138 */
131 count = snprintf(&modalias[len], size, "%s:", id->id); 139 if (acpi_dev->data.of_compatible) {
132 if (count < 0) 140 struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER };
133 return -EINVAL; 141 const union acpi_object *of_compatible, *obj;
134 if (count >= size) 142 int i, nval;
135 return -ENOMEM; 143 char *c;
136 len += count; 144
137 size -= count; 145 acpi_get_name(acpi_dev->handle, ACPI_SINGLE_NAME, &buf);
146 /* DT strings are all in lower case */
147 for (c = buf.pointer; *c != '\0'; c++)
148 *c = tolower(*c);
149
150 len = snprintf(modalias, size, "of:N%sT", (char *)buf.pointer);
151 ACPI_FREE(buf.pointer);
152
153 of_compatible = acpi_dev->data.of_compatible;
154 if (of_compatible->type == ACPI_TYPE_PACKAGE) {
155 nval = of_compatible->package.count;
156 obj = of_compatible->package.elements;
157 } else { /* Must be ACPI_TYPE_STRING. */
158 nval = 1;
159 obj = of_compatible;
160 }
161 for (i = 0; i < nval; i++, obj++) {
162 count = snprintf(&modalias[len], size, "C%s",
163 obj->string.pointer);
164 if (count < 0)
165 return -EINVAL;
166 if (count >= size)
167 return -ENOMEM;
168
169 len += count;
170 size -= count;
171 }
172 } else {
173 len = snprintf(modalias, size, "acpi:");
174 size -= len;
175
176 list_for_each_entry(id, &acpi_dev->pnp.ids, list) {
177 count = snprintf(&modalias[len], size, "%s:", id->id);
178 if (count < 0)
179 return -EINVAL;
180 if (count >= size)
181 return -ENOMEM;
182 len += count;
183 size -= count;
184 }
138 } 185 }
139 186
140 modalias[len] = '\0'; 187 modalias[len] = '\0';
@@ -902,6 +949,51 @@ int acpi_match_device_ids(struct acpi_device *device,
902} 949}
903EXPORT_SYMBOL(acpi_match_device_ids); 950EXPORT_SYMBOL(acpi_match_device_ids);
904 951
952/* Performs match against special "PRP0001" shoehorn ACPI ID */
953static bool acpi_of_driver_match_device(struct device *dev,
954 const struct device_driver *drv)
955{
956 const union acpi_object *of_compatible, *obj;
957 struct acpi_device *adev;
958 int i, nval;
959
960 adev = ACPI_COMPANION(dev);
961 if (!adev)
962 return false;
963
964 of_compatible = adev->data.of_compatible;
965 if (!drv->of_match_table || !of_compatible)
966 return false;
967
968 if (of_compatible->type == ACPI_TYPE_PACKAGE) {
969 nval = of_compatible->package.count;
970 obj = of_compatible->package.elements;
971 } else { /* Must be ACPI_TYPE_STRING. */
972 nval = 1;
973 obj = of_compatible;
974 }
975 /* Now we can look for the driver DT compatible strings */
976 for (i = 0; i < nval; i++, obj++) {
977 const struct of_device_id *id;
978
979 for (id = drv->of_match_table; id->compatible[0]; id++)
980 if (!strcasecmp(obj->string.pointer, id->compatible))
981 return true;
982 }
983
984 return false;
985}
986
987bool acpi_driver_match_device(struct device *dev,
988 const struct device_driver *drv)
989{
990 if (!drv->acpi_match_table)
991 return acpi_of_driver_match_device(dev, drv);
992
993 return !!acpi_match_device(drv->acpi_match_table, dev);
994}
995EXPORT_SYMBOL_GPL(acpi_driver_match_device);
996
905static void acpi_free_power_resources_lists(struct acpi_device *device) 997static void acpi_free_power_resources_lists(struct acpi_device *device)
906{ 998{
907 int i; 999 int i;
@@ -922,6 +1014,7 @@ static void acpi_device_release(struct device *dev)
922{ 1014{
923 struct acpi_device *acpi_dev = to_acpi_device(dev); 1015 struct acpi_device *acpi_dev = to_acpi_device(dev);
924 1016
1017 acpi_free_properties(acpi_dev);
925 acpi_free_pnp_ids(&acpi_dev->pnp); 1018 acpi_free_pnp_ids(&acpi_dev->pnp);
926 acpi_free_power_resources_lists(acpi_dev); 1019 acpi_free_power_resources_lists(acpi_dev);
927 kfree(acpi_dev); 1020 kfree(acpi_dev);
@@ -1304,6 +1397,26 @@ int acpi_device_add(struct acpi_device *device,
1304 return result; 1397 return result;
1305} 1398}
1306 1399
1400struct acpi_device *acpi_get_next_child(struct device *dev,
1401 struct acpi_device *child)
1402{
1403 struct acpi_device *adev = ACPI_COMPANION(dev);
1404 struct list_head *head, *next;
1405
1406 if (!adev)
1407 return NULL;
1408
1409 head = &adev->children;
1410 if (list_empty(head))
1411 return NULL;
1412
1413 if (!child)
1414 return list_first_entry(head, struct acpi_device, node);
1415
1416 next = child->node.next;
1417 return next == head ? NULL : list_entry(next, struct acpi_device, node);
1418}
1419
1307/* -------------------------------------------------------------------------- 1420/* --------------------------------------------------------------------------
1308 Driver Management 1421 Driver Management
1309 -------------------------------------------------------------------------- */ 1422 -------------------------------------------------------------------------- */
@@ -1923,9 +2036,11 @@ void acpi_init_device_object(struct acpi_device *device, acpi_handle handle,
1923 device->device_type = type; 2036 device->device_type = type;
1924 device->handle = handle; 2037 device->handle = handle;
1925 device->parent = acpi_bus_get_parent(handle); 2038 device->parent = acpi_bus_get_parent(handle);
2039 device->fwnode.type = FWNODE_ACPI;
1926 acpi_set_device_status(device, sta); 2040 acpi_set_device_status(device, sta);
1927 acpi_device_get_busid(device); 2041 acpi_device_get_busid(device);
1928 acpi_set_pnp_ids(handle, &device->pnp, type); 2042 acpi_set_pnp_ids(handle, &device->pnp, type);
2043 acpi_init_properties(device);
1929 acpi_bus_get_flags(device); 2044 acpi_bus_get_flags(device);
1930 device->flags.match_driver = false; 2045 device->flags.match_driver = false;
1931 device->flags.initialized = true; 2046 device->flags.initialized = true;
@@ -2086,6 +2201,59 @@ static void acpi_scan_init_hotplug(struct acpi_device *adev)
2086 } 2201 }
2087} 2202}
2088 2203
2204static void acpi_device_dep_initialize(struct acpi_device *adev)
2205{
2206 struct acpi_dep_data *dep;
2207 struct acpi_handle_list dep_devices;
2208 acpi_status status;
2209 int i;
2210
2211 if (!acpi_has_method(adev->handle, "_DEP"))
2212 return;
2213
2214 status = acpi_evaluate_reference(adev->handle, "_DEP", NULL,
2215 &dep_devices);
2216 if (ACPI_FAILURE(status)) {
2217 dev_err(&adev->dev, "Failed to evaluate _DEP.\n");
2218 return;
2219 }
2220
2221 for (i = 0; i < dep_devices.count; i++) {
2222 struct acpi_device_info *info;
2223 int skip;
2224
2225 status = acpi_get_object_info(dep_devices.handles[i], &info);
2226 if (ACPI_FAILURE(status)) {
2227 dev_err(&adev->dev, "Error reading device info\n");
2228 continue;
2229 }
2230
2231 /*
2232 * Skip the dependency of Windows System Power
2233 * Management Controller
2234 */
2235 skip = info->valid & ACPI_VALID_HID &&
2236 !strcmp(info->hardware_id.string, "INT3396");
2237
2238 kfree(info);
2239
2240 if (skip)
2241 continue;
2242
2243 dep = kzalloc(sizeof(struct acpi_dep_data), GFP_KERNEL);
2244 if (!dep)
2245 return;
2246
2247 dep->master = dep_devices.handles[i];
2248 dep->slave = adev->handle;
2249 adev->dep_unmet++;
2250
2251 mutex_lock(&acpi_dep_list_lock);
2252 list_add_tail(&dep->node , &acpi_dep_list);
2253 mutex_unlock(&acpi_dep_list_lock);
2254 }
2255}
2256
2089static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used, 2257static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used,
2090 void *not_used, void **return_value) 2258 void *not_used, void **return_value)
2091{ 2259{
@@ -2112,6 +2280,7 @@ static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used,
2112 return AE_CTRL_DEPTH; 2280 return AE_CTRL_DEPTH;
2113 2281
2114 acpi_scan_init_hotplug(device); 2282 acpi_scan_init_hotplug(device);
2283 acpi_device_dep_initialize(device);
2115 2284
2116 out: 2285 out:
2117 if (!*return_value) 2286 if (!*return_value)
@@ -2232,6 +2401,29 @@ static void acpi_bus_attach(struct acpi_device *device)
2232 device->handler->hotplug.notify_online(device); 2401 device->handler->hotplug.notify_online(device);
2233} 2402}
2234 2403
2404void acpi_walk_dep_device_list(acpi_handle handle)
2405{
2406 struct acpi_dep_data *dep, *tmp;
2407 struct acpi_device *adev;
2408
2409 mutex_lock(&acpi_dep_list_lock);
2410 list_for_each_entry_safe(dep, tmp, &acpi_dep_list, node) {
2411 if (dep->master == handle) {
2412 acpi_bus_get_device(dep->slave, &adev);
2413 if (!adev)
2414 continue;
2415
2416 adev->dep_unmet--;
2417 if (!adev->dep_unmet)
2418 acpi_bus_attach(adev);
2419 list_del(&dep->node);
2420 kfree(dep);
2421 }
2422 }
2423 mutex_unlock(&acpi_dep_list_lock);
2424}
2425EXPORT_SYMBOL_GPL(acpi_walk_dep_device_list);
2426
2235/** 2427/**
2236 * acpi_bus_scan - Add ACPI device node objects in a given namespace scope. 2428 * acpi_bus_scan - Add ACPI device node objects in a given namespace scope.
2237 * @handle: Root of the namespace scope to scan. 2429 * @handle: Root of the namespace scope to scan.
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index 05a31b573fc3..8aa9254a387f 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -630,6 +630,7 @@ static int acpi_freeze_begin(void)
630static int acpi_freeze_prepare(void) 630static int acpi_freeze_prepare(void)
631{ 631{
632 acpi_enable_all_wakeup_gpes(); 632 acpi_enable_all_wakeup_gpes();
633 acpi_os_wait_events_complete();
633 enable_irq_wake(acpi_gbl_FADT.sci_interrupt); 634 enable_irq_wake(acpi_gbl_FADT.sci_interrupt);
634 return 0; 635 return 0;
635} 636}
@@ -825,6 +826,7 @@ static void acpi_power_off_prepare(void)
825 /* Prepare to power off the system */ 826 /* Prepare to power off the system */
826 acpi_sleep_prepare(ACPI_STATE_S5); 827 acpi_sleep_prepare(ACPI_STATE_S5);
827 acpi_disable_all_gpes(); 828 acpi_disable_all_gpes();
829 acpi_os_wait_events_complete();
828} 830}
829 831
830static void acpi_power_off(void) 832static void acpi_power_off(void)
diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
index 6d5a6cda0734..93b81523a2fe 100644
--- a/drivers/acpi/tables.c
+++ b/drivers/acpi/tables.c
@@ -190,30 +190,24 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header)
190 } 190 }
191} 191}
192 192
193
194int __init 193int __init
195acpi_table_parse_entries(char *id, 194acpi_parse_entries(char *id, unsigned long table_size,
196 unsigned long table_size, 195 acpi_tbl_entry_handler handler,
197 int entry_id, 196 struct acpi_table_header *table_header,
198 acpi_tbl_entry_handler handler, 197 int entry_id, unsigned int max_entries)
199 unsigned int max_entries)
200{ 198{
201 struct acpi_table_header *table_header = NULL;
202 struct acpi_subtable_header *entry; 199 struct acpi_subtable_header *entry;
203 unsigned int count = 0; 200 int count = 0;
204 unsigned long table_end; 201 unsigned long table_end;
205 acpi_size tbl_size;
206 202
207 if (acpi_disabled) 203 if (acpi_disabled)
208 return -ENODEV; 204 return -ENODEV;
209 205
210 if (!handler) 206 if (!id || !handler)
211 return -EINVAL; 207 return -EINVAL;
212 208
213 if (strncmp(id, ACPI_SIG_MADT, 4) == 0) 209 if (!table_size)
214 acpi_get_table_with_size(id, acpi_apic_instance, &table_header, &tbl_size); 210 return -EINVAL;
215 else
216 acpi_get_table_with_size(id, 0, &table_header, &tbl_size);
217 211
218 if (!table_header) { 212 if (!table_header) {
219 pr_warn("%4.4s not present\n", id); 213 pr_warn("%4.4s not present\n", id);
@@ -230,9 +224,12 @@ acpi_table_parse_entries(char *id,
230 while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) < 224 while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) <
231 table_end) { 225 table_end) {
232 if (entry->type == entry_id 226 if (entry->type == entry_id
233 && (!max_entries || count++ < max_entries)) 227 && (!max_entries || count < max_entries)) {
234 if (handler(entry, table_end)) 228 if (handler(entry, table_end))
235 goto err; 229 return -EINVAL;
230
231 count++;
232 }
236 233
237 /* 234 /*
238 * If entry->length is 0, break from this loop to avoid 235 * If entry->length is 0, break from this loop to avoid
@@ -240,22 +237,53 @@ acpi_table_parse_entries(char *id,
240 */ 237 */
241 if (entry->length == 0) { 238 if (entry->length == 0) {
242 pr_err("[%4.4s:0x%02x] Invalid zero length\n", id, entry_id); 239 pr_err("[%4.4s:0x%02x] Invalid zero length\n", id, entry_id);
243 goto err; 240 return -EINVAL;
244 } 241 }
245 242
246 entry = (struct acpi_subtable_header *) 243 entry = (struct acpi_subtable_header *)
247 ((unsigned long)entry + entry->length); 244 ((unsigned long)entry + entry->length);
248 } 245 }
246
249 if (max_entries && count > max_entries) { 247 if (max_entries && count > max_entries) {
250 pr_warn("[%4.4s:0x%02x] ignored %i entries of %i found\n", 248 pr_warn("[%4.4s:0x%02x] ignored %i entries of %i found\n",
251 id, entry_id, count - max_entries, count); 249 id, entry_id, count - max_entries, count);
252 } 250 }
253 251
254 early_acpi_os_unmap_memory((char *)table_header, tbl_size);
255 return count; 252 return count;
256err: 253}
254
255int __init
256acpi_table_parse_entries(char *id,
257 unsigned long table_size,
258 int entry_id,
259 acpi_tbl_entry_handler handler,
260 unsigned int max_entries)
261{
262 struct acpi_table_header *table_header = NULL;
263 acpi_size tbl_size;
264 int count;
265 u32 instance = 0;
266
267 if (acpi_disabled)
268 return -ENODEV;
269
270 if (!id || !handler)
271 return -EINVAL;
272
273 if (!strncmp(id, ACPI_SIG_MADT, 4))
274 instance = acpi_apic_instance;
275
276 acpi_get_table_with_size(id, instance, &table_header, &tbl_size);
277 if (!table_header) {
278 pr_warn("%4.4s not present\n", id);
279 return -ENODEV;
280 }
281
282 count = acpi_parse_entries(id, table_size, handler, table_header,
283 entry_id, max_entries);
284
257 early_acpi_os_unmap_memory((char *)table_header, tbl_size); 285 early_acpi_os_unmap_memory((char *)table_header, tbl_size);
258 return -EINVAL; 286 return count;
259} 287}
260 288
261int __init 289int __init
diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index 371ac12d25b1..dd8ff63ee2b4 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -136,8 +136,7 @@ acpi_extract_package(union acpi_object *package,
136 break; 136 break;
137 case 'B': 137 case 'B':
138 size_required += 138 size_required +=
139 sizeof(u8 *) + 139 sizeof(u8 *) + element->buffer.length;
140 (element->buffer.length * sizeof(u8));
141 tail_offset += sizeof(u8 *); 140 tail_offset += sizeof(u8 *);
142 break; 141 break;
143 default: 142 default:
@@ -255,7 +254,7 @@ acpi_extract_package(union acpi_object *package,
255 memcpy(tail, element->buffer.pointer, 254 memcpy(tail, element->buffer.pointer,
256 element->buffer.length); 255 element->buffer.length);
257 head += sizeof(u8 *); 256 head += sizeof(u8 *);
258 tail += element->buffer.length * sizeof(u8); 257 tail += element->buffer.length;
259 break; 258 break;
260 default: 259 default:
261 /* Should never get here */ 260 /* Should never get here */
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index 807a88a0f394..185a57d13723 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -1164,7 +1164,8 @@ static bool acpi_video_device_in_dod(struct acpi_video_device *device)
1164 return true; 1164 return true;
1165 1165
1166 for (i = 0; i < video->attached_count; i++) { 1166 for (i = 0; i < video->attached_count; i++) {
1167 if (video->attached_array[i].bind_info == device) 1167 if ((video->attached_array[i].value.int_val & 0xfff) ==
1168 (device->device_id & 0xfff))
1168 return true; 1169 return true;
1169 } 1170 }
1170 1171
@@ -1680,6 +1681,19 @@ static void acpi_video_dev_register_backlight(struct acpi_video_device *device)
1680 printk(KERN_ERR PREFIX "Create sysfs link\n"); 1681 printk(KERN_ERR PREFIX "Create sysfs link\n");
1681} 1682}
1682 1683
1684static void acpi_video_run_bcl_for_osi(struct acpi_video_bus *video)
1685{
1686 struct acpi_video_device *dev;
1687 union acpi_object *levels;
1688
1689 mutex_lock(&video->device_list_lock);
1690 list_for_each_entry(dev, &video->video_device_list, entry) {
1691 if (!acpi_video_device_lcd_query_levels(dev, &levels))
1692 kfree(levels);
1693 }
1694 mutex_unlock(&video->device_list_lock);
1695}
1696
1683static int acpi_video_bus_register_backlight(struct acpi_video_bus *video) 1697static int acpi_video_bus_register_backlight(struct acpi_video_bus *video)
1684{ 1698{
1685 struct acpi_video_device *dev; 1699 struct acpi_video_device *dev;
@@ -1687,6 +1701,8 @@ static int acpi_video_bus_register_backlight(struct acpi_video_bus *video)
1687 if (video->backlight_registered) 1701 if (video->backlight_registered)
1688 return 0; 1702 return 0;
1689 1703
1704 acpi_video_run_bcl_for_osi(video);
1705
1690 if (!acpi_video_verify_backlight_support()) 1706 if (!acpi_video_verify_backlight_support())
1691 return 0; 1707 return 0;
1692 1708
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index e45f83789809..49f1e6890587 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -321,6 +321,9 @@ static const struct pci_device_id ahci_pci_tbl[] = {
321 { PCI_VDEVICE(INTEL, 0x8c87), board_ahci }, /* 9 Series RAID */ 321 { PCI_VDEVICE(INTEL, 0x8c87), board_ahci }, /* 9 Series RAID */
322 { PCI_VDEVICE(INTEL, 0x8c8e), board_ahci }, /* 9 Series RAID */ 322 { PCI_VDEVICE(INTEL, 0x8c8e), board_ahci }, /* 9 Series RAID */
323 { PCI_VDEVICE(INTEL, 0x8c8f), board_ahci }, /* 9 Series RAID */ 323 { PCI_VDEVICE(INTEL, 0x8c8f), board_ahci }, /* 9 Series RAID */
324 { PCI_VDEVICE(INTEL, 0x9d03), board_ahci }, /* Sunrise Point-LP AHCI */
325 { PCI_VDEVICE(INTEL, 0x9d05), board_ahci }, /* Sunrise Point-LP RAID */
326 { PCI_VDEVICE(INTEL, 0x9d07), board_ahci }, /* Sunrise Point-LP RAID */
324 { PCI_VDEVICE(INTEL, 0xa103), board_ahci }, /* Sunrise Point-H AHCI */ 327 { PCI_VDEVICE(INTEL, 0xa103), board_ahci }, /* Sunrise Point-H AHCI */
325 { PCI_VDEVICE(INTEL, 0xa103), board_ahci }, /* Sunrise Point-H RAID */ 328 { PCI_VDEVICE(INTEL, 0xa103), board_ahci }, /* Sunrise Point-H RAID */
326 { PCI_VDEVICE(INTEL, 0xa105), board_ahci }, /* Sunrise Point-H RAID */ 329 { PCI_VDEVICE(INTEL, 0xa105), board_ahci }, /* Sunrise Point-H RAID */
@@ -492,6 +495,7 @@ static const struct pci_device_id ahci_pci_tbl[] = {
492 * enabled. https://bugzilla.kernel.org/show_bug.cgi?id=60731 495 * enabled. https://bugzilla.kernel.org/show_bug.cgi?id=60731
493 */ 496 */
494 { PCI_VDEVICE(SAMSUNG, 0x1600), board_ahci_nomsi }, 497 { PCI_VDEVICE(SAMSUNG, 0x1600), board_ahci_nomsi },
498 { PCI_VDEVICE(SAMSUNG, 0xa800), board_ahci_nomsi },
495 499
496 /* Enmotus */ 500 /* Enmotus */
497 { PCI_DEVICE(0x1c44, 0x8000), board_ahci }, 501 { PCI_DEVICE(0x1c44, 0x8000), board_ahci },
diff --git a/drivers/ata/sata_fsl.c b/drivers/ata/sata_fsl.c
index 07bc7e4dbd04..65071591b143 100644
--- a/drivers/ata/sata_fsl.c
+++ b/drivers/ata/sata_fsl.c
@@ -1488,7 +1488,7 @@ static int sata_fsl_probe(struct platform_device *ofdev)
1488 host_priv->csr_base = csr_base; 1488 host_priv->csr_base = csr_base;
1489 1489
1490 irq = irq_of_parse_and_map(ofdev->dev.of_node, 0); 1490 irq = irq_of_parse_and_map(ofdev->dev.of_node, 0);
1491 if (irq < 0) { 1491 if (!irq) {
1492 dev_err(&ofdev->dev, "invalid irq from platform\n"); 1492 dev_err(&ofdev->dev, "invalid irq from platform\n");
1493 goto error_exit_with_cleanup; 1493 goto error_exit_with_cleanup;
1494 } 1494 }
diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
index 7652e8dc188f..21b0bc6a9c96 100644
--- a/drivers/atm/solos-pci.c
+++ b/drivers/atm/solos-pci.c
@@ -1225,11 +1225,13 @@ static int fpga_probe(struct pci_dev *dev, const struct pci_device_id *id)
1225 card->config_regs = pci_iomap(dev, 0, CONFIG_RAM_SIZE); 1225 card->config_regs = pci_iomap(dev, 0, CONFIG_RAM_SIZE);
1226 if (!card->config_regs) { 1226 if (!card->config_regs) {
1227 dev_warn(&dev->dev, "Failed to ioremap config registers\n"); 1227 dev_warn(&dev->dev, "Failed to ioremap config registers\n");
1228 err = -ENOMEM;
1228 goto out_release_regions; 1229 goto out_release_regions;
1229 } 1230 }
1230 card->buffers = pci_iomap(dev, 1, DATA_RAM_SIZE); 1231 card->buffers = pci_iomap(dev, 1, DATA_RAM_SIZE);
1231 if (!card->buffers) { 1232 if (!card->buffers) {
1232 dev_warn(&dev->dev, "Failed to ioremap data buffers\n"); 1233 dev_warn(&dev->dev, "Failed to ioremap data buffers\n");
1234 err = -ENOMEM;
1233 goto out_unmap_config; 1235 goto out_unmap_config;
1234 } 1236 }
1235 1237
diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index 6922cd6850a2..53c3fe1aeb29 100644
--- a/drivers/base/Makefile
+++ b/drivers/base/Makefile
@@ -4,7 +4,7 @@ obj-y := component.o core.o bus.o dd.o syscore.o \
4 driver.o class.o platform.o \ 4 driver.o class.o platform.o \
5 cpu.o firmware.o init.o map.o devres.o \ 5 cpu.o firmware.o init.o map.o devres.o \
6 attribute_container.o transport_class.o \ 6 attribute_container.o transport_class.o \
7 topology.o container.o 7 topology.o container.o property.o
8obj-$(CONFIG_DEVTMPFS) += devtmpfs.o 8obj-$(CONFIG_DEVTMPFS) += devtmpfs.o
9obj-$(CONFIG_DMA_CMA) += dma-contiguous.o 9obj-$(CONFIG_DMA_CMA) += dma-contiguous.o
10obj-y += power/ 10obj-y += power/
diff --git a/drivers/base/power/clock_ops.c b/drivers/base/power/clock_ops.c
index 78369305e069..b32b5d47b3c5 100644
--- a/drivers/base/power/clock_ops.c
+++ b/drivers/base/power/clock_ops.c
@@ -12,6 +12,7 @@
12#include <linux/pm.h> 12#include <linux/pm.h>
13#include <linux/pm_clock.h> 13#include <linux/pm_clock.h>
14#include <linux/clk.h> 14#include <linux/clk.h>
15#include <linux/clkdev.h>
15#include <linux/slab.h> 16#include <linux/slab.h>
16#include <linux/err.h> 17#include <linux/err.h>
17 18
@@ -34,14 +35,20 @@ struct pm_clock_entry {
34/** 35/**
35 * pm_clk_enable - Enable a clock, reporting any errors 36 * pm_clk_enable - Enable a clock, reporting any errors
36 * @dev: The device for the given clock 37 * @dev: The device for the given clock
37 * @clk: The clock being enabled. 38 * @ce: PM clock entry corresponding to the clock.
38 */ 39 */
39static inline int __pm_clk_enable(struct device *dev, struct clk *clk) 40static inline int __pm_clk_enable(struct device *dev, struct pm_clock_entry *ce)
40{ 41{
41 int ret = clk_enable(clk); 42 int ret;
42 if (ret) 43
43 dev_err(dev, "%s: failed to enable clk %p, error %d\n", 44 if (ce->status < PCE_STATUS_ERROR) {
44 __func__, clk, ret); 45 ret = clk_enable(ce->clk);
46 if (!ret)
47 ce->status = PCE_STATUS_ENABLED;
48 else
49 dev_err(dev, "%s: failed to enable clk %p, error %d\n",
50 __func__, ce->clk, ret);
51 }
45 52
46 return ret; 53 return ret;
47} 54}
@@ -53,7 +60,8 @@ static inline int __pm_clk_enable(struct device *dev, struct clk *clk)
53 */ 60 */
54static void pm_clk_acquire(struct device *dev, struct pm_clock_entry *ce) 61static void pm_clk_acquire(struct device *dev, struct pm_clock_entry *ce)
55{ 62{
56 ce->clk = clk_get(dev, ce->con_id); 63 if (!ce->clk)
64 ce->clk = clk_get(dev, ce->con_id);
57 if (IS_ERR(ce->clk)) { 65 if (IS_ERR(ce->clk)) {
58 ce->status = PCE_STATUS_ERROR; 66 ce->status = PCE_STATUS_ERROR;
59 } else { 67 } else {
@@ -63,15 +71,8 @@ static void pm_clk_acquire(struct device *dev, struct pm_clock_entry *ce)
63 } 71 }
64} 72}
65 73
66/** 74static int __pm_clk_add(struct device *dev, const char *con_id,
67 * pm_clk_add - Start using a device clock for power management. 75 struct clk *clk)
68 * @dev: Device whose clock is going to be used for power management.
69 * @con_id: Connection ID of the clock.
70 *
71 * Add the clock represented by @con_id to the list of clocks used for
72 * the power management of @dev.
73 */
74int pm_clk_add(struct device *dev, const char *con_id)
75{ 76{
76 struct pm_subsys_data *psd = dev_to_psd(dev); 77 struct pm_subsys_data *psd = dev_to_psd(dev);
77 struct pm_clock_entry *ce; 78 struct pm_clock_entry *ce;
@@ -93,6 +94,12 @@ int pm_clk_add(struct device *dev, const char *con_id)
93 kfree(ce); 94 kfree(ce);
94 return -ENOMEM; 95 return -ENOMEM;
95 } 96 }
97 } else {
98 if (IS_ERR(ce->clk) || !__clk_get(clk)) {
99 kfree(ce);
100 return -ENOENT;
101 }
102 ce->clk = clk;
96 } 103 }
97 104
98 pm_clk_acquire(dev, ce); 105 pm_clk_acquire(dev, ce);
@@ -104,6 +111,32 @@ int pm_clk_add(struct device *dev, const char *con_id)
104} 111}
105 112
106/** 113/**
114 * pm_clk_add - Start using a device clock for power management.
115 * @dev: Device whose clock is going to be used for power management.
116 * @con_id: Connection ID of the clock.
117 *
118 * Add the clock represented by @con_id to the list of clocks used for
119 * the power management of @dev.
120 */
121int pm_clk_add(struct device *dev, const char *con_id)
122{
123 return __pm_clk_add(dev, con_id, NULL);
124}
125
126/**
127 * pm_clk_add_clk - Start using a device clock for power management.
128 * @dev: Device whose clock is going to be used for power management.
129 * @clk: Clock pointer
130 *
131 * Add the clock to the list of clocks used for the power management of @dev.
132 * It will increment refcount on clock pointer, use clk_put() on it when done.
133 */
134int pm_clk_add_clk(struct device *dev, struct clk *clk)
135{
136 return __pm_clk_add(dev, NULL, clk);
137}
138
139/**
107 * __pm_clk_remove - Destroy PM clock entry. 140 * __pm_clk_remove - Destroy PM clock entry.
108 * @ce: PM clock entry to destroy. 141 * @ce: PM clock entry to destroy.
109 */ 142 */
@@ -266,7 +299,6 @@ int pm_clk_resume(struct device *dev)
266 struct pm_subsys_data *psd = dev_to_psd(dev); 299 struct pm_subsys_data *psd = dev_to_psd(dev);
267 struct pm_clock_entry *ce; 300 struct pm_clock_entry *ce;
268 unsigned long flags; 301 unsigned long flags;
269 int ret;
270 302
271 dev_dbg(dev, "%s()\n", __func__); 303 dev_dbg(dev, "%s()\n", __func__);
272 304
@@ -275,13 +307,8 @@ int pm_clk_resume(struct device *dev)
275 307
276 spin_lock_irqsave(&psd->lock, flags); 308 spin_lock_irqsave(&psd->lock, flags);
277 309
278 list_for_each_entry(ce, &psd->clock_list, node) { 310 list_for_each_entry(ce, &psd->clock_list, node)
279 if (ce->status < PCE_STATUS_ERROR) { 311 __pm_clk_enable(dev, ce);
280 ret = __pm_clk_enable(dev, ce->clk);
281 if (!ret)
282 ce->status = PCE_STATUS_ENABLED;
283 }
284 }
285 312
286 spin_unlock_irqrestore(&psd->lock, flags); 313 spin_unlock_irqrestore(&psd->lock, flags);
287 314
@@ -390,7 +417,6 @@ int pm_clk_resume(struct device *dev)
390 struct pm_subsys_data *psd = dev_to_psd(dev); 417 struct pm_subsys_data *psd = dev_to_psd(dev);
391 struct pm_clock_entry *ce; 418 struct pm_clock_entry *ce;
392 unsigned long flags; 419 unsigned long flags;
393 int ret;
394 420
395 dev_dbg(dev, "%s()\n", __func__); 421 dev_dbg(dev, "%s()\n", __func__);
396 422
@@ -400,13 +426,8 @@ int pm_clk_resume(struct device *dev)
400 426
401 spin_lock_irqsave(&psd->lock, flags); 427 spin_lock_irqsave(&psd->lock, flags);
402 428
403 list_for_each_entry(ce, &psd->clock_list, node) { 429 list_for_each_entry(ce, &psd->clock_list, node)
404 if (ce->status < PCE_STATUS_ERROR) { 430 __pm_clk_enable(dev, ce);
405 ret = __pm_clk_enable(dev, ce->clk);
406 if (!ret)
407 ce->status = PCE_STATUS_ENABLED;
408 }
409 }
410 431
411 spin_unlock_irqrestore(&psd->lock, flags); 432 spin_unlock_irqrestore(&psd->lock, flags);
412 433
diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index fb83d4acd400..5d7b7548873a 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -12,6 +12,7 @@
12#include <linux/pm_runtime.h> 12#include <linux/pm_runtime.h>
13#include <linux/pm_domain.h> 13#include <linux/pm_domain.h>
14#include <linux/pm_qos.h> 14#include <linux/pm_qos.h>
15#include <linux/pm_clock.h>
15#include <linux/slab.h> 16#include <linux/slab.h>
16#include <linux/err.h> 17#include <linux/err.h>
17#include <linux/sched.h> 18#include <linux/sched.h>
@@ -151,6 +152,59 @@ static void genpd_recalc_cpu_exit_latency(struct generic_pm_domain *genpd)
151 genpd->cpuidle_data->idle_state->exit_latency = usecs64; 152 genpd->cpuidle_data->idle_state->exit_latency = usecs64;
152} 153}
153 154
155static int genpd_power_on(struct generic_pm_domain *genpd)
156{
157 ktime_t time_start;
158 s64 elapsed_ns;
159 int ret;
160
161 if (!genpd->power_on)
162 return 0;
163
164 time_start = ktime_get();
165 ret = genpd->power_on(genpd);
166 if (ret)
167 return ret;
168
169 elapsed_ns = ktime_to_ns(ktime_sub(ktime_get(), time_start));
170 if (elapsed_ns <= genpd->power_on_latency_ns)
171 return ret;
172
173 genpd->power_on_latency_ns = elapsed_ns;
174 genpd->max_off_time_changed = true;
175 genpd_recalc_cpu_exit_latency(genpd);
176 pr_warn("%s: Power-%s latency exceeded, new value %lld ns\n",
177 genpd->name, "on", elapsed_ns);
178
179 return ret;
180}
181
182static int genpd_power_off(struct generic_pm_domain *genpd)
183{
184 ktime_t time_start;
185 s64 elapsed_ns;
186 int ret;
187
188 if (!genpd->power_off)
189 return 0;
190
191 time_start = ktime_get();
192 ret = genpd->power_off(genpd);
193 if (ret == -EBUSY)
194 return ret;
195
196 elapsed_ns = ktime_to_ns(ktime_sub(ktime_get(), time_start));
197 if (elapsed_ns <= genpd->power_off_latency_ns)
198 return ret;
199
200 genpd->power_off_latency_ns = elapsed_ns;
201 genpd->max_off_time_changed = true;
202 pr_warn("%s: Power-%s latency exceeded, new value %lld ns\n",
203 genpd->name, "off", elapsed_ns);
204
205 return ret;
206}
207
154/** 208/**
155 * __pm_genpd_poweron - Restore power to a given PM domain and its masters. 209 * __pm_genpd_poweron - Restore power to a given PM domain and its masters.
156 * @genpd: PM domain to power up. 210 * @genpd: PM domain to power up.
@@ -222,25 +276,9 @@ static int __pm_genpd_poweron(struct generic_pm_domain *genpd)
222 } 276 }
223 } 277 }
224 278
225 if (genpd->power_on) { 279 ret = genpd_power_on(genpd);
226 ktime_t time_start = ktime_get(); 280 if (ret)
227 s64 elapsed_ns; 281 goto err;
228
229 ret = genpd->power_on(genpd);
230 if (ret)
231 goto err;
232
233 elapsed_ns = ktime_to_ns(ktime_sub(ktime_get(), time_start));
234 if (elapsed_ns > genpd->power_on_latency_ns) {
235 genpd->power_on_latency_ns = elapsed_ns;
236 genpd->max_off_time_changed = true;
237 genpd_recalc_cpu_exit_latency(genpd);
238 if (genpd->name)
239 pr_warning("%s: Power-on latency exceeded, "
240 "new value %lld ns\n", genpd->name,
241 elapsed_ns);
242 }
243 }
244 282
245 out: 283 out:
246 genpd_set_active(genpd); 284 genpd_set_active(genpd);
@@ -544,16 +582,11 @@ static int pm_genpd_poweroff(struct generic_pm_domain *genpd)
544 } 582 }
545 583
546 if (genpd->power_off) { 584 if (genpd->power_off) {
547 ktime_t time_start;
548 s64 elapsed_ns;
549
550 if (atomic_read(&genpd->sd_count) > 0) { 585 if (atomic_read(&genpd->sd_count) > 0) {
551 ret = -EBUSY; 586 ret = -EBUSY;
552 goto out; 587 goto out;
553 } 588 }
554 589
555 time_start = ktime_get();
556
557 /* 590 /*
558 * If sd_count > 0 at this point, one of the subdomains hasn't 591 * If sd_count > 0 at this point, one of the subdomains hasn't
559 * managed to call pm_genpd_poweron() for the master yet after 592 * managed to call pm_genpd_poweron() for the master yet after
@@ -562,21 +595,11 @@ static int pm_genpd_poweroff(struct generic_pm_domain *genpd)
562 * the pm_genpd_poweron() restore power for us (this shouldn't 595 * the pm_genpd_poweron() restore power for us (this shouldn't
563 * happen very often). 596 * happen very often).
564 */ 597 */
565 ret = genpd->power_off(genpd); 598 ret = genpd_power_off(genpd);
566 if (ret == -EBUSY) { 599 if (ret == -EBUSY) {
567 genpd_set_active(genpd); 600 genpd_set_active(genpd);
568 goto out; 601 goto out;
569 } 602 }
570
571 elapsed_ns = ktime_to_ns(ktime_sub(ktime_get(), time_start));
572 if (elapsed_ns > genpd->power_off_latency_ns) {
573 genpd->power_off_latency_ns = elapsed_ns;
574 genpd->max_off_time_changed = true;
575 if (genpd->name)
576 pr_warning("%s: Power-off latency exceeded, "
577 "new value %lld ns\n", genpd->name,
578 elapsed_ns);
579 }
580 } 603 }
581 604
582 genpd->status = GPD_STATE_POWER_OFF; 605 genpd->status = GPD_STATE_POWER_OFF;
@@ -779,9 +802,9 @@ static inline void genpd_power_off_work_fn(struct work_struct *work) {}
779 * pm_genpd_present - Check if the given PM domain has been initialized. 802 * pm_genpd_present - Check if the given PM domain has been initialized.
780 * @genpd: PM domain to check. 803 * @genpd: PM domain to check.
781 */ 804 */
782static bool pm_genpd_present(struct generic_pm_domain *genpd) 805static bool pm_genpd_present(const struct generic_pm_domain *genpd)
783{ 806{
784 struct generic_pm_domain *gpd; 807 const struct generic_pm_domain *gpd;
785 808
786 if (IS_ERR_OR_NULL(genpd)) 809 if (IS_ERR_OR_NULL(genpd))
787 return false; 810 return false;
@@ -822,8 +845,7 @@ static void pm_genpd_sync_poweroff(struct generic_pm_domain *genpd)
822 || atomic_read(&genpd->sd_count) > 0) 845 || atomic_read(&genpd->sd_count) > 0)
823 return; 846 return;
824 847
825 if (genpd->power_off) 848 genpd_power_off(genpd);
826 genpd->power_off(genpd);
827 849
828 genpd->status = GPD_STATE_POWER_OFF; 850 genpd->status = GPD_STATE_POWER_OFF;
829 851
@@ -854,8 +876,7 @@ static void pm_genpd_sync_poweron(struct generic_pm_domain *genpd)
854 genpd_sd_counter_inc(link->master); 876 genpd_sd_counter_inc(link->master);
855 } 877 }
856 878
857 if (genpd->power_on) 879 genpd_power_on(genpd);
858 genpd->power_on(genpd);
859 880
860 genpd->status = GPD_STATE_ACTIVE; 881 genpd->status = GPD_STATE_ACTIVE;
861} 882}
@@ -1277,8 +1298,7 @@ static int pm_genpd_restore_noirq(struct device *dev)
1277 * If the domain was off before the hibernation, make 1298 * If the domain was off before the hibernation, make
1278 * sure it will be off going forward. 1299 * sure it will be off going forward.
1279 */ 1300 */
1280 if (genpd->power_off) 1301 genpd_power_off(genpd);
1281 genpd->power_off(genpd);
1282 1302
1283 return 0; 1303 return 0;
1284 } 1304 }
@@ -1929,6 +1949,12 @@ void pm_genpd_init(struct generic_pm_domain *genpd,
1929 genpd->domain.ops.complete = pm_genpd_complete; 1949 genpd->domain.ops.complete = pm_genpd_complete;
1930 genpd->dev_ops.save_state = pm_genpd_default_save_state; 1950 genpd->dev_ops.save_state = pm_genpd_default_save_state;
1931 genpd->dev_ops.restore_state = pm_genpd_default_restore_state; 1951 genpd->dev_ops.restore_state = pm_genpd_default_restore_state;
1952
1953 if (genpd->flags & GENPD_FLAG_PM_CLK) {
1954 genpd->dev_ops.stop = pm_clk_suspend;
1955 genpd->dev_ops.start = pm_clk_resume;
1956 }
1957
1932 mutex_lock(&gpd_list_lock); 1958 mutex_lock(&gpd_list_lock);
1933 list_add(&genpd->gpd_list_node, &gpd_list); 1959 list_add(&genpd->gpd_list_node, &gpd_list);
1934 mutex_unlock(&gpd_list_lock); 1960 mutex_unlock(&gpd_list_lock);
@@ -2216,6 +2242,7 @@ int genpd_dev_pm_attach(struct device *dev)
2216 } 2242 }
2217 2243
2218 dev->pm_domain->detach = genpd_dev_pm_detach; 2244 dev->pm_domain->detach = genpd_dev_pm_detach;
2245 pm_genpd_poweron(pd);
2219 2246
2220 return 0; 2247 return 0;
2221} 2248}
diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c
index 89ced955fafa..2d195f3a1998 100644
--- a/drivers/base/power/opp.c
+++ b/drivers/base/power/opp.c
@@ -49,11 +49,12 @@
49 * are protected by the dev_opp_list_lock for integrity. 49 * are protected by the dev_opp_list_lock for integrity.
50 * IMPORTANT: the opp nodes should be maintained in increasing 50 * IMPORTANT: the opp nodes should be maintained in increasing
51 * order. 51 * order.
52 * @dynamic: not-created from static DT entries.
52 * @available: true/false - marks if this OPP as available or not 53 * @available: true/false - marks if this OPP as available or not
53 * @rate: Frequency in hertz 54 * @rate: Frequency in hertz
54 * @u_volt: Nominal voltage in microvolts corresponding to this OPP 55 * @u_volt: Nominal voltage in microvolts corresponding to this OPP
55 * @dev_opp: points back to the device_opp struct this opp belongs to 56 * @dev_opp: points back to the device_opp struct this opp belongs to
56 * @head: RCU callback head used for deferred freeing 57 * @rcu_head: RCU callback head used for deferred freeing
57 * 58 *
58 * This structure stores the OPP information for a given device. 59 * This structure stores the OPP information for a given device.
59 */ 60 */
@@ -61,11 +62,12 @@ struct dev_pm_opp {
61 struct list_head node; 62 struct list_head node;
62 63
63 bool available; 64 bool available;
65 bool dynamic;
64 unsigned long rate; 66 unsigned long rate;
65 unsigned long u_volt; 67 unsigned long u_volt;
66 68
67 struct device_opp *dev_opp; 69 struct device_opp *dev_opp;
68 struct rcu_head head; 70 struct rcu_head rcu_head;
69}; 71};
70 72
71/** 73/**
@@ -76,7 +78,8 @@ struct dev_pm_opp {
76 * RCU usage: nodes are not modified in the list of device_opp, 78 * RCU usage: nodes are not modified in the list of device_opp,
77 * however addition is possible and is secured by dev_opp_list_lock 79 * however addition is possible and is secured by dev_opp_list_lock
78 * @dev: device pointer 80 * @dev: device pointer
79 * @head: notifier head to notify the OPP availability changes. 81 * @srcu_head: notifier head to notify the OPP availability changes.
82 * @rcu_head: RCU callback head used for deferred freeing
80 * @opp_list: list of opps 83 * @opp_list: list of opps
81 * 84 *
82 * This is an internal data structure maintaining the link to opps attached to 85 * This is an internal data structure maintaining the link to opps attached to
@@ -87,7 +90,8 @@ struct device_opp {
87 struct list_head node; 90 struct list_head node;
88 91
89 struct device *dev; 92 struct device *dev;
90 struct srcu_notifier_head head; 93 struct srcu_notifier_head srcu_head;
94 struct rcu_head rcu_head;
91 struct list_head opp_list; 95 struct list_head opp_list;
92}; 96};
93 97
@@ -378,30 +382,8 @@ struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
378} 382}
379EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor); 383EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor);
380 384
381/** 385static int dev_pm_opp_add_dynamic(struct device *dev, unsigned long freq,
382 * dev_pm_opp_add() - Add an OPP table from a table definitions 386 unsigned long u_volt, bool dynamic)
383 * @dev: device for which we do this operation
384 * @freq: Frequency in Hz for this OPP
385 * @u_volt: Voltage in uVolts for this OPP
386 *
387 * This function adds an opp definition to the opp list and returns status.
388 * The opp is made available by default and it can be controlled using
389 * dev_pm_opp_enable/disable functions.
390 *
391 * Locking: The internal device_opp and opp structures are RCU protected.
392 * Hence this function internally uses RCU updater strategy with mutex locks
393 * to keep the integrity of the internal data structures. Callers should ensure
394 * that this function is *NOT* called under RCU protection or in contexts where
395 * mutex cannot be locked.
396 *
397 * Return:
398 * 0: On success OR
399 * Duplicate OPPs (both freq and volt are same) and opp->available
400 * -EEXIST: Freq are same and volt are different OR
401 * Duplicate OPPs (both freq and volt are same) and !opp->available
402 * -ENOMEM: Memory allocation failure
403 */
404int dev_pm_opp_add(struct device *dev, unsigned long freq, unsigned long u_volt)
405{ 387{
406 struct device_opp *dev_opp = NULL; 388 struct device_opp *dev_opp = NULL;
407 struct dev_pm_opp *opp, *new_opp; 389 struct dev_pm_opp *opp, *new_opp;
@@ -417,6 +399,13 @@ int dev_pm_opp_add(struct device *dev, unsigned long freq, unsigned long u_volt)
417 /* Hold our list modification lock here */ 399 /* Hold our list modification lock here */
418 mutex_lock(&dev_opp_list_lock); 400 mutex_lock(&dev_opp_list_lock);
419 401
402 /* populate the opp table */
403 new_opp->dev_opp = dev_opp;
404 new_opp->rate = freq;
405 new_opp->u_volt = u_volt;
406 new_opp->available = true;
407 new_opp->dynamic = dynamic;
408
420 /* Check for existing list for 'dev' */ 409 /* Check for existing list for 'dev' */
421 dev_opp = find_device_opp(dev); 410 dev_opp = find_device_opp(dev);
422 if (IS_ERR(dev_opp)) { 411 if (IS_ERR(dev_opp)) {
@@ -436,19 +425,15 @@ int dev_pm_opp_add(struct device *dev, unsigned long freq, unsigned long u_volt)
436 } 425 }
437 426
438 dev_opp->dev = dev; 427 dev_opp->dev = dev;
439 srcu_init_notifier_head(&dev_opp->head); 428 srcu_init_notifier_head(&dev_opp->srcu_head);
440 INIT_LIST_HEAD(&dev_opp->opp_list); 429 INIT_LIST_HEAD(&dev_opp->opp_list);
441 430
442 /* Secure the device list modification */ 431 /* Secure the device list modification */
443 list_add_rcu(&dev_opp->node, &dev_opp_list); 432 list_add_rcu(&dev_opp->node, &dev_opp_list);
433 head = &dev_opp->opp_list;
434 goto list_add;
444 } 435 }
445 436
446 /* populate the opp table */
447 new_opp->dev_opp = dev_opp;
448 new_opp->rate = freq;
449 new_opp->u_volt = u_volt;
450 new_opp->available = true;
451
452 /* 437 /*
453 * Insert new OPP in order of increasing frequency 438 * Insert new OPP in order of increasing frequency
454 * and discard if already present 439 * and discard if already present
@@ -474,6 +459,7 @@ int dev_pm_opp_add(struct device *dev, unsigned long freq, unsigned long u_volt)
474 return ret; 459 return ret;
475 } 460 }
476 461
462list_add:
477 list_add_rcu(&new_opp->node, head); 463 list_add_rcu(&new_opp->node, head);
478 mutex_unlock(&dev_opp_list_lock); 464 mutex_unlock(&dev_opp_list_lock);
479 465
@@ -481,11 +467,109 @@ int dev_pm_opp_add(struct device *dev, unsigned long freq, unsigned long u_volt)
481 * Notify the changes in the availability of the operable 467 * Notify the changes in the availability of the operable
482 * frequency/voltage list. 468 * frequency/voltage list.
483 */ 469 */
484 srcu_notifier_call_chain(&dev_opp->head, OPP_EVENT_ADD, new_opp); 470 srcu_notifier_call_chain(&dev_opp->srcu_head, OPP_EVENT_ADD, new_opp);
485 return 0; 471 return 0;
486} 472}
473
474/**
475 * dev_pm_opp_add() - Add an OPP table from a table definitions
476 * @dev: device for which we do this operation
477 * @freq: Frequency in Hz for this OPP
478 * @u_volt: Voltage in uVolts for this OPP
479 *
480 * This function adds an opp definition to the opp list and returns status.
481 * The opp is made available by default and it can be controlled using
482 * dev_pm_opp_enable/disable functions.
483 *
484 * Locking: The internal device_opp and opp structures are RCU protected.
485 * Hence this function internally uses RCU updater strategy with mutex locks
486 * to keep the integrity of the internal data structures. Callers should ensure
487 * that this function is *NOT* called under RCU protection or in contexts where
488 * mutex cannot be locked.
489 *
490 * Return:
491 * 0: On success OR
492 * Duplicate OPPs (both freq and volt are same) and opp->available
493 * -EEXIST: Freq are same and volt are different OR
494 * Duplicate OPPs (both freq and volt are same) and !opp->available
495 * -ENOMEM: Memory allocation failure
496 */
497int dev_pm_opp_add(struct device *dev, unsigned long freq, unsigned long u_volt)
498{
499 return dev_pm_opp_add_dynamic(dev, freq, u_volt, true);
500}
487EXPORT_SYMBOL_GPL(dev_pm_opp_add); 501EXPORT_SYMBOL_GPL(dev_pm_opp_add);
488 502
503static void kfree_opp_rcu(struct rcu_head *head)
504{
505 struct dev_pm_opp *opp = container_of(head, struct dev_pm_opp, rcu_head);
506
507 kfree_rcu(opp, rcu_head);
508}
509
510static void kfree_device_rcu(struct rcu_head *head)
511{
512 struct device_opp *device_opp = container_of(head, struct device_opp, rcu_head);
513
514 kfree(device_opp);
515}
516
517void __dev_pm_opp_remove(struct device_opp *dev_opp, struct dev_pm_opp *opp)
518{
519 /*
520 * Notify the changes in the availability of the operable
521 * frequency/voltage list.
522 */
523 srcu_notifier_call_chain(&dev_opp->srcu_head, OPP_EVENT_REMOVE, opp);
524 list_del_rcu(&opp->node);
525 call_srcu(&dev_opp->srcu_head.srcu, &opp->rcu_head, kfree_opp_rcu);
526
527 if (list_empty(&dev_opp->opp_list)) {
528 list_del_rcu(&dev_opp->node);
529 call_srcu(&dev_opp->srcu_head.srcu, &dev_opp->rcu_head,
530 kfree_device_rcu);
531 }
532}
533
534/**
535 * dev_pm_opp_remove() - Remove an OPP from OPP list
536 * @dev: device for which we do this operation
537 * @freq: OPP to remove with matching 'freq'
538 *
539 * This function removes an opp from the opp list.
540 */
541void dev_pm_opp_remove(struct device *dev, unsigned long freq)
542{
543 struct dev_pm_opp *opp;
544 struct device_opp *dev_opp;
545 bool found = false;
546
547 /* Hold our list modification lock here */
548 mutex_lock(&dev_opp_list_lock);
549
550 dev_opp = find_device_opp(dev);
551 if (IS_ERR(dev_opp))
552 goto unlock;
553
554 list_for_each_entry(opp, &dev_opp->opp_list, node) {
555 if (opp->rate == freq) {
556 found = true;
557 break;
558 }
559 }
560
561 if (!found) {
562 dev_warn(dev, "%s: Couldn't find OPP with freq: %lu\n",
563 __func__, freq);
564 goto unlock;
565 }
566
567 __dev_pm_opp_remove(dev_opp, opp);
568unlock:
569 mutex_unlock(&dev_opp_list_lock);
570}
571EXPORT_SYMBOL_GPL(dev_pm_opp_remove);
572
489/** 573/**
490 * opp_set_availability() - helper to set the availability of an opp 574 * opp_set_availability() - helper to set the availability of an opp
491 * @dev: device for which we do this operation 575 * @dev: device for which we do this operation
@@ -557,14 +641,14 @@ static int opp_set_availability(struct device *dev, unsigned long freq,
557 641
558 list_replace_rcu(&opp->node, &new_opp->node); 642 list_replace_rcu(&opp->node, &new_opp->node);
559 mutex_unlock(&dev_opp_list_lock); 643 mutex_unlock(&dev_opp_list_lock);
560 kfree_rcu(opp, head); 644 call_srcu(&dev_opp->srcu_head.srcu, &opp->rcu_head, kfree_opp_rcu);
561 645
562 /* Notify the change of the OPP availability */ 646 /* Notify the change of the OPP availability */
563 if (availability_req) 647 if (availability_req)
564 srcu_notifier_call_chain(&dev_opp->head, OPP_EVENT_ENABLE, 648 srcu_notifier_call_chain(&dev_opp->srcu_head, OPP_EVENT_ENABLE,
565 new_opp); 649 new_opp);
566 else 650 else
567 srcu_notifier_call_chain(&dev_opp->head, OPP_EVENT_DISABLE, 651 srcu_notifier_call_chain(&dev_opp->srcu_head, OPP_EVENT_DISABLE,
568 new_opp); 652 new_opp);
569 653
570 return 0; 654 return 0;
@@ -629,7 +713,7 @@ struct srcu_notifier_head *dev_pm_opp_get_notifier(struct device *dev)
629 if (IS_ERR(dev_opp)) 713 if (IS_ERR(dev_opp))
630 return ERR_CAST(dev_opp); /* matching type */ 714 return ERR_CAST(dev_opp); /* matching type */
631 715
632 return &dev_opp->head; 716 return &dev_opp->srcu_head;
633} 717}
634 718
635#ifdef CONFIG_OF 719#ifdef CONFIG_OF
@@ -666,7 +750,7 @@ int of_init_opp_table(struct device *dev)
666 unsigned long freq = be32_to_cpup(val++) * 1000; 750 unsigned long freq = be32_to_cpup(val++) * 1000;
667 unsigned long volt = be32_to_cpup(val++); 751 unsigned long volt = be32_to_cpup(val++);
668 752
669 if (dev_pm_opp_add(dev, freq, volt)) 753 if (dev_pm_opp_add_dynamic(dev, freq, volt, false))
670 dev_warn(dev, "%s: Failed to add OPP %ld\n", 754 dev_warn(dev, "%s: Failed to add OPP %ld\n",
671 __func__, freq); 755 __func__, freq);
672 nr -= 2; 756 nr -= 2;
@@ -675,4 +759,34 @@ int of_init_opp_table(struct device *dev)
675 return 0; 759 return 0;
676} 760}
677EXPORT_SYMBOL_GPL(of_init_opp_table); 761EXPORT_SYMBOL_GPL(of_init_opp_table);
762
763/**
764 * of_free_opp_table() - Free OPP table entries created from static DT entries
765 * @dev: device pointer used to lookup device OPPs.
766 *
767 * Free OPPs created using static entries present in DT.
768 */
769void of_free_opp_table(struct device *dev)
770{
771 struct device_opp *dev_opp = find_device_opp(dev);
772 struct dev_pm_opp *opp, *tmp;
773
774 /* Check for existing list for 'dev' */
775 dev_opp = find_device_opp(dev);
776 if (WARN(IS_ERR(dev_opp), "%s: dev_opp: %ld\n", dev_name(dev),
777 PTR_ERR(dev_opp)))
778 return;
779
780 /* Hold our list modification lock here */
781 mutex_lock(&dev_opp_list_lock);
782
783 /* Free static OPPs */
784 list_for_each_entry_safe(opp, tmp, &dev_opp->opp_list, node) {
785 if (!opp->dynamic)
786 __dev_pm_opp_remove(dev_opp, opp);
787 }
788
789 mutex_unlock(&dev_opp_list_lock);
790}
791EXPORT_SYMBOL_GPL(of_free_opp_table);
678#endif 792#endif
diff --git a/drivers/base/property.c b/drivers/base/property.c
new file mode 100644
index 000000000000..c45845874d4f
--- /dev/null
+++ b/drivers/base/property.c
@@ -0,0 +1,431 @@
1/*
2 * property.c - Unified device property interface.
3 *
4 * Copyright (C) 2014, Intel Corporation
5 * Authors: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
6 * Mika Westerberg <mika.westerberg@linux.intel.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#include <linux/property.h>
14#include <linux/export.h>
15#include <linux/acpi.h>
16#include <linux/of.h>
17
18/**
19 * device_property_present - check if a property of a device is present
20 * @dev: Device whose property is being checked
21 * @propname: Name of the property
22 *
23 * Check if property @propname is present in the device firmware description.
24 */
25bool device_property_present(struct device *dev, const char *propname)
26{
27 if (IS_ENABLED(CONFIG_OF) && dev->of_node)
28 return of_property_read_bool(dev->of_node, propname);
29
30 return !acpi_dev_prop_get(ACPI_COMPANION(dev), propname, NULL);
31}
32EXPORT_SYMBOL_GPL(device_property_present);
33
34/**
35 * fwnode_property_present - check if a property of a firmware node is present
36 * @fwnode: Firmware node whose property to check
37 * @propname: Name of the property
38 */
39bool fwnode_property_present(struct fwnode_handle *fwnode, const char *propname)
40{
41 if (is_of_node(fwnode))
42 return of_property_read_bool(of_node(fwnode), propname);
43 else if (is_acpi_node(fwnode))
44 return !acpi_dev_prop_get(acpi_node(fwnode), propname, NULL);
45
46 return false;
47}
48EXPORT_SYMBOL_GPL(fwnode_property_present);
49
50#define OF_DEV_PROP_READ_ARRAY(node, propname, type, val, nval) \
51 (val) ? of_property_read_##type##_array((node), (propname), (val), (nval)) \
52 : of_property_count_elems_of_size((node), (propname), sizeof(type))
53
54#define DEV_PROP_READ_ARRAY(_dev_, _propname_, _type_, _proptype_, _val_, _nval_) \
55 IS_ENABLED(CONFIG_OF) && _dev_->of_node ? \
56 (OF_DEV_PROP_READ_ARRAY(_dev_->of_node, _propname_, _type_, \
57 _val_, _nval_)) : \
58 acpi_dev_prop_read(ACPI_COMPANION(_dev_), _propname_, \
59 _proptype_, _val_, _nval_)
60
61/**
62 * device_property_read_u8_array - return a u8 array property of a device
63 * @dev: Device to get the property of
64 * @propname: Name of the property
65 * @val: The values are stored here
66 * @nval: Size of the @val array
67 *
68 * Function reads an array of u8 properties with @propname from the device
69 * firmware description and stores them to @val if found.
70 *
71 * Return: %0 if the property was found (success),
72 * %-EINVAL if given arguments are not valid,
73 * %-ENODATA if the property does not have a value,
74 * %-EPROTO if the property is not an array of numbers,
75 * %-EOVERFLOW if the size of the property is not as expected.
76 */
77int device_property_read_u8_array(struct device *dev, const char *propname,
78 u8 *val, size_t nval)
79{
80 return DEV_PROP_READ_ARRAY(dev, propname, u8, DEV_PROP_U8, val, nval);
81}
82EXPORT_SYMBOL_GPL(device_property_read_u8_array);
83
84/**
85 * device_property_read_u16_array - return a u16 array property of a device
86 * @dev: Device to get the property of
87 * @propname: Name of the property
88 * @val: The values are stored here
89 * @nval: Size of the @val array
90 *
91 * Function reads an array of u16 properties with @propname from the device
92 * firmware description and stores them to @val if found.
93 *
94 * Return: %0 if the property was found (success),
95 * %-EINVAL if given arguments are not valid,
96 * %-ENODATA if the property does not have a value,
97 * %-EPROTO if the property is not an array of numbers,
98 * %-EOVERFLOW if the size of the property is not as expected.
99 */
100int device_property_read_u16_array(struct device *dev, const char *propname,
101 u16 *val, size_t nval)
102{
103 return DEV_PROP_READ_ARRAY(dev, propname, u16, DEV_PROP_U16, val, nval);
104}
105EXPORT_SYMBOL_GPL(device_property_read_u16_array);
106
107/**
108 * device_property_read_u32_array - return a u32 array property of a device
109 * @dev: Device to get the property of
110 * @propname: Name of the property
111 * @val: The values are stored here
112 * @nval: Size of the @val array
113 *
114 * Function reads an array of u32 properties with @propname from the device
115 * firmware description and stores them to @val if found.
116 *
117 * Return: %0 if the property was found (success),
118 * %-EINVAL if given arguments are not valid,
119 * %-ENODATA if the property does not have a value,
120 * %-EPROTO if the property is not an array of numbers,
121 * %-EOVERFLOW if the size of the property is not as expected.
122 */
123int device_property_read_u32_array(struct device *dev, const char *propname,
124 u32 *val, size_t nval)
125{
126 return DEV_PROP_READ_ARRAY(dev, propname, u32, DEV_PROP_U32, val, nval);
127}
128EXPORT_SYMBOL_GPL(device_property_read_u32_array);
129
130/**
131 * device_property_read_u64_array - return a u64 array property of a device
132 * @dev: Device to get the property of
133 * @propname: Name of the property
134 * @val: The values are stored here
135 * @nval: Size of the @val array
136 *
137 * Function reads an array of u64 properties with @propname from the device
138 * firmware description and stores them to @val if found.
139 *
140 * Return: %0 if the property was found (success),
141 * %-EINVAL if given arguments are not valid,
142 * %-ENODATA if the property does not have a value,
143 * %-EPROTO if the property is not an array of numbers,
144 * %-EOVERFLOW if the size of the property is not as expected.
145 */
146int device_property_read_u64_array(struct device *dev, const char *propname,
147 u64 *val, size_t nval)
148{
149 return DEV_PROP_READ_ARRAY(dev, propname, u64, DEV_PROP_U64, val, nval);
150}
151EXPORT_SYMBOL_GPL(device_property_read_u64_array);
152
153/**
154 * device_property_read_string_array - return a string array property of device
155 * @dev: Device to get the property of
156 * @propname: Name of the property
157 * @val: The values are stored here
158 * @nval: Size of the @val array
159 *
160 * Function reads an array of string properties with @propname from the device
161 * firmware description and stores them to @val if found.
162 *
163 * Return: %0 if the property was found (success),
164 * %-EINVAL if given arguments are not valid,
165 * %-ENODATA if the property does not have a value,
166 * %-EPROTO or %-EILSEQ if the property is not an array of strings,
167 * %-EOVERFLOW if the size of the property is not as expected.
168 */
169int device_property_read_string_array(struct device *dev, const char *propname,
170 const char **val, size_t nval)
171{
172 return IS_ENABLED(CONFIG_OF) && dev->of_node ?
173 of_property_read_string_array(dev->of_node, propname, val, nval) :
174 acpi_dev_prop_read(ACPI_COMPANION(dev), propname,
175 DEV_PROP_STRING, val, nval);
176}
177EXPORT_SYMBOL_GPL(device_property_read_string_array);
178
179/**
180 * device_property_read_string - return a string property of a device
181 * @dev: Device to get the property of
182 * @propname: Name of the property
183 * @val: The value is stored here
184 *
185 * Function reads property @propname from the device firmware description and
186 * stores the value into @val if found. The value is checked to be a string.
187 *
188 * Return: %0 if the property was found (success),
189 * %-EINVAL if given arguments are not valid,
190 * %-ENODATA if the property does not have a value,
191 * %-EPROTO or %-EILSEQ if the property type is not a string.
192 */
193int device_property_read_string(struct device *dev, const char *propname,
194 const char **val)
195{
196 return IS_ENABLED(CONFIG_OF) && dev->of_node ?
197 of_property_read_string(dev->of_node, propname, val) :
198 acpi_dev_prop_read(ACPI_COMPANION(dev), propname,
199 DEV_PROP_STRING, val, 1);
200}
201EXPORT_SYMBOL_GPL(device_property_read_string);
202
203#define FWNODE_PROP_READ_ARRAY(_fwnode_, _propname_, _type_, _proptype_, _val_, _nval_) \
204({ \
205 int _ret_; \
206 if (is_of_node(_fwnode_)) \
207 _ret_ = OF_DEV_PROP_READ_ARRAY(of_node(_fwnode_), _propname_, \
208 _type_, _val_, _nval_); \
209 else if (is_acpi_node(_fwnode_)) \
210 _ret_ = acpi_dev_prop_read(acpi_node(_fwnode_), _propname_, \
211 _proptype_, _val_, _nval_); \
212 else \
213 _ret_ = -ENXIO; \
214 _ret_; \
215})
216
217/**
218 * fwnode_property_read_u8_array - return a u8 array property of firmware node
219 * @fwnode: Firmware node to get the property of
220 * @propname: Name of the property
221 * @val: The values are stored here
222 * @nval: Size of the @val array
223 *
224 * Read an array of u8 properties with @propname from @fwnode and stores them to
225 * @val if found.
226 *
227 * Return: %0 if the property was found (success),
228 * %-EINVAL if given arguments are not valid,
229 * %-ENODATA if the property does not have a value,
230 * %-EPROTO if the property is not an array of numbers,
231 * %-EOVERFLOW if the size of the property is not as expected,
232 * %-ENXIO if no suitable firmware interface is present.
233 */
234int fwnode_property_read_u8_array(struct fwnode_handle *fwnode,
235 const char *propname, u8 *val, size_t nval)
236{
237 return FWNODE_PROP_READ_ARRAY(fwnode, propname, u8, DEV_PROP_U8,
238 val, nval);
239}
240EXPORT_SYMBOL_GPL(fwnode_property_read_u8_array);
241
242/**
243 * fwnode_property_read_u16_array - return a u16 array property of firmware node
244 * @fwnode: Firmware node to get the property of
245 * @propname: Name of the property
246 * @val: The values are stored here
247 * @nval: Size of the @val array
248 *
249 * Read an array of u16 properties with @propname from @fwnode and store them to
250 * @val if found.
251 *
252 * Return: %0 if the property was found (success),
253 * %-EINVAL if given arguments are not valid,
254 * %-ENODATA if the property does not have a value,
255 * %-EPROTO if the property is not an array of numbers,
256 * %-EOVERFLOW if the size of the property is not as expected,
257 * %-ENXIO if no suitable firmware interface is present.
258 */
259int fwnode_property_read_u16_array(struct fwnode_handle *fwnode,
260 const char *propname, u16 *val, size_t nval)
261{
262 return FWNODE_PROP_READ_ARRAY(fwnode, propname, u16, DEV_PROP_U16,
263 val, nval);
264}
265EXPORT_SYMBOL_GPL(fwnode_property_read_u16_array);
266
267/**
268 * fwnode_property_read_u32_array - return a u32 array property of firmware node
269 * @fwnode: Firmware node to get the property of
270 * @propname: Name of the property
271 * @val: The values are stored here
272 * @nval: Size of the @val array
273 *
274 * Read an array of u32 properties with @propname from @fwnode store them to
275 * @val if found.
276 *
277 * Return: %0 if the property was found (success),
278 * %-EINVAL if given arguments are not valid,
279 * %-ENODATA if the property does not have a value,
280 * %-EPROTO if the property is not an array of numbers,
281 * %-EOVERFLOW if the size of the property is not as expected,
282 * %-ENXIO if no suitable firmware interface is present.
283 */
284int fwnode_property_read_u32_array(struct fwnode_handle *fwnode,
285 const char *propname, u32 *val, size_t nval)
286{
287 return FWNODE_PROP_READ_ARRAY(fwnode, propname, u32, DEV_PROP_U32,
288 val, nval);
289}
290EXPORT_SYMBOL_GPL(fwnode_property_read_u32_array);
291
292/**
293 * fwnode_property_read_u64_array - return a u64 array property firmware node
294 * @fwnode: Firmware node to get the property of
295 * @propname: Name of the property
296 * @val: The values are stored here
297 * @nval: Size of the @val array
298 *
299 * Read an array of u64 properties with @propname from @fwnode and store them to
300 * @val if found.
301 *
302 * Return: %0 if the property was found (success),
303 * %-EINVAL if given arguments are not valid,
304 * %-ENODATA if the property does not have a value,
305 * %-EPROTO if the property is not an array of numbers,
306 * %-EOVERFLOW if the size of the property is not as expected,
307 * %-ENXIO if no suitable firmware interface is present.
308 */
309int fwnode_property_read_u64_array(struct fwnode_handle *fwnode,
310 const char *propname, u64 *val, size_t nval)
311{
312 return FWNODE_PROP_READ_ARRAY(fwnode, propname, u64, DEV_PROP_U64,
313 val, nval);
314}
315EXPORT_SYMBOL_GPL(fwnode_property_read_u64_array);
316
317/**
318 * fwnode_property_read_string_array - return string array property of a node
319 * @fwnode: Firmware node to get the property of
320 * @propname: Name of the property
321 * @val: The values are stored here
322 * @nval: Size of the @val array
323 *
324 * Read an string list property @propname from the given firmware node and store
325 * them to @val if found.
326 *
327 * Return: %0 if the property was found (success),
328 * %-EINVAL if given arguments are not valid,
329 * %-ENODATA if the property does not have a value,
330 * %-EPROTO if the property is not an array of strings,
331 * %-EOVERFLOW if the size of the property is not as expected,
332 * %-ENXIO if no suitable firmware interface is present.
333 */
334int fwnode_property_read_string_array(struct fwnode_handle *fwnode,
335 const char *propname, const char **val,
336 size_t nval)
337{
338 if (is_of_node(fwnode))
339 return of_property_read_string_array(of_node(fwnode), propname,
340 val, nval);
341 else if (is_acpi_node(fwnode))
342 return acpi_dev_prop_read(acpi_node(fwnode), propname,
343 DEV_PROP_STRING, val, nval);
344
345 return -ENXIO;
346}
347EXPORT_SYMBOL_GPL(fwnode_property_read_string_array);
348
349/**
350 * fwnode_property_read_string - return a string property of a firmware node
351 * @fwnode: Firmware node to get the property of
352 * @propname: Name of the property
353 * @val: The value is stored here
354 *
355 * Read property @propname from the given firmware node and store the value into
356 * @val if found. The value is checked to be a string.
357 *
358 * Return: %0 if the property was found (success),
359 * %-EINVAL if given arguments are not valid,
360 * %-ENODATA if the property does not have a value,
361 * %-EPROTO or %-EILSEQ if the property is not a string,
362 * %-ENXIO if no suitable firmware interface is present.
363 */
364int fwnode_property_read_string(struct fwnode_handle *fwnode,
365 const char *propname, const char **val)
366{
367 if (is_of_node(fwnode))
368 return of_property_read_string(of_node(fwnode),propname, val);
369 else if (is_acpi_node(fwnode))
370 return acpi_dev_prop_read(acpi_node(fwnode), propname,
371 DEV_PROP_STRING, val, 1);
372
373 return -ENXIO;
374}
375EXPORT_SYMBOL_GPL(fwnode_property_read_string);
376
377/**
378 * device_get_next_child_node - Return the next child node handle for a device
379 * @dev: Device to find the next child node for.
380 * @child: Handle to one of the device's child nodes or a null handle.
381 */
382struct fwnode_handle *device_get_next_child_node(struct device *dev,
383 struct fwnode_handle *child)
384{
385 if (IS_ENABLED(CONFIG_OF) && dev->of_node) {
386 struct device_node *node;
387
388 node = of_get_next_available_child(dev->of_node, of_node(child));
389 if (node)
390 return &node->fwnode;
391 } else if (IS_ENABLED(CONFIG_ACPI)) {
392 struct acpi_device *node;
393
394 node = acpi_get_next_child(dev, acpi_node(child));
395 if (node)
396 return acpi_fwnode_handle(node);
397 }
398 return NULL;
399}
400EXPORT_SYMBOL_GPL(device_get_next_child_node);
401
402/**
403 * fwnode_handle_put - Drop reference to a device node
404 * @fwnode: Pointer to the device node to drop the reference to.
405 *
406 * This has to be used when terminating device_for_each_child_node() iteration
407 * with break or return to prevent stale device node references from being left
408 * behind.
409 */
410void fwnode_handle_put(struct fwnode_handle *fwnode)
411{
412 if (is_of_node(fwnode))
413 of_node_put(of_node(fwnode));
414}
415EXPORT_SYMBOL_GPL(fwnode_handle_put);
416
417/**
418 * device_get_child_node_count - return the number of child nodes for device
419 * @dev: Device to cound the child nodes for
420 */
421unsigned int device_get_child_node_count(struct device *dev)
422{
423 struct fwnode_handle *child;
424 unsigned int count = 0;
425
426 device_for_each_child_node(dev, child)
427 count++;
428
429 return count;
430}
431EXPORT_SYMBOL_GPL(device_get_child_node_count);
diff --git a/drivers/clk/at91/clk-usb.c b/drivers/clk/at91/clk-usb.c
index 24b5b020753a..a23ac0c724f0 100644
--- a/drivers/clk/at91/clk-usb.c
+++ b/drivers/clk/at91/clk-usb.c
@@ -52,29 +52,26 @@ static unsigned long at91sam9x5_clk_usb_recalc_rate(struct clk_hw *hw,
52 52
53 tmp = pmc_read(pmc, AT91_PMC_USB); 53 tmp = pmc_read(pmc, AT91_PMC_USB);
54 usbdiv = (tmp & AT91_PMC_OHCIUSBDIV) >> SAM9X5_USB_DIV_SHIFT; 54 usbdiv = (tmp & AT91_PMC_OHCIUSBDIV) >> SAM9X5_USB_DIV_SHIFT;
55 return parent_rate / (usbdiv + 1); 55
56 return DIV_ROUND_CLOSEST(parent_rate, (usbdiv + 1));
56} 57}
57 58
58static long at91sam9x5_clk_usb_round_rate(struct clk_hw *hw, unsigned long rate, 59static long at91sam9x5_clk_usb_round_rate(struct clk_hw *hw, unsigned long rate,
59 unsigned long *parent_rate) 60 unsigned long *parent_rate)
60{ 61{
61 unsigned long div; 62 unsigned long div;
62 unsigned long bestrate; 63
63 unsigned long tmp; 64 if (!rate)
65 return -EINVAL;
64 66
65 if (rate >= *parent_rate) 67 if (rate >= *parent_rate)
66 return *parent_rate; 68 return *parent_rate;
67 69
68 div = *parent_rate / rate; 70 div = DIV_ROUND_CLOSEST(*parent_rate, rate);
69 if (div >= SAM9X5_USB_MAX_DIV) 71 if (div > SAM9X5_USB_MAX_DIV + 1)
70 return *parent_rate / (SAM9X5_USB_MAX_DIV + 1); 72 div = SAM9X5_USB_MAX_DIV + 1;
71
72 bestrate = *parent_rate / div;
73 tmp = *parent_rate / (div + 1);
74 if (bestrate - rate > rate - tmp)
75 bestrate = tmp;
76 73
77 return bestrate; 74 return DIV_ROUND_CLOSEST(*parent_rate, div);
78} 75}
79 76
80static int at91sam9x5_clk_usb_set_parent(struct clk_hw *hw, u8 index) 77static int at91sam9x5_clk_usb_set_parent(struct clk_hw *hw, u8 index)
@@ -106,9 +103,13 @@ static int at91sam9x5_clk_usb_set_rate(struct clk_hw *hw, unsigned long rate,
106 u32 tmp; 103 u32 tmp;
107 struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw); 104 struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw);
108 struct at91_pmc *pmc = usb->pmc; 105 struct at91_pmc *pmc = usb->pmc;
109 unsigned long div = parent_rate / rate; 106 unsigned long div;
107
108 if (!rate)
109 return -EINVAL;
110 110
111 if (parent_rate % rate || div < 1 || div >= SAM9X5_USB_MAX_DIV) 111 div = DIV_ROUND_CLOSEST(parent_rate, rate);
112 if (div > SAM9X5_USB_MAX_DIV + 1 || !div)
112 return -EINVAL; 113 return -EINVAL;
113 114
114 tmp = pmc_read(pmc, AT91_PMC_USB) & ~AT91_PMC_OHCIUSBDIV; 115 tmp = pmc_read(pmc, AT91_PMC_USB) & ~AT91_PMC_OHCIUSBDIV;
@@ -253,7 +254,7 @@ static long at91rm9200_clk_usb_round_rate(struct clk_hw *hw, unsigned long rate,
253 254
254 tmp_parent_rate = rate * usb->divisors[i]; 255 tmp_parent_rate = rate * usb->divisors[i];
255 tmp_parent_rate = __clk_round_rate(parent, tmp_parent_rate); 256 tmp_parent_rate = __clk_round_rate(parent, tmp_parent_rate);
256 tmprate = tmp_parent_rate / usb->divisors[i]; 257 tmprate = DIV_ROUND_CLOSEST(tmp_parent_rate, usb->divisors[i]);
257 if (tmprate < rate) 258 if (tmprate < rate)
258 tmpdiff = rate - tmprate; 259 tmpdiff = rate - tmprate;
259 else 260 else
@@ -281,10 +282,10 @@ static int at91rm9200_clk_usb_set_rate(struct clk_hw *hw, unsigned long rate,
281 struct at91_pmc *pmc = usb->pmc; 282 struct at91_pmc *pmc = usb->pmc;
282 unsigned long div; 283 unsigned long div;
283 284
284 if (!rate || parent_rate % rate) 285 if (!rate)
285 return -EINVAL; 286 return -EINVAL;
286 287
287 div = parent_rate / rate; 288 div = DIV_ROUND_CLOSEST(parent_rate, rate);
288 289
289 for (i = 0; i < RM9200_USB_DIV_TAB_SIZE; i++) { 290 for (i = 0; i < RM9200_USB_DIV_TAB_SIZE; i++) {
290 if (usb->divisors[i] == div) { 291 if (usb->divisors[i] == div) {
diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
index 18a9de29df0e..c0a842b335c5 100644
--- a/drivers/clk/clk-divider.c
+++ b/drivers/clk/clk-divider.c
@@ -263,6 +263,14 @@ static int clk_divider_bestdiv(struct clk_hw *hw, unsigned long rate,
263 if (!rate) 263 if (!rate)
264 rate = 1; 264 rate = 1;
265 265
266 /* if read only, just return current value */
267 if (divider->flags & CLK_DIVIDER_READ_ONLY) {
268 bestdiv = readl(divider->reg) >> divider->shift;
269 bestdiv &= div_mask(divider);
270 bestdiv = _get_div(divider, bestdiv);
271 return bestdiv;
272 }
273
266 maxdiv = _get_maxdiv(divider); 274 maxdiv = _get_maxdiv(divider);
267 275
268 if (!(__clk_get_flags(hw->clk) & CLK_SET_RATE_PARENT)) { 276 if (!(__clk_get_flags(hw->clk) & CLK_SET_RATE_PARENT)) {
@@ -361,11 +369,6 @@ const struct clk_ops clk_divider_ops = {
361}; 369};
362EXPORT_SYMBOL_GPL(clk_divider_ops); 370EXPORT_SYMBOL_GPL(clk_divider_ops);
363 371
364const struct clk_ops clk_divider_ro_ops = {
365 .recalc_rate = clk_divider_recalc_rate,
366};
367EXPORT_SYMBOL_GPL(clk_divider_ro_ops);
368
369static struct clk *_register_divider(struct device *dev, const char *name, 372static struct clk *_register_divider(struct device *dev, const char *name,
370 const char *parent_name, unsigned long flags, 373 const char *parent_name, unsigned long flags,
371 void __iomem *reg, u8 shift, u8 width, 374 void __iomem *reg, u8 shift, u8 width,
@@ -391,10 +394,7 @@ static struct clk *_register_divider(struct device *dev, const char *name,
391 } 394 }
392 395
393 init.name = name; 396 init.name = name;
394 if (clk_divider_flags & CLK_DIVIDER_READ_ONLY) 397 init.ops = &clk_divider_ops;
395 init.ops = &clk_divider_ro_ops;
396 else
397 init.ops = &clk_divider_ops;
398 init.flags = flags | CLK_IS_BASIC; 398 init.flags = flags | CLK_IS_BASIC;
399 init.parent_names = (parent_name ? &parent_name: NULL); 399 init.parent_names = (parent_name ? &parent_name: NULL);
400 init.num_parents = (parent_name ? 1 : 0); 400 init.num_parents = (parent_name ? 1 : 0);
diff --git a/drivers/clk/pxa/clk-pxa27x.c b/drivers/clk/pxa/clk-pxa27x.c
index b345cc791e5d..88b9fe13fa44 100644
--- a/drivers/clk/pxa/clk-pxa27x.c
+++ b/drivers/clk/pxa/clk-pxa27x.c
@@ -322,7 +322,7 @@ static unsigned long clk_pxa27x_memory_get_rate(struct clk_hw *hw,
322 unsigned long ccsr = CCSR; 322 unsigned long ccsr = CCSR;
323 323
324 osc_forced = ccsr & (1 << CCCR_CPDIS_BIT); 324 osc_forced = ccsr & (1 << CCCR_CPDIS_BIT);
325 a = cccr & CCCR_A_BIT; 325 a = cccr & (1 << CCCR_A_BIT);
326 l = ccsr & CCSR_L_MASK; 326 l = ccsr & CCSR_L_MASK;
327 327
328 if (osc_forced || a) 328 if (osc_forced || a)
@@ -341,7 +341,7 @@ static u8 clk_pxa27x_memory_get_parent(struct clk_hw *hw)
341 unsigned long ccsr = CCSR; 341 unsigned long ccsr = CCSR;
342 342
343 osc_forced = ccsr & (1 << CCCR_CPDIS_BIT); 343 osc_forced = ccsr & (1 << CCCR_CPDIS_BIT);
344 a = cccr & CCCR_A_BIT; 344 a = cccr & (1 << CCCR_A_BIT);
345 if (osc_forced) 345 if (osc_forced)
346 return PXA_MEM_13Mhz; 346 return PXA_MEM_13Mhz;
347 if (a) 347 if (a)
diff --git a/drivers/clk/qcom/mmcc-apq8084.c b/drivers/clk/qcom/mmcc-apq8084.c
index dab988ab8cf1..157139a5c1ca 100644
--- a/drivers/clk/qcom/mmcc-apq8084.c
+++ b/drivers/clk/qcom/mmcc-apq8084.c
@@ -3122,7 +3122,7 @@ static struct clk_regmap *mmcc_apq8084_clocks[] = {
3122 [ESC1_CLK_SRC] = &esc1_clk_src.clkr, 3122 [ESC1_CLK_SRC] = &esc1_clk_src.clkr,
3123 [HDMI_CLK_SRC] = &hdmi_clk_src.clkr, 3123 [HDMI_CLK_SRC] = &hdmi_clk_src.clkr,
3124 [VSYNC_CLK_SRC] = &vsync_clk_src.clkr, 3124 [VSYNC_CLK_SRC] = &vsync_clk_src.clkr,
3125 [RBCPR_CLK_SRC] = &rbcpr_clk_src.clkr, 3125 [MMSS_RBCPR_CLK_SRC] = &rbcpr_clk_src.clkr,
3126 [RBBMTIMER_CLK_SRC] = &rbbmtimer_clk_src.clkr, 3126 [RBBMTIMER_CLK_SRC] = &rbbmtimer_clk_src.clkr,
3127 [MAPLE_CLK_SRC] = &maple_clk_src.clkr, 3127 [MAPLE_CLK_SRC] = &maple_clk_src.clkr,
3128 [VDP_CLK_SRC] = &vdp_clk_src.clkr, 3128 [VDP_CLK_SRC] = &vdp_clk_src.clkr,
diff --git a/drivers/clk/rockchip/clk.c b/drivers/clk/rockchip/clk.c
index 1e68bff481b8..880a266f0143 100644
--- a/drivers/clk/rockchip/clk.c
+++ b/drivers/clk/rockchip/clk.c
@@ -90,9 +90,7 @@ static struct clk *rockchip_clk_register_branch(const char *name,
90 div->width = div_width; 90 div->width = div_width;
91 div->lock = lock; 91 div->lock = lock;
92 div->table = div_table; 92 div->table = div_table;
93 div_ops = (div_flags & CLK_DIVIDER_READ_ONLY) 93 div_ops = &clk_divider_ops;
94 ? &clk_divider_ro_ops
95 : &clk_divider_ops;
96 } 94 }
97 95
98 clk = clk_register_composite(NULL, name, parent_names, num_parents, 96 clk = clk_register_composite(NULL, name, parent_names, num_parents,
diff --git a/drivers/clocksource/sun4i_timer.c b/drivers/clocksource/sun4i_timer.c
index efb17c3ee120..f4a9c0058b4d 100644
--- a/drivers/clocksource/sun4i_timer.c
+++ b/drivers/clocksource/sun4i_timer.c
@@ -182,6 +182,12 @@ static void __init sun4i_timer_init(struct device_node *node)
182 /* Make sure timer is stopped before playing with interrupts */ 182 /* Make sure timer is stopped before playing with interrupts */
183 sun4i_clkevt_time_stop(0); 183 sun4i_clkevt_time_stop(0);
184 184
185 sun4i_clockevent.cpumask = cpu_possible_mask;
186 sun4i_clockevent.irq = irq;
187
188 clockevents_config_and_register(&sun4i_clockevent, rate,
189 TIMER_SYNC_TICKS, 0xffffffff);
190
185 ret = setup_irq(irq, &sun4i_timer_irq); 191 ret = setup_irq(irq, &sun4i_timer_irq);
186 if (ret) 192 if (ret)
187 pr_warn("failed to setup irq %d\n", irq); 193 pr_warn("failed to setup irq %d\n", irq);
@@ -189,12 +195,6 @@ static void __init sun4i_timer_init(struct device_node *node)
189 /* Enable timer0 interrupt */ 195 /* Enable timer0 interrupt */
190 val = readl(timer_base + TIMER_IRQ_EN_REG); 196 val = readl(timer_base + TIMER_IRQ_EN_REG);
191 writel(val | TIMER_IRQ_EN(0), timer_base + TIMER_IRQ_EN_REG); 197 writel(val | TIMER_IRQ_EN(0), timer_base + TIMER_IRQ_EN_REG);
192
193 sun4i_clockevent.cpumask = cpu_possible_mask;
194 sun4i_clockevent.irq = irq;
195
196 clockevents_config_and_register(&sun4i_clockevent, rate,
197 TIMER_SYNC_TICKS, 0xffffffff);
198} 198}
199CLOCKSOURCE_OF_DECLARE(sun4i, "allwinner,sun4i-a10-timer", 199CLOCKSOURCE_OF_DECLARE(sun4i, "allwinner,sun4i-a10-timer",
200 sun4i_timer_init); 200 sun4i_timer_init);
diff --git a/drivers/dma/dw/core.c b/drivers/dma/dw/core.c
index 244722170410..380478562b7d 100644
--- a/drivers/dma/dw/core.c
+++ b/drivers/dma/dw/core.c
@@ -22,6 +22,7 @@
22#include <linux/mm.h> 22#include <linux/mm.h>
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/pm_runtime.h>
25 26
26#include "../dmaengine.h" 27#include "../dmaengine.h"
27#include "internal.h" 28#include "internal.h"
@@ -1504,6 +1505,9 @@ int dw_dma_probe(struct dw_dma_chip *chip, struct dw_dma_platform_data *pdata)
1504 dw->regs = chip->regs; 1505 dw->regs = chip->regs;
1505 chip->dw = dw; 1506 chip->dw = dw;
1506 1507
1508 pm_runtime_enable(chip->dev);
1509 pm_runtime_get_sync(chip->dev);
1510
1507 dw_params = dma_read_byaddr(chip->regs, DW_PARAMS); 1511 dw_params = dma_read_byaddr(chip->regs, DW_PARAMS);
1508 autocfg = dw_params >> DW_PARAMS_EN & 0x1; 1512 autocfg = dw_params >> DW_PARAMS_EN & 0x1;
1509 1513
@@ -1667,11 +1671,14 @@ int dw_dma_probe(struct dw_dma_chip *chip, struct dw_dma_platform_data *pdata)
1667 dev_info(chip->dev, "DesignWare DMA Controller, %d channels\n", 1671 dev_info(chip->dev, "DesignWare DMA Controller, %d channels\n",
1668 nr_channels); 1672 nr_channels);
1669 1673
1674 pm_runtime_put_sync_suspend(chip->dev);
1675
1670 return 0; 1676 return 0;
1671 1677
1672err_dma_register: 1678err_dma_register:
1673 free_irq(chip->irq, dw); 1679 free_irq(chip->irq, dw);
1674err_pdata: 1680err_pdata:
1681 pm_runtime_put_sync_suspend(chip->dev);
1675 return err; 1682 return err;
1676} 1683}
1677EXPORT_SYMBOL_GPL(dw_dma_probe); 1684EXPORT_SYMBOL_GPL(dw_dma_probe);
@@ -1681,6 +1688,8 @@ int dw_dma_remove(struct dw_dma_chip *chip)
1681 struct dw_dma *dw = chip->dw; 1688 struct dw_dma *dw = chip->dw;
1682 struct dw_dma_chan *dwc, *_dwc; 1689 struct dw_dma_chan *dwc, *_dwc;
1683 1690
1691 pm_runtime_get_sync(chip->dev);
1692
1684 dw_dma_off(dw); 1693 dw_dma_off(dw);
1685 dma_async_device_unregister(&dw->dma); 1694 dma_async_device_unregister(&dw->dma);
1686 1695
@@ -1693,6 +1702,8 @@ int dw_dma_remove(struct dw_dma_chip *chip)
1693 channel_clear_bit(dw, CH_EN, dwc->mask); 1702 channel_clear_bit(dw, CH_EN, dwc->mask);
1694 } 1703 }
1695 1704
1705 pm_runtime_put_sync_suspend(chip->dev);
1706 pm_runtime_disable(chip->dev);
1696 return 0; 1707 return 0;
1697} 1708}
1698EXPORT_SYMBOL_GPL(dw_dma_remove); 1709EXPORT_SYMBOL_GPL(dw_dma_remove);
diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c
index 4839bfa74a10..19a99743cf52 100644
--- a/drivers/dma/pl330.c
+++ b/drivers/dma/pl330.c
@@ -271,7 +271,7 @@ struct pl330_config {
271#define DMAC_MODE_NS (1 << 0) 271#define DMAC_MODE_NS (1 << 0)
272 unsigned int mode; 272 unsigned int mode;
273 unsigned int data_bus_width:10; /* In number of bits */ 273 unsigned int data_bus_width:10; /* In number of bits */
274 unsigned int data_buf_dep:10; 274 unsigned int data_buf_dep:11;
275 unsigned int num_chan:4; 275 unsigned int num_chan:4;
276 unsigned int num_peri:6; 276 unsigned int num_peri:6;
277 u32 peri_ns; 277 u32 peri_ns;
@@ -2336,7 +2336,7 @@ static inline int get_burst_len(struct dma_pl330_desc *desc, size_t len)
2336 int burst_len; 2336 int burst_len;
2337 2337
2338 burst_len = pl330->pcfg.data_bus_width / 8; 2338 burst_len = pl330->pcfg.data_bus_width / 8;
2339 burst_len *= pl330->pcfg.data_buf_dep; 2339 burst_len *= pl330->pcfg.data_buf_dep / pl330->pcfg.num_chan;
2340 burst_len >>= desc->rqcfg.brst_size; 2340 burst_len >>= desc->rqcfg.brst_size;
2341 2341
2342 /* src/dst_burst_len can't be more than 16 */ 2342 /* src/dst_burst_len can't be more than 16 */
@@ -2459,16 +2459,25 @@ pl330_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dst,
2459 /* Select max possible burst size */ 2459 /* Select max possible burst size */
2460 burst = pl330->pcfg.data_bus_width / 8; 2460 burst = pl330->pcfg.data_bus_width / 8;
2461 2461
2462 while (burst > 1) { 2462 /*
2463 if (!(len % burst)) 2463 * Make sure we use a burst size that aligns with all the memcpy
2464 break; 2464 * parameters because our DMA programming algorithm doesn't cope with
2465 * transfers which straddle an entry in the DMA device's MFIFO.
2466 */
2467 while ((src | dst | len) & (burst - 1))
2465 burst /= 2; 2468 burst /= 2;
2466 }
2467 2469
2468 desc->rqcfg.brst_size = 0; 2470 desc->rqcfg.brst_size = 0;
2469 while (burst != (1 << desc->rqcfg.brst_size)) 2471 while (burst != (1 << desc->rqcfg.brst_size))
2470 desc->rqcfg.brst_size++; 2472 desc->rqcfg.brst_size++;
2471 2473
2474 /*
2475 * If burst size is smaller than bus width then make sure we only
2476 * transfer one at a time to avoid a burst stradling an MFIFO entry.
2477 */
2478 if (desc->rqcfg.brst_size * 8 < pl330->pcfg.data_bus_width)
2479 desc->rqcfg.brst_len = 1;
2480
2472 desc->rqcfg.brst_len = get_burst_len(desc, len); 2481 desc->rqcfg.brst_len = get_burst_len(desc, len);
2473 2482
2474 desc->txd.flags = flags; 2483 desc->txd.flags = flags;
@@ -2732,7 +2741,7 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
2732 2741
2733 2742
2734 dev_info(&adev->dev, 2743 dev_info(&adev->dev,
2735 "Loaded driver for PL330 DMAC-%d\n", adev->periphid); 2744 "Loaded driver for PL330 DMAC-%x\n", adev->periphid);
2736 dev_info(&adev->dev, 2745 dev_info(&adev->dev,
2737 "\tDBUFF-%ux%ubytes Num_Chans-%u Num_Peri-%u Num_Events-%u\n", 2746 "\tDBUFF-%ux%ubytes Num_Chans-%u Num_Peri-%u Num_Events-%u\n",
2738 pcfg->data_buf_dep, pcfg->data_bus_width / 8, pcfg->num_chan, 2747 pcfg->data_buf_dep, pcfg->data_bus_width / 8, pcfg->num_chan,
diff --git a/drivers/dma/sun6i-dma.c b/drivers/dma/sun6i-dma.c
index 3aa10b328254..91292f5513ff 100644
--- a/drivers/dma/sun6i-dma.c
+++ b/drivers/dma/sun6i-dma.c
@@ -230,30 +230,25 @@ static inline void sun6i_dma_dump_chan_regs(struct sun6i_dma_dev *sdev,
230 readl(pchan->base + DMA_CHAN_CUR_PARA)); 230 readl(pchan->base + DMA_CHAN_CUR_PARA));
231} 231}
232 232
233static inline int convert_burst(u32 maxburst, u8 *burst) 233static inline s8 convert_burst(u32 maxburst)
234{ 234{
235 switch (maxburst) { 235 switch (maxburst) {
236 case 1: 236 case 1:
237 *burst = 0; 237 return 0;
238 break;
239 case 8: 238 case 8:
240 *burst = 2; 239 return 2;
241 break;
242 default: 240 default:
243 return -EINVAL; 241 return -EINVAL;
244 } 242 }
245
246 return 0;
247} 243}
248 244
249static inline int convert_buswidth(enum dma_slave_buswidth addr_width, u8 *width) 245static inline s8 convert_buswidth(enum dma_slave_buswidth addr_width)
250{ 246{
251 if ((addr_width < DMA_SLAVE_BUSWIDTH_1_BYTE) || 247 if ((addr_width < DMA_SLAVE_BUSWIDTH_1_BYTE) ||
252 (addr_width > DMA_SLAVE_BUSWIDTH_4_BYTES)) 248 (addr_width > DMA_SLAVE_BUSWIDTH_4_BYTES))
253 return -EINVAL; 249 return -EINVAL;
254 250
255 *width = addr_width >> 1; 251 return addr_width >> 1;
256 return 0;
257} 252}
258 253
259static void *sun6i_dma_lli_add(struct sun6i_dma_lli *prev, 254static void *sun6i_dma_lli_add(struct sun6i_dma_lli *prev,
@@ -284,26 +279,25 @@ static inline int sun6i_dma_cfg_lli(struct sun6i_dma_lli *lli,
284 struct dma_slave_config *config) 279 struct dma_slave_config *config)
285{ 280{
286 u8 src_width, dst_width, src_burst, dst_burst; 281 u8 src_width, dst_width, src_burst, dst_burst;
287 int ret;
288 282
289 if (!config) 283 if (!config)
290 return -EINVAL; 284 return -EINVAL;
291 285
292 ret = convert_burst(config->src_maxburst, &src_burst); 286 src_burst = convert_burst(config->src_maxburst);
293 if (ret) 287 if (src_burst)
294 return ret; 288 return src_burst;
295 289
296 ret = convert_burst(config->dst_maxburst, &dst_burst); 290 dst_burst = convert_burst(config->dst_maxburst);
297 if (ret) 291 if (dst_burst)
298 return ret; 292 return dst_burst;
299 293
300 ret = convert_buswidth(config->src_addr_width, &src_width); 294 src_width = convert_buswidth(config->src_addr_width);
301 if (ret) 295 if (src_width)
302 return ret; 296 return src_width;
303 297
304 ret = convert_buswidth(config->dst_addr_width, &dst_width); 298 dst_width = convert_buswidth(config->dst_addr_width);
305 if (ret) 299 if (dst_width)
306 return ret; 300 return dst_width;
307 301
308 lli->cfg = DMA_CHAN_CFG_SRC_BURST(src_burst) | 302 lli->cfg = DMA_CHAN_CFG_SRC_BURST(src_burst) |
309 DMA_CHAN_CFG_SRC_WIDTH(src_width) | 303 DMA_CHAN_CFG_SRC_WIDTH(src_width) |
@@ -542,11 +536,10 @@ static struct dma_async_tx_descriptor *sun6i_dma_prep_dma_memcpy(
542{ 536{
543 struct sun6i_dma_dev *sdev = to_sun6i_dma_dev(chan->device); 537 struct sun6i_dma_dev *sdev = to_sun6i_dma_dev(chan->device);
544 struct sun6i_vchan *vchan = to_sun6i_vchan(chan); 538 struct sun6i_vchan *vchan = to_sun6i_vchan(chan);
545 struct dma_slave_config *sconfig = &vchan->cfg;
546 struct sun6i_dma_lli *v_lli; 539 struct sun6i_dma_lli *v_lli;
547 struct sun6i_desc *txd; 540 struct sun6i_desc *txd;
548 dma_addr_t p_lli; 541 dma_addr_t p_lli;
549 int ret; 542 s8 burst, width;
550 543
551 dev_dbg(chan2dev(chan), 544 dev_dbg(chan2dev(chan),
552 "%s; chan: %d, dest: %pad, src: %pad, len: %zu. flags: 0x%08lx\n", 545 "%s; chan: %d, dest: %pad, src: %pad, len: %zu. flags: 0x%08lx\n",
@@ -565,14 +558,21 @@ static struct dma_async_tx_descriptor *sun6i_dma_prep_dma_memcpy(
565 goto err_txd_free; 558 goto err_txd_free;
566 } 559 }
567 560
568 ret = sun6i_dma_cfg_lli(v_lli, src, dest, len, sconfig); 561 v_lli->src = src;
569 if (ret) 562 v_lli->dst = dest;
570 goto err_dma_free; 563 v_lli->len = len;
564 v_lli->para = NORMAL_WAIT;
571 565
566 burst = convert_burst(8);
567 width = convert_buswidth(DMA_SLAVE_BUSWIDTH_4_BYTES);
572 v_lli->cfg |= DMA_CHAN_CFG_SRC_DRQ(DRQ_SDRAM) | 568 v_lli->cfg |= DMA_CHAN_CFG_SRC_DRQ(DRQ_SDRAM) |
573 DMA_CHAN_CFG_DST_DRQ(DRQ_SDRAM) | 569 DMA_CHAN_CFG_DST_DRQ(DRQ_SDRAM) |
574 DMA_CHAN_CFG_DST_LINEAR_MODE | 570 DMA_CHAN_CFG_DST_LINEAR_MODE |
575 DMA_CHAN_CFG_SRC_LINEAR_MODE; 571 DMA_CHAN_CFG_SRC_LINEAR_MODE |
572 DMA_CHAN_CFG_SRC_BURST(burst) |
573 DMA_CHAN_CFG_SRC_WIDTH(width) |
574 DMA_CHAN_CFG_DST_BURST(burst) |
575 DMA_CHAN_CFG_DST_WIDTH(width);
576 576
577 sun6i_dma_lli_add(NULL, v_lli, p_lli, txd); 577 sun6i_dma_lli_add(NULL, v_lli, p_lli, txd);
578 578
@@ -580,8 +580,6 @@ static struct dma_async_tx_descriptor *sun6i_dma_prep_dma_memcpy(
580 580
581 return vchan_tx_prep(&vchan->vc, &txd->vd, flags); 581 return vchan_tx_prep(&vchan->vc, &txd->vd, flags);
582 582
583err_dma_free:
584 dma_pool_free(sdev->pool, v_lli, p_lli);
585err_txd_free: 583err_txd_free:
586 kfree(txd); 584 kfree(txd);
587 return NULL; 585 return NULL;
@@ -915,6 +913,7 @@ static int sun6i_dma_probe(struct platform_device *pdev)
915 sdc->slave.device_prep_dma_memcpy = sun6i_dma_prep_dma_memcpy; 913 sdc->slave.device_prep_dma_memcpy = sun6i_dma_prep_dma_memcpy;
916 sdc->slave.device_control = sun6i_dma_control; 914 sdc->slave.device_control = sun6i_dma_control;
917 sdc->slave.chancnt = NR_MAX_VCHANS; 915 sdc->slave.chancnt = NR_MAX_VCHANS;
916 sdc->slave.copy_align = 4;
918 917
919 sdc->slave.dev = &pdev->dev; 918 sdc->slave.dev = &pdev->dev;
920 919
diff --git a/drivers/gpio/devres.c b/drivers/gpio/devres.c
index 954b9f6b0ef8..13dbd3dfc33a 100644
--- a/drivers/gpio/devres.c
+++ b/drivers/gpio/devres.c
@@ -109,6 +109,38 @@ struct gpio_desc *__must_check __devm_gpiod_get_index(struct device *dev,
109EXPORT_SYMBOL(__devm_gpiod_get_index); 109EXPORT_SYMBOL(__devm_gpiod_get_index);
110 110
111/** 111/**
112 * devm_get_gpiod_from_child - get a GPIO descriptor from a device's child node
113 * @dev: GPIO consumer
114 * @child: firmware node (child of @dev)
115 *
116 * GPIO descriptors returned from this function are automatically disposed on
117 * driver detach.
118 */
119struct gpio_desc *devm_get_gpiod_from_child(struct device *dev,
120 struct fwnode_handle *child)
121{
122 struct gpio_desc **dr;
123 struct gpio_desc *desc;
124
125 dr = devres_alloc(devm_gpiod_release, sizeof(struct gpio_desc *),
126 GFP_KERNEL);
127 if (!dr)
128 return ERR_PTR(-ENOMEM);
129
130 desc = fwnode_get_named_gpiod(child, "gpios");
131 if (IS_ERR(desc)) {
132 devres_free(dr);
133 return desc;
134 }
135
136 *dr = desc;
137 devres_add(dev, dr);
138
139 return desc;
140}
141EXPORT_SYMBOL(devm_get_gpiod_from_child);
142
143/**
112 * devm_gpiod_get_index_optional - Resource-managed gpiod_get_index_optional() 144 * devm_gpiod_get_index_optional - Resource-managed gpiod_get_index_optional()
113 * @dev: GPIO consumer 145 * @dev: GPIO consumer
114 * @con_id: function within the GPIO consumer 146 * @con_id: function within the GPIO consumer
diff --git a/drivers/gpio/gpio-sch.c b/drivers/gpio/gpio-sch.c
index 41e91d70301e..99720c8bc8ed 100644
--- a/drivers/gpio/gpio-sch.c
+++ b/drivers/gpio/gpio-sch.c
@@ -29,290 +29,221 @@
29 29
30#include <linux/gpio.h> 30#include <linux/gpio.h>
31 31
32static DEFINE_SPINLOCK(gpio_lock); 32#define GEN 0x00
33 33#define GIO 0x04
34#define CGEN (0x00) 34#define GLV 0x08
35#define CGIO (0x04) 35
36#define CGLV (0x08) 36struct sch_gpio {
37 37 struct gpio_chip chip;
38#define RGEN (0x20) 38 spinlock_t lock;
39#define RGIO (0x24) 39 unsigned short iobase;
40#define RGLV (0x28) 40 unsigned short core_base;
41 41 unsigned short resume_base;
42static unsigned short gpio_ba; 42};
43
44static int sch_gpio_core_direction_in(struct gpio_chip *gc, unsigned gpio_num)
45{
46 u8 curr_dirs;
47 unsigned short offset, bit;
48
49 spin_lock(&gpio_lock);
50
51 offset = CGIO + gpio_num / 8;
52 bit = gpio_num % 8;
53
54 curr_dirs = inb(gpio_ba + offset);
55
56 if (!(curr_dirs & (1 << bit)))
57 outb(curr_dirs | (1 << bit), gpio_ba + offset);
58 43
59 spin_unlock(&gpio_lock); 44#define to_sch_gpio(c) container_of(c, struct sch_gpio, chip)
60 return 0;
61}
62 45
63static int sch_gpio_core_get(struct gpio_chip *gc, unsigned gpio_num) 46static unsigned sch_gpio_offset(struct sch_gpio *sch, unsigned gpio,
47 unsigned reg)
64{ 48{
65 int res; 49 unsigned base = 0;
66 unsigned short offset, bit;
67 50
68 offset = CGLV + gpio_num / 8; 51 if (gpio >= sch->resume_base) {
69 bit = gpio_num % 8; 52 gpio -= sch->resume_base;
53 base += 0x20;
54 }
70 55
71 res = !!(inb(gpio_ba + offset) & (1 << bit)); 56 return base + reg + gpio / 8;
72 return res;
73} 57}
74 58
75static void sch_gpio_core_set(struct gpio_chip *gc, unsigned gpio_num, int val) 59static unsigned sch_gpio_bit(struct sch_gpio *sch, unsigned gpio)
76{ 60{
77 u8 curr_vals; 61 if (gpio >= sch->resume_base)
78 unsigned short offset, bit; 62 gpio -= sch->resume_base;
79 63 return gpio % 8;
80 spin_lock(&gpio_lock);
81
82 offset = CGLV + gpio_num / 8;
83 bit = gpio_num % 8;
84
85 curr_vals = inb(gpio_ba + offset);
86
87 if (val)
88 outb(curr_vals | (1 << bit), gpio_ba + offset);
89 else
90 outb((curr_vals & ~(1 << bit)), gpio_ba + offset);
91 spin_unlock(&gpio_lock);
92} 64}
93 65
94static int sch_gpio_core_direction_out(struct gpio_chip *gc, 66static void sch_gpio_enable(struct sch_gpio *sch, unsigned gpio)
95 unsigned gpio_num, int val)
96{ 67{
97 u8 curr_dirs;
98 unsigned short offset, bit; 68 unsigned short offset, bit;
69 u8 enable;
99 70
100 spin_lock(&gpio_lock); 71 spin_lock(&sch->lock);
101 72
102 offset = CGIO + gpio_num / 8; 73 offset = sch_gpio_offset(sch, gpio, GEN);
103 bit = gpio_num % 8; 74 bit = sch_gpio_bit(sch, gpio);
104
105 curr_dirs = inb(gpio_ba + offset);
106 if (curr_dirs & (1 << bit))
107 outb(curr_dirs & ~(1 << bit), gpio_ba + offset);
108 75
109 spin_unlock(&gpio_lock); 76 enable = inb(sch->iobase + offset);
77 if (!(enable & (1 << bit)))
78 outb(enable | (1 << bit), sch->iobase + offset);
110 79
111 /* 80 spin_unlock(&sch->lock);
112 * according to the datasheet, writing to the level register has no
113 * effect when GPIO is programmed as input.
114 * Actually the the level register is read-only when configured as input.
115 * Thus presetting the output level before switching to output is _NOT_ possible.
116 * Hence we set the level after configuring the GPIO as output.
117 * But we cannot prevent a short low pulse if direction is set to high
118 * and an external pull-up is connected.
119 */
120 sch_gpio_core_set(gc, gpio_num, val);
121 return 0;
122} 81}
123 82
124static struct gpio_chip sch_gpio_core = { 83static int sch_gpio_direction_in(struct gpio_chip *gc, unsigned gpio_num)
125 .label = "sch_gpio_core",
126 .owner = THIS_MODULE,
127 .direction_input = sch_gpio_core_direction_in,
128 .get = sch_gpio_core_get,
129 .direction_output = sch_gpio_core_direction_out,
130 .set = sch_gpio_core_set,
131};
132
133static int sch_gpio_resume_direction_in(struct gpio_chip *gc,
134 unsigned gpio_num)
135{ 84{
85 struct sch_gpio *sch = to_sch_gpio(gc);
136 u8 curr_dirs; 86 u8 curr_dirs;
137 unsigned short offset, bit; 87 unsigned short offset, bit;
138 88
139 spin_lock(&gpio_lock); 89 spin_lock(&sch->lock);
140 90
141 offset = RGIO + gpio_num / 8; 91 offset = sch_gpio_offset(sch, gpio_num, GIO);
142 bit = gpio_num % 8; 92 bit = sch_gpio_bit(sch, gpio_num);
143 93
144 curr_dirs = inb(gpio_ba + offset); 94 curr_dirs = inb(sch->iobase + offset);
145 95
146 if (!(curr_dirs & (1 << bit))) 96 if (!(curr_dirs & (1 << bit)))
147 outb(curr_dirs | (1 << bit), gpio_ba + offset); 97 outb(curr_dirs | (1 << bit), sch->iobase + offset);
148 98
149 spin_unlock(&gpio_lock); 99 spin_unlock(&sch->lock);
150 return 0; 100 return 0;
151} 101}
152 102
153static int sch_gpio_resume_get(struct gpio_chip *gc, unsigned gpio_num) 103static int sch_gpio_get(struct gpio_chip *gc, unsigned gpio_num)
154{ 104{
105 struct sch_gpio *sch = to_sch_gpio(gc);
106 int res;
155 unsigned short offset, bit; 107 unsigned short offset, bit;
156 108
157 offset = RGLV + gpio_num / 8; 109 offset = sch_gpio_offset(sch, gpio_num, GLV);
158 bit = gpio_num % 8; 110 bit = sch_gpio_bit(sch, gpio_num);
111
112 res = !!(inb(sch->iobase + offset) & (1 << bit));
159 113
160 return !!(inb(gpio_ba + offset) & (1 << bit)); 114 return res;
161} 115}
162 116
163static void sch_gpio_resume_set(struct gpio_chip *gc, 117static void sch_gpio_set(struct gpio_chip *gc, unsigned gpio_num, int val)
164 unsigned gpio_num, int val)
165{ 118{
119 struct sch_gpio *sch = to_sch_gpio(gc);
166 u8 curr_vals; 120 u8 curr_vals;
167 unsigned short offset, bit; 121 unsigned short offset, bit;
168 122
169 spin_lock(&gpio_lock); 123 spin_lock(&sch->lock);
170 124
171 offset = RGLV + gpio_num / 8; 125 offset = sch_gpio_offset(sch, gpio_num, GLV);
172 bit = gpio_num % 8; 126 bit = sch_gpio_bit(sch, gpio_num);
173 127
174 curr_vals = inb(gpio_ba + offset); 128 curr_vals = inb(sch->iobase + offset);
175 129
176 if (val) 130 if (val)
177 outb(curr_vals | (1 << bit), gpio_ba + offset); 131 outb(curr_vals | (1 << bit), sch->iobase + offset);
178 else 132 else
179 outb((curr_vals & ~(1 << bit)), gpio_ba + offset); 133 outb((curr_vals & ~(1 << bit)), sch->iobase + offset);
180 134
181 spin_unlock(&gpio_lock); 135 spin_unlock(&sch->lock);
182} 136}
183 137
184static int sch_gpio_resume_direction_out(struct gpio_chip *gc, 138static int sch_gpio_direction_out(struct gpio_chip *gc, unsigned gpio_num,
185 unsigned gpio_num, int val) 139 int val)
186{ 140{
141 struct sch_gpio *sch = to_sch_gpio(gc);
187 u8 curr_dirs; 142 u8 curr_dirs;
188 unsigned short offset, bit; 143 unsigned short offset, bit;
189 144
190 offset = RGIO + gpio_num / 8; 145 spin_lock(&sch->lock);
191 bit = gpio_num % 8;
192 146
193 spin_lock(&gpio_lock); 147 offset = sch_gpio_offset(sch, gpio_num, GIO);
148 bit = sch_gpio_bit(sch, gpio_num);
194 149
195 curr_dirs = inb(gpio_ba + offset); 150 curr_dirs = inb(sch->iobase + offset);
196 if (curr_dirs & (1 << bit)) 151 if (curr_dirs & (1 << bit))
197 outb(curr_dirs & ~(1 << bit), gpio_ba + offset); 152 outb(curr_dirs & ~(1 << bit), sch->iobase + offset);
198 153
199 spin_unlock(&gpio_lock); 154 spin_unlock(&sch->lock);
200 155
201 /* 156 /*
202 * according to the datasheet, writing to the level register has no 157 * according to the datasheet, writing to the level register has no
203 * effect when GPIO is programmed as input. 158 * effect when GPIO is programmed as input.
204 * Actually the the level register is read-only when configured as input. 159 * Actually the the level register is read-only when configured as input.
205 * Thus presetting the output level before switching to output is _NOT_ possible. 160 * Thus presetting the output level before switching to output is _NOT_ possible.
206 * Hence we set the level after configuring the GPIO as output. 161 * Hence we set the level after configuring the GPIO as output.
207 * But we cannot prevent a short low pulse if direction is set to high 162 * But we cannot prevent a short low pulse if direction is set to high
208 * and an external pull-up is connected. 163 * and an external pull-up is connected.
209 */ 164 */
210 sch_gpio_resume_set(gc, gpio_num, val); 165 sch_gpio_set(gc, gpio_num, val);
211 return 0; 166 return 0;
212} 167}
213 168
214static struct gpio_chip sch_gpio_resume = { 169static struct gpio_chip sch_gpio_chip = {
215 .label = "sch_gpio_resume", 170 .label = "sch_gpio",
216 .owner = THIS_MODULE, 171 .owner = THIS_MODULE,
217 .direction_input = sch_gpio_resume_direction_in, 172 .direction_input = sch_gpio_direction_in,
218 .get = sch_gpio_resume_get, 173 .get = sch_gpio_get,
219 .direction_output = sch_gpio_resume_direction_out, 174 .direction_output = sch_gpio_direction_out,
220 .set = sch_gpio_resume_set, 175 .set = sch_gpio_set,
221}; 176};
222 177
223static int sch_gpio_probe(struct platform_device *pdev) 178static int sch_gpio_probe(struct platform_device *pdev)
224{ 179{
180 struct sch_gpio *sch;
225 struct resource *res; 181 struct resource *res;
226 int err, id;
227 182
228 id = pdev->id; 183 sch = devm_kzalloc(&pdev->dev, sizeof(*sch), GFP_KERNEL);
229 if (!id) 184 if (!sch)
230 return -ENODEV; 185 return -ENOMEM;
231 186
232 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 187 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
233 if (!res) 188 if (!res)
234 return -EBUSY; 189 return -EBUSY;
235 190
236 if (!request_region(res->start, resource_size(res), pdev->name)) 191 if (!devm_request_region(&pdev->dev, res->start, resource_size(res),
192 pdev->name))
237 return -EBUSY; 193 return -EBUSY;
238 194
239 gpio_ba = res->start; 195 spin_lock_init(&sch->lock);
196 sch->iobase = res->start;
197 sch->chip = sch_gpio_chip;
198 sch->chip.label = dev_name(&pdev->dev);
199 sch->chip.dev = &pdev->dev;
240 200
241 switch (id) { 201 switch (pdev->id) {
242 case PCI_DEVICE_ID_INTEL_SCH_LPC: 202 case PCI_DEVICE_ID_INTEL_SCH_LPC:
243 sch_gpio_core.base = 0; 203 sch->core_base = 0;
244 sch_gpio_core.ngpio = 10; 204 sch->resume_base = 10;
245 sch_gpio_resume.base = 10; 205 sch->chip.ngpio = 14;
246 sch_gpio_resume.ngpio = 4; 206
247 /* 207 /*
248 * GPIO[6:0] enabled by default 208 * GPIO[6:0] enabled by default
249 * GPIO7 is configured by the CMC as SLPIOVR 209 * GPIO7 is configured by the CMC as SLPIOVR
250 * Enable GPIO[9:8] core powered gpios explicitly 210 * Enable GPIO[9:8] core powered gpios explicitly
251 */ 211 */
252 outb(0x3, gpio_ba + CGEN + 1); 212 sch_gpio_enable(sch, 8);
213 sch_gpio_enable(sch, 9);
253 /* 214 /*
254 * SUS_GPIO[2:0] enabled by default 215 * SUS_GPIO[2:0] enabled by default
255 * Enable SUS_GPIO3 resume powered gpio explicitly 216 * Enable SUS_GPIO3 resume powered gpio explicitly
256 */ 217 */
257 outb(0x8, gpio_ba + RGEN); 218 sch_gpio_enable(sch, 13);
258 break; 219 break;
259 220
260 case PCI_DEVICE_ID_INTEL_ITC_LPC: 221 case PCI_DEVICE_ID_INTEL_ITC_LPC:
261 sch_gpio_core.base = 0; 222 sch->core_base = 0;
262 sch_gpio_core.ngpio = 5; 223 sch->resume_base = 5;
263 sch_gpio_resume.base = 5; 224 sch->chip.ngpio = 14;
264 sch_gpio_resume.ngpio = 9;
265 break; 225 break;
266 226
267 case PCI_DEVICE_ID_INTEL_CENTERTON_ILB: 227 case PCI_DEVICE_ID_INTEL_CENTERTON_ILB:
268 sch_gpio_core.base = 0; 228 sch->core_base = 0;
269 sch_gpio_core.ngpio = 21; 229 sch->resume_base = 21;
270 sch_gpio_resume.base = 21; 230 sch->chip.ngpio = 30;
271 sch_gpio_resume.ngpio = 9;
272 break; 231 break;
273 232
274 default: 233 default:
275 err = -ENODEV; 234 return -ENODEV;
276 goto err_sch_gpio_core;
277 } 235 }
278 236
279 sch_gpio_core.dev = &pdev->dev; 237 platform_set_drvdata(pdev, sch);
280 sch_gpio_resume.dev = &pdev->dev;
281
282 err = gpiochip_add(&sch_gpio_core);
283 if (err < 0)
284 goto err_sch_gpio_core;
285 238
286 err = gpiochip_add(&sch_gpio_resume); 239 return gpiochip_add(&sch->chip);
287 if (err < 0)
288 goto err_sch_gpio_resume;
289
290 return 0;
291
292err_sch_gpio_resume:
293 gpiochip_remove(&sch_gpio_core);
294
295err_sch_gpio_core:
296 release_region(res->start, resource_size(res));
297 gpio_ba = 0;
298
299 return err;
300} 240}
301 241
302static int sch_gpio_remove(struct platform_device *pdev) 242static int sch_gpio_remove(struct platform_device *pdev)
303{ 243{
304 struct resource *res; 244 struct sch_gpio *sch = platform_get_drvdata(pdev);
305 if (gpio_ba) {
306
307 gpiochip_remove(&sch_gpio_core);
308 gpiochip_remove(&sch_gpio_resume);
309
310 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
311
312 release_region(res->start, resource_size(res));
313 gpio_ba = 0;
314 }
315 245
246 gpiochip_remove(&sch->chip);
316 return 0; 247 return 0;
317} 248}
318 249
diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index 05c6275da224..ba98bb59a58f 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -287,9 +287,45 @@ void acpi_gpiochip_free_interrupts(struct gpio_chip *chip)
287 } 287 }
288} 288}
289 289
290int acpi_dev_add_driver_gpios(struct acpi_device *adev,
291 const struct acpi_gpio_mapping *gpios)
292{
293 if (adev && gpios) {
294 adev->driver_gpios = gpios;
295 return 0;
296 }
297 return -EINVAL;
298}
299EXPORT_SYMBOL_GPL(acpi_dev_add_driver_gpios);
300
301static bool acpi_get_driver_gpio_data(struct acpi_device *adev,
302 const char *name, int index,
303 struct acpi_reference_args *args)
304{
305 const struct acpi_gpio_mapping *gm;
306
307 if (!adev->driver_gpios)
308 return false;
309
310 for (gm = adev->driver_gpios; gm->name; gm++)
311 if (!strcmp(name, gm->name) && gm->data && index < gm->size) {
312 const struct acpi_gpio_params *par = gm->data + index;
313
314 args->adev = adev;
315 args->args[0] = par->crs_entry_index;
316 args->args[1] = par->line_index;
317 args->args[2] = par->active_low;
318 args->nargs = 3;
319 return true;
320 }
321
322 return false;
323}
324
290struct acpi_gpio_lookup { 325struct acpi_gpio_lookup {
291 struct acpi_gpio_info info; 326 struct acpi_gpio_info info;
292 int index; 327 int index;
328 int pin_index;
293 struct gpio_desc *desc; 329 struct gpio_desc *desc;
294 int n; 330 int n;
295}; 331};
@@ -303,13 +339,24 @@ static int acpi_find_gpio(struct acpi_resource *ares, void *data)
303 339
304 if (lookup->n++ == lookup->index && !lookup->desc) { 340 if (lookup->n++ == lookup->index && !lookup->desc) {
305 const struct acpi_resource_gpio *agpio = &ares->data.gpio; 341 const struct acpi_resource_gpio *agpio = &ares->data.gpio;
342 int pin_index = lookup->pin_index;
343
344 if (pin_index >= agpio->pin_table_length)
345 return 1;
306 346
307 lookup->desc = acpi_get_gpiod(agpio->resource_source.string_ptr, 347 lookup->desc = acpi_get_gpiod(agpio->resource_source.string_ptr,
308 agpio->pin_table[0]); 348 agpio->pin_table[pin_index]);
309 lookup->info.gpioint = 349 lookup->info.gpioint =
310 agpio->connection_type == ACPI_RESOURCE_GPIO_TYPE_INT; 350 agpio->connection_type == ACPI_RESOURCE_GPIO_TYPE_INT;
311 lookup->info.active_low = 351
312 agpio->polarity == ACPI_ACTIVE_LOW; 352 /*
353 * ActiveLow is only specified for GpioInt resource. If
354 * GpioIo is used then the only way to set the flag is
355 * to use _DSD "gpios" property.
356 */
357 if (lookup->info.gpioint)
358 lookup->info.active_low =
359 agpio->polarity == ACPI_ACTIVE_LOW;
313 } 360 }
314 361
315 return 1; 362 return 1;
@@ -317,40 +364,79 @@ static int acpi_find_gpio(struct acpi_resource *ares, void *data)
317 364
318/** 365/**
319 * acpi_get_gpiod_by_index() - get a GPIO descriptor from device resources 366 * acpi_get_gpiod_by_index() - get a GPIO descriptor from device resources
320 * @dev: pointer to a device to get GPIO from 367 * @adev: pointer to a ACPI device to get GPIO from
368 * @propname: Property name of the GPIO (optional)
321 * @index: index of GpioIo/GpioInt resource (starting from %0) 369 * @index: index of GpioIo/GpioInt resource (starting from %0)
322 * @info: info pointer to fill in (optional) 370 * @info: info pointer to fill in (optional)
323 * 371 *
324 * Function goes through ACPI resources for @dev and based on @index looks 372 * Function goes through ACPI resources for @adev and based on @index looks
325 * up a GpioIo/GpioInt resource, translates it to the Linux GPIO descriptor, 373 * up a GpioIo/GpioInt resource, translates it to the Linux GPIO descriptor,
326 * and returns it. @index matches GpioIo/GpioInt resources only so if there 374 * and returns it. @index matches GpioIo/GpioInt resources only so if there
327 * are total %3 GPIO resources, the index goes from %0 to %2. 375 * are total %3 GPIO resources, the index goes from %0 to %2.
328 * 376 *
377 * If @propname is specified the GPIO is looked using device property. In
378 * that case @index is used to select the GPIO entry in the property value
379 * (in case of multiple).
380 *
329 * If the GPIO cannot be translated or there is an error an ERR_PTR is 381 * If the GPIO cannot be translated or there is an error an ERR_PTR is
330 * returned. 382 * returned.
331 * 383 *
332 * Note: if the GPIO resource has multiple entries in the pin list, this 384 * Note: if the GPIO resource has multiple entries in the pin list, this
333 * function only returns the first. 385 * function only returns the first.
334 */ 386 */
335struct gpio_desc *acpi_get_gpiod_by_index(struct device *dev, int index, 387struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev,
388 const char *propname, int index,
336 struct acpi_gpio_info *info) 389 struct acpi_gpio_info *info)
337{ 390{
338 struct acpi_gpio_lookup lookup; 391 struct acpi_gpio_lookup lookup;
339 struct list_head resource_list; 392 struct list_head resource_list;
340 struct acpi_device *adev; 393 bool active_low = false;
341 acpi_handle handle;
342 int ret; 394 int ret;
343 395
344 if (!dev) 396 if (!adev)
345 return ERR_PTR(-EINVAL);
346
347 handle = ACPI_HANDLE(dev);
348 if (!handle || acpi_bus_get_device(handle, &adev))
349 return ERR_PTR(-ENODEV); 397 return ERR_PTR(-ENODEV);
350 398
351 memset(&lookup, 0, sizeof(lookup)); 399 memset(&lookup, 0, sizeof(lookup));
352 lookup.index = index; 400 lookup.index = index;
353 401
402 if (propname) {
403 struct acpi_reference_args args;
404
405 dev_dbg(&adev->dev, "GPIO: looking up %s\n", propname);
406
407 memset(&args, 0, sizeof(args));
408 ret = acpi_dev_get_property_reference(adev, propname,
409 index, &args);
410 if (ret) {
411 bool found = acpi_get_driver_gpio_data(adev, propname,
412 index, &args);
413 if (!found)
414 return ERR_PTR(ret);
415 }
416
417 /*
418 * The property was found and resolved so need to
419 * lookup the GPIO based on returned args instead.
420 */
421 adev = args.adev;
422 if (args.nargs >= 2) {
423 lookup.index = args.args[0];
424 lookup.pin_index = args.args[1];
425 /*
426 * 3rd argument, if present is used to
427 * specify active_low.
428 */
429 if (args.nargs >= 3)
430 active_low = !!args.args[2];
431 }
432
433 dev_dbg(&adev->dev, "GPIO: _DSD returned %s %zd %llu %llu %llu\n",
434 dev_name(&adev->dev), args.nargs,
435 args.args[0], args.args[1], args.args[2]);
436 } else {
437 dev_dbg(&adev->dev, "GPIO: looking up %d in _CRS\n", index);
438 }
439
354 INIT_LIST_HEAD(&resource_list); 440 INIT_LIST_HEAD(&resource_list);
355 ret = acpi_dev_get_resources(adev, &resource_list, acpi_find_gpio, 441 ret = acpi_dev_get_resources(adev, &resource_list, acpi_find_gpio,
356 &lookup); 442 &lookup);
@@ -359,8 +445,11 @@ struct gpio_desc *acpi_get_gpiod_by_index(struct device *dev, int index,
359 445
360 acpi_dev_free_resource_list(&resource_list); 446 acpi_dev_free_resource_list(&resource_list);
361 447
362 if (lookup.desc && info) 448 if (lookup.desc && info) {
363 *info = lookup.info; 449 *info = lookup.info;
450 if (active_low)
451 info->active_low = active_low;
452 }
364 453
365 return lookup.desc ? lookup.desc : ERR_PTR(-ENOENT); 454 return lookup.desc ? lookup.desc : ERR_PTR(-ENOENT);
366} 455}
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index e8e98ca25ec7..58659dbe702a 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1505,14 +1505,36 @@ static struct gpio_desc *acpi_find_gpio(struct device *dev, const char *con_id,
1505 unsigned int idx, 1505 unsigned int idx,
1506 enum gpio_lookup_flags *flags) 1506 enum gpio_lookup_flags *flags)
1507{ 1507{
1508 static const char * const suffixes[] = { "gpios", "gpio" };
1509 struct acpi_device *adev = ACPI_COMPANION(dev);
1508 struct acpi_gpio_info info; 1510 struct acpi_gpio_info info;
1509 struct gpio_desc *desc; 1511 struct gpio_desc *desc;
1512 char propname[32];
1513 int i;
1510 1514
1511 desc = acpi_get_gpiod_by_index(dev, idx, &info); 1515 /* Try first from _DSD */
1512 if (IS_ERR(desc)) 1516 for (i = 0; i < ARRAY_SIZE(suffixes); i++) {
1513 return desc; 1517 if (con_id && strcmp(con_id, "gpios")) {
1518 snprintf(propname, sizeof(propname), "%s-%s",
1519 con_id, suffixes[i]);
1520 } else {
1521 snprintf(propname, sizeof(propname), "%s",
1522 suffixes[i]);
1523 }
1524
1525 desc = acpi_get_gpiod_by_index(adev, propname, idx, &info);
1526 if (!IS_ERR(desc) || (PTR_ERR(desc) == -EPROBE_DEFER))
1527 break;
1528 }
1514 1529
1515 if (info.gpioint && info.active_low) 1530 /* Then from plain _CRS GPIOs */
1531 if (IS_ERR(desc)) {
1532 desc = acpi_get_gpiod_by_index(adev, NULL, idx, &info);
1533 if (IS_ERR(desc))
1534 return desc;
1535 }
1536
1537 if (info.active_low)
1516 *flags |= GPIO_ACTIVE_LOW; 1538 *flags |= GPIO_ACTIVE_LOW;
1517 1539
1518 return desc; 1540 return desc;
@@ -1713,6 +1735,61 @@ struct gpio_desc *__must_check __gpiod_get_index(struct device *dev,
1713EXPORT_SYMBOL_GPL(__gpiod_get_index); 1735EXPORT_SYMBOL_GPL(__gpiod_get_index);
1714 1736
1715/** 1737/**
1738 * fwnode_get_named_gpiod - obtain a GPIO from firmware node
1739 * @fwnode: handle of the firmware node
1740 * @propname: name of the firmware property representing the GPIO
1741 *
1742 * This function can be used for drivers that get their configuration
1743 * from firmware.
1744 *
1745 * Function properly finds the corresponding GPIO using whatever is the
1746 * underlying firmware interface and then makes sure that the GPIO
1747 * descriptor is requested before it is returned to the caller.
1748 *
1749 * In case of error an ERR_PTR() is returned.
1750 */
1751struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
1752 const char *propname)
1753{
1754 struct gpio_desc *desc = ERR_PTR(-ENODEV);
1755 bool active_low = false;
1756 int ret;
1757
1758 if (!fwnode)
1759 return ERR_PTR(-EINVAL);
1760
1761 if (is_of_node(fwnode)) {
1762 enum of_gpio_flags flags;
1763
1764 desc = of_get_named_gpiod_flags(of_node(fwnode), propname, 0,
1765 &flags);
1766 if (!IS_ERR(desc))
1767 active_low = flags & OF_GPIO_ACTIVE_LOW;
1768 } else if (is_acpi_node(fwnode)) {
1769 struct acpi_gpio_info info;
1770
1771 desc = acpi_get_gpiod_by_index(acpi_node(fwnode), propname, 0,
1772 &info);
1773 if (!IS_ERR(desc))
1774 active_low = info.active_low;
1775 }
1776
1777 if (IS_ERR(desc))
1778 return desc;
1779
1780 ret = gpiod_request(desc, NULL);
1781 if (ret)
1782 return ERR_PTR(ret);
1783
1784 /* Only value flag can be set from both DT and ACPI is active_low */
1785 if (active_low)
1786 set_bit(FLAG_ACTIVE_LOW, &desc->flags);
1787
1788 return desc;
1789}
1790EXPORT_SYMBOL_GPL(fwnode_get_named_gpiod);
1791
1792/**
1716 * gpiod_get_index_optional - obtain an optional GPIO from a multi-index GPIO 1793 * gpiod_get_index_optional - obtain an optional GPIO from a multi-index GPIO
1717 * function 1794 * function
1718 * @dev: GPIO consumer, can be NULL for system-global GPIOs 1795 * @dev: GPIO consumer, can be NULL for system-global GPIOs
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index 9db2b6a71c5d..e3a52113a541 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -34,7 +34,8 @@ void acpi_gpiochip_remove(struct gpio_chip *chip);
34void acpi_gpiochip_request_interrupts(struct gpio_chip *chip); 34void acpi_gpiochip_request_interrupts(struct gpio_chip *chip);
35void acpi_gpiochip_free_interrupts(struct gpio_chip *chip); 35void acpi_gpiochip_free_interrupts(struct gpio_chip *chip);
36 36
37struct gpio_desc *acpi_get_gpiod_by_index(struct device *dev, int index, 37struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev,
38 const char *propname, int index,
38 struct acpi_gpio_info *info); 39 struct acpi_gpio_info *info);
39#else 40#else
40static inline void acpi_gpiochip_add(struct gpio_chip *chip) { } 41static inline void acpi_gpiochip_add(struct gpio_chip *chip) { }
@@ -47,8 +48,8 @@ static inline void
47acpi_gpiochip_free_interrupts(struct gpio_chip *chip) { } 48acpi_gpiochip_free_interrupts(struct gpio_chip *chip) { }
48 49
49static inline struct gpio_desc * 50static inline struct gpio_desc *
50acpi_get_gpiod_by_index(struct device *dev, int index, 51acpi_get_gpiod_by_index(struct acpi_device *adev, const char *propname,
51 struct acpi_gpio_info *info) 52 int index, struct acpi_gpio_info *info)
52{ 53{
53 return ERR_PTR(-ENOSYS); 54 return ERR_PTR(-ENOSYS);
54} 55}
diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
index 1403b01e8216..318ade9bb5af 100644
--- a/drivers/gpu/drm/i915/i915_dma.c
+++ b/drivers/gpu/drm/i915/i915_dma.c
@@ -1670,15 +1670,17 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
1670 goto out_regs; 1670 goto out_regs;
1671 1671
1672 if (drm_core_check_feature(dev, DRIVER_MODESET)) { 1672 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
1673 ret = i915_kick_out_vgacon(dev_priv); 1673 /* WARNING: Apparently we must kick fbdev drivers before vgacon,
1674 * otherwise the vga fbdev driver falls over. */
1675 ret = i915_kick_out_firmware_fb(dev_priv);
1674 if (ret) { 1676 if (ret) {
1675 DRM_ERROR("failed to remove conflicting VGA console\n"); 1677 DRM_ERROR("failed to remove conflicting framebuffer drivers\n");
1676 goto out_gtt; 1678 goto out_gtt;
1677 } 1679 }
1678 1680
1679 ret = i915_kick_out_firmware_fb(dev_priv); 1681 ret = i915_kick_out_vgacon(dev_priv);
1680 if (ret) { 1682 if (ret) {
1681 DRM_ERROR("failed to remove conflicting framebuffer drivers\n"); 1683 DRM_ERROR("failed to remove conflicting VGA console\n");
1682 goto out_gtt; 1684 goto out_gtt;
1683 } 1685 }
1684 } 1686 }
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index f0a1a56406eb..9cb5c95d5898 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -4325,7 +4325,6 @@ static void ironlake_crtc_disable(struct drm_crtc *crtc)
4325 ironlake_fdi_disable(crtc); 4325 ironlake_fdi_disable(crtc);
4326 4326
4327 ironlake_disable_pch_transcoder(dev_priv, pipe); 4327 ironlake_disable_pch_transcoder(dev_priv, pipe);
4328 intel_set_pch_fifo_underrun_reporting(dev, pipe, true);
4329 4328
4330 if (HAS_PCH_CPT(dev)) { 4329 if (HAS_PCH_CPT(dev)) {
4331 /* disable TRANS_DP_CTL */ 4330 /* disable TRANS_DP_CTL */
@@ -4389,7 +4388,6 @@ static void haswell_crtc_disable(struct drm_crtc *crtc)
4389 4388
4390 if (intel_crtc->config.has_pch_encoder) { 4389 if (intel_crtc->config.has_pch_encoder) {
4391 lpt_disable_pch_transcoder(dev_priv); 4390 lpt_disable_pch_transcoder(dev_priv);
4392 intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, true);
4393 intel_ddi_fdi_disable(crtc); 4391 intel_ddi_fdi_disable(crtc);
4394 } 4392 }
4395 4393
@@ -9408,6 +9406,10 @@ static bool page_flip_finished(struct intel_crtc *crtc)
9408 struct drm_device *dev = crtc->base.dev; 9406 struct drm_device *dev = crtc->base.dev;
9409 struct drm_i915_private *dev_priv = dev->dev_private; 9407 struct drm_i915_private *dev_priv = dev->dev_private;
9410 9408
9409 if (i915_reset_in_progress(&dev_priv->gpu_error) ||
9410 crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter))
9411 return true;
9412
9411 /* 9413 /*
9412 * The relevant registers doen't exist on pre-ctg. 9414 * The relevant registers doen't exist on pre-ctg.
9413 * As the flip done interrupt doesn't trigger for mmio 9415 * As the flip done interrupt doesn't trigger for mmio
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index 5ad45bfff3fe..4bcd91757321 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -4450,6 +4450,7 @@ static void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
4450 * vdd might still be enabled do to the delayed vdd off. 4450 * vdd might still be enabled do to the delayed vdd off.
4451 * Make sure vdd is actually turned off here. 4451 * Make sure vdd is actually turned off here.
4452 */ 4452 */
4453 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
4453 pps_lock(intel_dp); 4454 pps_lock(intel_dp);
4454 edp_panel_vdd_off_sync(intel_dp); 4455 edp_panel_vdd_off_sync(intel_dp);
4455 pps_unlock(intel_dp); 4456 pps_unlock(intel_dp);
diff --git a/drivers/gpu/drm/i915/intel_lvds.c b/drivers/gpu/drm/i915/intel_lvds.c
index a6bd1422e38f..c0bbf2172446 100644
--- a/drivers/gpu/drm/i915/intel_lvds.c
+++ b/drivers/gpu/drm/i915/intel_lvds.c
@@ -899,6 +899,17 @@ void intel_lvds_init(struct drm_device *dev)
899 int pipe; 899 int pipe;
900 u8 pin; 900 u8 pin;
901 901
902 /*
903 * Unlock registers and just leave them unlocked. Do this before
904 * checking quirk lists to avoid bogus WARNINGs.
905 */
906 if (HAS_PCH_SPLIT(dev)) {
907 I915_WRITE(PCH_PP_CONTROL,
908 I915_READ(PCH_PP_CONTROL) | PANEL_UNLOCK_REGS);
909 } else {
910 I915_WRITE(PP_CONTROL,
911 I915_READ(PP_CONTROL) | PANEL_UNLOCK_REGS);
912 }
902 if (!intel_lvds_supported(dev)) 913 if (!intel_lvds_supported(dev))
903 return; 914 return;
904 915
@@ -1097,17 +1108,6 @@ out:
1097 lvds_encoder->a3_power = I915_READ(lvds_encoder->reg) & 1108 lvds_encoder->a3_power = I915_READ(lvds_encoder->reg) &
1098 LVDS_A3_POWER_MASK; 1109 LVDS_A3_POWER_MASK;
1099 1110
1100 /*
1101 * Unlock registers and just
1102 * leave them unlocked
1103 */
1104 if (HAS_PCH_SPLIT(dev)) {
1105 I915_WRITE(PCH_PP_CONTROL,
1106 I915_READ(PCH_PP_CONTROL) | PANEL_UNLOCK_REGS);
1107 } else {
1108 I915_WRITE(PP_CONTROL,
1109 I915_READ(PP_CONTROL) | PANEL_UNLOCK_REGS);
1110 }
1111 lvds_connector->lid_notifier.notifier_call = intel_lid_notify; 1111 lvds_connector->lid_notifier.notifier_call = intel_lid_notify;
1112 if (acpi_lid_notifier_register(&lvds_connector->lid_notifier)) { 1112 if (acpi_lid_notifier_register(&lvds_connector->lid_notifier)) {
1113 DRM_DEBUG_KMS("lid notifier registration failed\n"); 1113 DRM_DEBUG_KMS("lid notifier registration failed\n");
diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
index c27b6140bfd1..ad2fd605f76b 100644
--- a/drivers/gpu/drm/i915/intel_pm.c
+++ b/drivers/gpu/drm/i915/intel_pm.c
@@ -5469,11 +5469,6 @@ static void gen6_init_clock_gating(struct drm_device *dev)
5469 I915_WRITE(_3D_CHICKEN, 5469 I915_WRITE(_3D_CHICKEN,
5470 _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB)); 5470 _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB));
5471 5471
5472 /* WaSetupGtModeTdRowDispatch:snb */
5473 if (IS_SNB_GT1(dev))
5474 I915_WRITE(GEN6_GT_MODE,
5475 _MASKED_BIT_ENABLE(GEN6_TD_FOUR_ROW_DISPATCH_DISABLE));
5476
5477 /* WaDisable_RenderCache_OperationalFlush:snb */ 5472 /* WaDisable_RenderCache_OperationalFlush:snb */
5478 I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); 5473 I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE));
5479 5474
diff --git a/drivers/gpu/drm/nouveau/core/engine/device/nvc0.c b/drivers/gpu/drm/nouveau/core/engine/device/nvc0.c
index cd05677ad4b7..72a40f95d048 100644
--- a/drivers/gpu/drm/nouveau/core/engine/device/nvc0.c
+++ b/drivers/gpu/drm/nouveau/core/engine/device/nvc0.c
@@ -218,7 +218,6 @@ nvc0_identify(struct nouveau_device *device)
218 device->oclass[NVDEV_ENGINE_BSP ] = &nvc0_bsp_oclass; 218 device->oclass[NVDEV_ENGINE_BSP ] = &nvc0_bsp_oclass;
219 device->oclass[NVDEV_ENGINE_PPP ] = &nvc0_ppp_oclass; 219 device->oclass[NVDEV_ENGINE_PPP ] = &nvc0_ppp_oclass;
220 device->oclass[NVDEV_ENGINE_COPY0 ] = &nvc0_copy0_oclass; 220 device->oclass[NVDEV_ENGINE_COPY0 ] = &nvc0_copy0_oclass;
221 device->oclass[NVDEV_ENGINE_COPY1 ] = &nvc0_copy1_oclass;
222 device->oclass[NVDEV_ENGINE_DISP ] = nva3_disp_oclass; 221 device->oclass[NVDEV_ENGINE_DISP ] = nva3_disp_oclass;
223 device->oclass[NVDEV_ENGINE_PERFMON] = &nvc0_perfmon_oclass; 222 device->oclass[NVDEV_ENGINE_PERFMON] = &nvc0_perfmon_oclass;
224 break; 223 break;
diff --git a/drivers/gpu/drm/nouveau/core/engine/fifo/nv04.c b/drivers/gpu/drm/nouveau/core/engine/fifo/nv04.c
index 5ae6a43893b5..1931057f9962 100644
--- a/drivers/gpu/drm/nouveau/core/engine/fifo/nv04.c
+++ b/drivers/gpu/drm/nouveau/core/engine/fifo/nv04.c
@@ -551,8 +551,8 @@ nv04_fifo_intr(struct nouveau_subdev *subdev)
551 } 551 }
552 552
553 if (status & 0x40000000) { 553 if (status & 0x40000000) {
554 nouveau_fifo_uevent(&priv->base);
555 nv_wr32(priv, 0x002100, 0x40000000); 554 nv_wr32(priv, 0x002100, 0x40000000);
555 nouveau_fifo_uevent(&priv->base);
556 status &= ~0x40000000; 556 status &= ~0x40000000;
557 } 557 }
558 } 558 }
diff --git a/drivers/gpu/drm/nouveau/core/engine/fifo/nvc0.c b/drivers/gpu/drm/nouveau/core/engine/fifo/nvc0.c
index 1fe1f8fbda0c..074d434c3077 100644
--- a/drivers/gpu/drm/nouveau/core/engine/fifo/nvc0.c
+++ b/drivers/gpu/drm/nouveau/core/engine/fifo/nvc0.c
@@ -740,6 +740,8 @@ nvc0_fifo_intr_engine_unit(struct nvc0_fifo_priv *priv, int engn)
740 u32 inte = nv_rd32(priv, 0x002628); 740 u32 inte = nv_rd32(priv, 0x002628);
741 u32 unkn; 741 u32 unkn;
742 742
743 nv_wr32(priv, 0x0025a8 + (engn * 0x04), intr);
744
743 for (unkn = 0; unkn < 8; unkn++) { 745 for (unkn = 0; unkn < 8; unkn++) {
744 u32 ints = (intr >> (unkn * 0x04)) & inte; 746 u32 ints = (intr >> (unkn * 0x04)) & inte;
745 if (ints & 0x1) { 747 if (ints & 0x1) {
@@ -751,8 +753,6 @@ nvc0_fifo_intr_engine_unit(struct nvc0_fifo_priv *priv, int engn)
751 nv_mask(priv, 0x002628, ints, 0); 753 nv_mask(priv, 0x002628, ints, 0);
752 } 754 }
753 } 755 }
754
755 nv_wr32(priv, 0x0025a8 + (engn * 0x04), intr);
756} 756}
757 757
758static void 758static void
diff --git a/drivers/gpu/drm/nouveau/core/engine/fifo/nve0.c b/drivers/gpu/drm/nouveau/core/engine/fifo/nve0.c
index d2f0fd39c145..f8734eb74eaa 100644
--- a/drivers/gpu/drm/nouveau/core/engine/fifo/nve0.c
+++ b/drivers/gpu/drm/nouveau/core/engine/fifo/nve0.c
@@ -952,8 +952,8 @@ nve0_fifo_intr(struct nouveau_subdev *subdev)
952 } 952 }
953 953
954 if (stat & 0x80000000) { 954 if (stat & 0x80000000) {
955 nve0_fifo_intr_engine(priv);
956 nv_wr32(priv, 0x002100, 0x80000000); 955 nv_wr32(priv, 0x002100, 0x80000000);
956 nve0_fifo_intr_engine(priv);
957 stat &= ~0x80000000; 957 stat &= ~0x80000000;
958 } 958 }
959 959
diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c b/drivers/gpu/drm/nouveau/nouveau_drm.c
index 57238076049f..62b97c4eef8d 100644
--- a/drivers/gpu/drm/nouveau/nouveau_drm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_drm.c
@@ -629,7 +629,6 @@ int nouveau_pmops_suspend(struct device *dev)
629 629
630 pci_save_state(pdev); 630 pci_save_state(pdev);
631 pci_disable_device(pdev); 631 pci_disable_device(pdev);
632 pci_ignore_hotplug(pdev);
633 pci_set_power_state(pdev, PCI_D3hot); 632 pci_set_power_state(pdev, PCI_D3hot);
634 return 0; 633 return 0;
635} 634}
@@ -933,6 +932,7 @@ static int nouveau_pmops_runtime_suspend(struct device *dev)
933 ret = nouveau_do_suspend(drm_dev, true); 932 ret = nouveau_do_suspend(drm_dev, true);
934 pci_save_state(pdev); 933 pci_save_state(pdev);
935 pci_disable_device(pdev); 934 pci_disable_device(pdev);
935 pci_ignore_hotplug(pdev);
936 pci_set_power_state(pdev, PCI_D3cold); 936 pci_set_power_state(pdev, PCI_D3cold);
937 drm_dev->switch_power_state = DRM_SWITCH_POWER_DYNAMIC_OFF; 937 drm_dev->switch_power_state = DRM_SWITCH_POWER_DYNAMIC_OFF;
938 return ret; 938 return ret;
diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
index 515cd9aebb99..f32a434724e3 100644
--- a/drivers/gpu/drm/nouveau/nouveau_fence.c
+++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
@@ -52,20 +52,24 @@ nouveau_fctx(struct nouveau_fence *fence)
52 return container_of(fence->base.lock, struct nouveau_fence_chan, lock); 52 return container_of(fence->base.lock, struct nouveau_fence_chan, lock);
53} 53}
54 54
55static void 55static int
56nouveau_fence_signal(struct nouveau_fence *fence) 56nouveau_fence_signal(struct nouveau_fence *fence)
57{ 57{
58 int drop = 0;
59
58 fence_signal_locked(&fence->base); 60 fence_signal_locked(&fence->base);
59 list_del(&fence->head); 61 list_del(&fence->head);
62 rcu_assign_pointer(fence->channel, NULL);
60 63
61 if (test_bit(FENCE_FLAG_USER_BITS, &fence->base.flags)) { 64 if (test_bit(FENCE_FLAG_USER_BITS, &fence->base.flags)) {
62 struct nouveau_fence_chan *fctx = nouveau_fctx(fence); 65 struct nouveau_fence_chan *fctx = nouveau_fctx(fence);
63 66
64 if (!--fctx->notify_ref) 67 if (!--fctx->notify_ref)
65 nvif_notify_put(&fctx->notify); 68 drop = 1;
66 } 69 }
67 70
68 fence_put(&fence->base); 71 fence_put(&fence->base);
72 return drop;
69} 73}
70 74
71static struct nouveau_fence * 75static struct nouveau_fence *
@@ -88,16 +92,23 @@ nouveau_fence_context_del(struct nouveau_fence_chan *fctx)
88{ 92{
89 struct nouveau_fence *fence; 93 struct nouveau_fence *fence;
90 94
91 nvif_notify_fini(&fctx->notify);
92
93 spin_lock_irq(&fctx->lock); 95 spin_lock_irq(&fctx->lock);
94 while (!list_empty(&fctx->pending)) { 96 while (!list_empty(&fctx->pending)) {
95 fence = list_entry(fctx->pending.next, typeof(*fence), head); 97 fence = list_entry(fctx->pending.next, typeof(*fence), head);
96 98
97 nouveau_fence_signal(fence); 99 if (nouveau_fence_signal(fence))
98 fence->channel = NULL; 100 nvif_notify_put(&fctx->notify);
99 } 101 }
100 spin_unlock_irq(&fctx->lock); 102 spin_unlock_irq(&fctx->lock);
103
104 nvif_notify_fini(&fctx->notify);
105 fctx->dead = 1;
106
107 /*
108 * Ensure that all accesses to fence->channel complete before freeing
109 * the channel.
110 */
111 synchronize_rcu();
101} 112}
102 113
103static void 114static void
@@ -112,21 +123,23 @@ nouveau_fence_context_free(struct nouveau_fence_chan *fctx)
112 kref_put(&fctx->fence_ref, nouveau_fence_context_put); 123 kref_put(&fctx->fence_ref, nouveau_fence_context_put);
113} 124}
114 125
115static void 126static int
116nouveau_fence_update(struct nouveau_channel *chan, struct nouveau_fence_chan *fctx) 127nouveau_fence_update(struct nouveau_channel *chan, struct nouveau_fence_chan *fctx)
117{ 128{
118 struct nouveau_fence *fence; 129 struct nouveau_fence *fence;
119 130 int drop = 0;
120 u32 seq = fctx->read(chan); 131 u32 seq = fctx->read(chan);
121 132
122 while (!list_empty(&fctx->pending)) { 133 while (!list_empty(&fctx->pending)) {
123 fence = list_entry(fctx->pending.next, typeof(*fence), head); 134 fence = list_entry(fctx->pending.next, typeof(*fence), head);
124 135
125 if ((int)(seq - fence->base.seqno) < 0) 136 if ((int)(seq - fence->base.seqno) < 0)
126 return; 137 break;
127 138
128 nouveau_fence_signal(fence); 139 drop |= nouveau_fence_signal(fence);
129 } 140 }
141
142 return drop;
130} 143}
131 144
132static int 145static int
@@ -135,18 +148,21 @@ nouveau_fence_wait_uevent_handler(struct nvif_notify *notify)
135 struct nouveau_fence_chan *fctx = 148 struct nouveau_fence_chan *fctx =
136 container_of(notify, typeof(*fctx), notify); 149 container_of(notify, typeof(*fctx), notify);
137 unsigned long flags; 150 unsigned long flags;
151 int ret = NVIF_NOTIFY_KEEP;
138 152
139 spin_lock_irqsave(&fctx->lock, flags); 153 spin_lock_irqsave(&fctx->lock, flags);
140 if (!list_empty(&fctx->pending)) { 154 if (!list_empty(&fctx->pending)) {
141 struct nouveau_fence *fence; 155 struct nouveau_fence *fence;
156 struct nouveau_channel *chan;
142 157
143 fence = list_entry(fctx->pending.next, typeof(*fence), head); 158 fence = list_entry(fctx->pending.next, typeof(*fence), head);
144 nouveau_fence_update(fence->channel, fctx); 159 chan = rcu_dereference_protected(fence->channel, lockdep_is_held(&fctx->lock));
160 if (nouveau_fence_update(fence->channel, fctx))
161 ret = NVIF_NOTIFY_DROP;
145 } 162 }
146 spin_unlock_irqrestore(&fctx->lock, flags); 163 spin_unlock_irqrestore(&fctx->lock, flags);
147 164
148 /* Always return keep here. NVIF refcount is handled with nouveau_fence_update */ 165 return ret;
149 return NVIF_NOTIFY_KEEP;
150} 166}
151 167
152void 168void
@@ -262,7 +278,10 @@ nouveau_fence_emit(struct nouveau_fence *fence, struct nouveau_channel *chan)
262 if (!ret) { 278 if (!ret) {
263 fence_get(&fence->base); 279 fence_get(&fence->base);
264 spin_lock_irq(&fctx->lock); 280 spin_lock_irq(&fctx->lock);
265 nouveau_fence_update(chan, fctx); 281
282 if (nouveau_fence_update(chan, fctx))
283 nvif_notify_put(&fctx->notify);
284
266 list_add_tail(&fence->head, &fctx->pending); 285 list_add_tail(&fence->head, &fctx->pending);
267 spin_unlock_irq(&fctx->lock); 286 spin_unlock_irq(&fctx->lock);
268 } 287 }
@@ -276,13 +295,16 @@ nouveau_fence_done(struct nouveau_fence *fence)
276 if (fence->base.ops == &nouveau_fence_ops_legacy || 295 if (fence->base.ops == &nouveau_fence_ops_legacy ||
277 fence->base.ops == &nouveau_fence_ops_uevent) { 296 fence->base.ops == &nouveau_fence_ops_uevent) {
278 struct nouveau_fence_chan *fctx = nouveau_fctx(fence); 297 struct nouveau_fence_chan *fctx = nouveau_fctx(fence);
298 struct nouveau_channel *chan;
279 unsigned long flags; 299 unsigned long flags;
280 300
281 if (test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->base.flags)) 301 if (test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->base.flags))
282 return true; 302 return true;
283 303
284 spin_lock_irqsave(&fctx->lock, flags); 304 spin_lock_irqsave(&fctx->lock, flags);
285 nouveau_fence_update(fence->channel, fctx); 305 chan = rcu_dereference_protected(fence->channel, lockdep_is_held(&fctx->lock));
306 if (chan && nouveau_fence_update(chan, fctx))
307 nvif_notify_put(&fctx->notify);
286 spin_unlock_irqrestore(&fctx->lock, flags); 308 spin_unlock_irqrestore(&fctx->lock, flags);
287 } 309 }
288 return fence_is_signaled(&fence->base); 310 return fence_is_signaled(&fence->base);
@@ -387,12 +409,18 @@ nouveau_fence_sync(struct nouveau_bo *nvbo, struct nouveau_channel *chan, bool e
387 409
388 if (fence && (!exclusive || !fobj || !fobj->shared_count)) { 410 if (fence && (!exclusive || !fobj || !fobj->shared_count)) {
389 struct nouveau_channel *prev = NULL; 411 struct nouveau_channel *prev = NULL;
412 bool must_wait = true;
390 413
391 f = nouveau_local_fence(fence, chan->drm); 414 f = nouveau_local_fence(fence, chan->drm);
392 if (f) 415 if (f) {
393 prev = f->channel; 416 rcu_read_lock();
417 prev = rcu_dereference(f->channel);
418 if (prev && (prev == chan || fctx->sync(f, prev, chan) == 0))
419 must_wait = false;
420 rcu_read_unlock();
421 }
394 422
395 if (!prev || (prev != chan && (ret = fctx->sync(f, prev, chan)))) 423 if (must_wait)
396 ret = fence_wait(fence, intr); 424 ret = fence_wait(fence, intr);
397 425
398 return ret; 426 return ret;
@@ -403,19 +431,22 @@ nouveau_fence_sync(struct nouveau_bo *nvbo, struct nouveau_channel *chan, bool e
403 431
404 for (i = 0; i < fobj->shared_count && !ret; ++i) { 432 for (i = 0; i < fobj->shared_count && !ret; ++i) {
405 struct nouveau_channel *prev = NULL; 433 struct nouveau_channel *prev = NULL;
434 bool must_wait = true;
406 435
407 fence = rcu_dereference_protected(fobj->shared[i], 436 fence = rcu_dereference_protected(fobj->shared[i],
408 reservation_object_held(resv)); 437 reservation_object_held(resv));
409 438
410 f = nouveau_local_fence(fence, chan->drm); 439 f = nouveau_local_fence(fence, chan->drm);
411 if (f) 440 if (f) {
412 prev = f->channel; 441 rcu_read_lock();
442 prev = rcu_dereference(f->channel);
443 if (prev && (prev == chan || fctx->sync(f, prev, chan) == 0))
444 must_wait = false;
445 rcu_read_unlock();
446 }
413 447
414 if (!prev || (prev != chan && (ret = fctx->sync(f, prev, chan)))) 448 if (must_wait)
415 ret = fence_wait(fence, intr); 449 ret = fence_wait(fence, intr);
416
417 if (ret)
418 break;
419 } 450 }
420 451
421 return ret; 452 return ret;
@@ -463,7 +494,7 @@ static const char *nouveau_fence_get_timeline_name(struct fence *f)
463 struct nouveau_fence *fence = from_fence(f); 494 struct nouveau_fence *fence = from_fence(f);
464 struct nouveau_fence_chan *fctx = nouveau_fctx(fence); 495 struct nouveau_fence_chan *fctx = nouveau_fctx(fence);
465 496
466 return fence->channel ? fctx->name : "dead channel"; 497 return !fctx->dead ? fctx->name : "dead channel";
467} 498}
468 499
469/* 500/*
@@ -476,9 +507,16 @@ static bool nouveau_fence_is_signaled(struct fence *f)
476{ 507{
477 struct nouveau_fence *fence = from_fence(f); 508 struct nouveau_fence *fence = from_fence(f);
478 struct nouveau_fence_chan *fctx = nouveau_fctx(fence); 509 struct nouveau_fence_chan *fctx = nouveau_fctx(fence);
479 struct nouveau_channel *chan = fence->channel; 510 struct nouveau_channel *chan;
511 bool ret = false;
512
513 rcu_read_lock();
514 chan = rcu_dereference(fence->channel);
515 if (chan)
516 ret = (int)(fctx->read(chan) - fence->base.seqno) >= 0;
517 rcu_read_unlock();
480 518
481 return (int)(fctx->read(chan) - fence->base.seqno) >= 0; 519 return ret;
482} 520}
483 521
484static bool nouveau_fence_no_signaling(struct fence *f) 522static bool nouveau_fence_no_signaling(struct fence *f)
diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
index 943b0b17b1fc..96e461c6f68f 100644
--- a/drivers/gpu/drm/nouveau/nouveau_fence.h
+++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
@@ -14,7 +14,7 @@ struct nouveau_fence {
14 14
15 bool sysmem; 15 bool sysmem;
16 16
17 struct nouveau_channel *channel; 17 struct nouveau_channel __rcu *channel;
18 unsigned long timeout; 18 unsigned long timeout;
19}; 19};
20 20
@@ -47,7 +47,7 @@ struct nouveau_fence_chan {
47 char name[32]; 47 char name[32];
48 48
49 struct nvif_notify notify; 49 struct nvif_notify notify;
50 int notify_ref; 50 int notify_ref, dead;
51}; 51};
52 52
53struct nouveau_fence_priv { 53struct nouveau_fence_priv {
diff --git a/drivers/gpu/drm/radeon/r600_dpm.c b/drivers/gpu/drm/radeon/r600_dpm.c
index f6309bd23e01..b5c73df8e202 100644
--- a/drivers/gpu/drm/radeon/r600_dpm.c
+++ b/drivers/gpu/drm/radeon/r600_dpm.c
@@ -1256,7 +1256,7 @@ int r600_parse_extended_power_table(struct radeon_device *rdev)
1256 (mode_info->atom_context->bios + data_offset + 1256 (mode_info->atom_context->bios + data_offset +
1257 le16_to_cpu(ext_hdr->usPowerTuneTableOffset)); 1257 le16_to_cpu(ext_hdr->usPowerTuneTableOffset));
1258 rdev->pm.dpm.dyn_state.cac_tdp_table->maximum_power_delivery_limit = 1258 rdev->pm.dpm.dyn_state.cac_tdp_table->maximum_power_delivery_limit =
1259 ppt->usMaximumPowerDeliveryLimit; 1259 le16_to_cpu(ppt->usMaximumPowerDeliveryLimit);
1260 pt = &ppt->power_tune_table; 1260 pt = &ppt->power_tune_table;
1261 } else { 1261 } else {
1262 ATOM_PPLIB_POWERTUNE_Table *ppt = (ATOM_PPLIB_POWERTUNE_Table *) 1262 ATOM_PPLIB_POWERTUNE_Table *ppt = (ATOM_PPLIB_POWERTUNE_Table *)
diff --git a/drivers/gpu/drm/radeon/radeon_connectors.c b/drivers/gpu/drm/radeon/radeon_connectors.c
index 300c4b3d4669..26baa9c05f6c 100644
--- a/drivers/gpu/drm/radeon/radeon_connectors.c
+++ b/drivers/gpu/drm/radeon/radeon_connectors.c
@@ -322,6 +322,12 @@ static void radeon_connector_get_edid(struct drm_connector *connector)
322 } 322 }
323 323
324 if (!radeon_connector->edid) { 324 if (!radeon_connector->edid) {
325 /* don't fetch the edid from the vbios if ddc fails and runpm is
326 * enabled so we report disconnected.
327 */
328 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
329 return;
330
325 if (rdev->is_atom_bios) { 331 if (rdev->is_atom_bios) {
326 /* some laptops provide a hardcoded edid in rom for LCDs */ 332 /* some laptops provide a hardcoded edid in rom for LCDs */
327 if (((connector->connector_type == DRM_MODE_CONNECTOR_LVDS) || 333 if (((connector->connector_type == DRM_MODE_CONNECTOR_LVDS) ||
@@ -826,6 +832,8 @@ static int radeon_lvds_mode_valid(struct drm_connector *connector,
826static enum drm_connector_status 832static enum drm_connector_status
827radeon_lvds_detect(struct drm_connector *connector, bool force) 833radeon_lvds_detect(struct drm_connector *connector, bool force)
828{ 834{
835 struct drm_device *dev = connector->dev;
836 struct radeon_device *rdev = dev->dev_private;
829 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 837 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
830 struct drm_encoder *encoder = radeon_best_single_encoder(connector); 838 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
831 enum drm_connector_status ret = connector_status_disconnected; 839 enum drm_connector_status ret = connector_status_disconnected;
@@ -842,7 +850,11 @@ radeon_lvds_detect(struct drm_connector *connector, bool force)
842 /* check if panel is valid */ 850 /* check if panel is valid */
843 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240) 851 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
844 ret = connector_status_connected; 852 ret = connector_status_connected;
845 853 /* don't fetch the edid from the vbios if ddc fails and runpm is
854 * enabled so we report disconnected.
855 */
856 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
857 ret = connector_status_disconnected;
846 } 858 }
847 859
848 /* check for edid as well */ 860 /* check for edid as well */
@@ -1589,6 +1601,11 @@ radeon_dp_detect(struct drm_connector *connector, bool force)
1589 /* check if panel is valid */ 1601 /* check if panel is valid */
1590 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240) 1602 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
1591 ret = connector_status_connected; 1603 ret = connector_status_connected;
1604 /* don't fetch the edid from the vbios if ddc fails and runpm is
1605 * enabled so we report disconnected.
1606 */
1607 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
1608 ret = connector_status_disconnected;
1592 } 1609 }
1593 /* eDP is always DP */ 1610 /* eDP is always DP */
1594 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT; 1611 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
diff --git a/drivers/gpu/drm/radeon/radeon_cs.c b/drivers/gpu/drm/radeon/radeon_cs.c
index a3e7aed7e680..6f377de099f9 100644
--- a/drivers/gpu/drm/radeon/radeon_cs.c
+++ b/drivers/gpu/drm/radeon/radeon_cs.c
@@ -251,22 +251,19 @@ static int radeon_cs_get_ring(struct radeon_cs_parser *p, u32 ring, s32 priority
251 251
252static int radeon_cs_sync_rings(struct radeon_cs_parser *p) 252static int radeon_cs_sync_rings(struct radeon_cs_parser *p)
253{ 253{
254 int i, r = 0; 254 struct radeon_cs_reloc *reloc;
255 int r;
255 256
256 for (i = 0; i < p->nrelocs; i++) { 257 list_for_each_entry(reloc, &p->validated, tv.head) {
257 struct reservation_object *resv; 258 struct reservation_object *resv;
258 259
259 if (!p->relocs[i].robj) 260 resv = reloc->robj->tbo.resv;
260 continue;
261
262 resv = p->relocs[i].robj->tbo.resv;
263 r = radeon_semaphore_sync_resv(p->rdev, p->ib.semaphore, resv, 261 r = radeon_semaphore_sync_resv(p->rdev, p->ib.semaphore, resv,
264 p->relocs[i].tv.shared); 262 reloc->tv.shared);
265
266 if (r) 263 if (r)
267 break; 264 return r;
268 } 265 }
269 return r; 266 return 0;
270} 267}
271 268
272/* XXX: note that this is called from the legacy UMS CS ioctl as well */ 269/* XXX: note that this is called from the legacy UMS CS ioctl as well */
diff --git a/drivers/gpu/drm/radeon/radeon_encoders.c b/drivers/gpu/drm/radeon/radeon_encoders.c
index 9a19e52cc655..6b670b0bc47b 100644
--- a/drivers/gpu/drm/radeon/radeon_encoders.c
+++ b/drivers/gpu/drm/radeon/radeon_encoders.c
@@ -179,6 +179,9 @@ static void radeon_encoder_add_backlight(struct radeon_encoder *radeon_encoder,
179 (rdev->pdev->subsystem_vendor == 0x1734) && 179 (rdev->pdev->subsystem_vendor == 0x1734) &&
180 (rdev->pdev->subsystem_device == 0x1107)) 180 (rdev->pdev->subsystem_device == 0x1107))
181 use_bl = false; 181 use_bl = false;
182 /* disable native backlight control on older asics */
183 else if (rdev->family < CHIP_R600)
184 use_bl = false;
182 else 185 else
183 use_bl = true; 186 use_bl = true;
184 } 187 }
diff --git a/drivers/gpu/drm/radeon/radeon_irq_kms.c b/drivers/gpu/drm/radeon/radeon_irq_kms.c
index 7784911d78ef..00fc59762e0d 100644
--- a/drivers/gpu/drm/radeon/radeon_irq_kms.c
+++ b/drivers/gpu/drm/radeon/radeon_irq_kms.c
@@ -185,6 +185,16 @@ static bool radeon_msi_ok(struct radeon_device *rdev)
185 if (rdev->flags & RADEON_IS_AGP) 185 if (rdev->flags & RADEON_IS_AGP)
186 return false; 186 return false;
187 187
188 /*
189 * Older chips have a HW limitation, they can only generate 40 bits
190 * of address for "64-bit" MSIs which breaks on some platforms, notably
191 * IBM POWER servers, so we limit them
192 */
193 if (rdev->family < CHIP_BONAIRE) {
194 dev_info(rdev->dev, "radeon: MSI limited to 32-bit\n");
195 rdev->pdev->no_64bit_msi = 1;
196 }
197
188 /* force MSI on */ 198 /* force MSI on */
189 if (radeon_msi == 1) 199 if (radeon_msi == 1)
190 return true; 200 return true;
diff --git a/drivers/gpu/drm/radeon/radeon_kms.c b/drivers/gpu/drm/radeon/radeon_kms.c
index 8309b11e674d..03586763ee86 100644
--- a/drivers/gpu/drm/radeon/radeon_kms.c
+++ b/drivers/gpu/drm/radeon/radeon_kms.c
@@ -795,6 +795,8 @@ int radeon_get_vblank_timestamp_kms(struct drm_device *dev, int crtc,
795 795
796 /* Get associated drm_crtc: */ 796 /* Get associated drm_crtc: */
797 drmcrtc = &rdev->mode_info.crtcs[crtc]->base; 797 drmcrtc = &rdev->mode_info.crtcs[crtc]->base;
798 if (!drmcrtc)
799 return -EINVAL;
798 800
799 /* Helper routine in DRM core does all the work: */ 801 /* Helper routine in DRM core does all the work: */
800 return drm_calc_vbltimestamp_from_scanoutpos(dev, crtc, max_error, 802 return drm_calc_vbltimestamp_from_scanoutpos(dev, crtc, max_error,
diff --git a/drivers/gpu/drm/radeon/radeon_object.c b/drivers/gpu/drm/radeon/radeon_object.c
index 99a960a4f302..4c0d786d5c7a 100644
--- a/drivers/gpu/drm/radeon/radeon_object.c
+++ b/drivers/gpu/drm/radeon/radeon_object.c
@@ -213,6 +213,13 @@ int radeon_bo_create(struct radeon_device *rdev,
213 if (!(rdev->flags & RADEON_IS_PCIE)) 213 if (!(rdev->flags & RADEON_IS_PCIE))
214 bo->flags &= ~(RADEON_GEM_GTT_WC | RADEON_GEM_GTT_UC); 214 bo->flags &= ~(RADEON_GEM_GTT_WC | RADEON_GEM_GTT_UC);
215 215
216#ifdef CONFIG_X86_32
217 /* XXX: Write-combined CPU mappings of GTT seem broken on 32-bit
218 * See https://bugs.freedesktop.org/show_bug.cgi?id=84627
219 */
220 bo->flags &= ~RADEON_GEM_GTT_WC;
221#endif
222
216 radeon_ttm_placement_from_domain(bo, domain); 223 radeon_ttm_placement_from_domain(bo, domain);
217 /* Kernel allocation are uninterruptible */ 224 /* Kernel allocation are uninterruptible */
218 down_read(&rdev->pm.mclk_lock); 225 down_read(&rdev->pm.mclk_lock);
diff --git a/drivers/hwmon/g762.c b/drivers/hwmon/g762.c
index 6aac695b1688..9b55e673b67c 100644
--- a/drivers/hwmon/g762.c
+++ b/drivers/hwmon/g762.c
@@ -1084,10 +1084,8 @@ static int g762_probe(struct i2c_client *client, const struct i2c_device_id *id)
1084 if (ret) 1084 if (ret)
1085 goto clock_dis; 1085 goto clock_dis;
1086 1086
1087 data->hwmon_dev = devm_hwmon_device_register_with_groups(dev, 1087 data->hwmon_dev = hwmon_device_register_with_groups(dev, client->name,
1088 client->name, 1088 data, g762_groups);
1089 data,
1090 g762_groups);
1091 if (IS_ERR(data->hwmon_dev)) { 1089 if (IS_ERR(data->hwmon_dev)) {
1092 ret = PTR_ERR(data->hwmon_dev); 1090 ret = PTR_ERR(data->hwmon_dev);
1093 goto clock_dis; 1091 goto clock_dis;
diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
index 63f3f03ecc9b..c604f4c3ac0d 100644
--- a/drivers/i2c/busses/i2c-cadence.c
+++ b/drivers/i2c/busses/i2c-cadence.c
@@ -111,6 +111,8 @@
111#define CDNS_I2C_DIVA_MAX 4 111#define CDNS_I2C_DIVA_MAX 4
112#define CDNS_I2C_DIVB_MAX 64 112#define CDNS_I2C_DIVB_MAX 64
113 113
114#define CDNS_I2C_TIMEOUT_MAX 0xFF
115
114#define cdns_i2c_readreg(offset) readl_relaxed(id->membase + offset) 116#define cdns_i2c_readreg(offset) readl_relaxed(id->membase + offset)
115#define cdns_i2c_writereg(val, offset) writel_relaxed(val, id->membase + offset) 117#define cdns_i2c_writereg(val, offset) writel_relaxed(val, id->membase + offset)
116 118
@@ -852,6 +854,15 @@ static int cdns_i2c_probe(struct platform_device *pdev)
852 goto err_clk_dis; 854 goto err_clk_dis;
853 } 855 }
854 856
857 /*
858 * Cadence I2C controller has a bug wherein it generates
859 * invalid read transaction after HW timeout in master receiver mode.
860 * HW timeout is not used by this driver and the interrupt is disabled.
861 * But the feature itself cannot be disabled. Hence maximum value
862 * is written to this register to reduce the chances of error.
863 */
864 cdns_i2c_writereg(CDNS_I2C_TIMEOUT_MAX, CDNS_I2C_TIME_OUT_OFFSET);
865
855 dev_info(&pdev->dev, "%u kHz mmio %08lx irq %d\n", 866 dev_info(&pdev->dev, "%u kHz mmio %08lx irq %d\n",
856 id->i2c_clk / 1000, (unsigned long)r_mem->start, id->irq); 867 id->i2c_clk / 1000, (unsigned long)r_mem->start, id->irq);
857 868
diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
index d15b7c9b9219..01f0cd87a4a5 100644
--- a/drivers/i2c/busses/i2c-davinci.c
+++ b/drivers/i2c/busses/i2c-davinci.c
@@ -407,11 +407,9 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
407 if (dev->cmd_err & DAVINCI_I2C_STR_NACK) { 407 if (dev->cmd_err & DAVINCI_I2C_STR_NACK) {
408 if (msg->flags & I2C_M_IGNORE_NAK) 408 if (msg->flags & I2C_M_IGNORE_NAK)
409 return msg->len; 409 return msg->len;
410 if (stop) { 410 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG);
411 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG); 411 w |= DAVINCI_I2C_MDR_STP;
412 w |= DAVINCI_I2C_MDR_STP; 412 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, w);
413 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, w);
414 }
415 return -EREMOTEIO; 413 return -EREMOTEIO;
416 } 414 }
417 return -EIO; 415 return -EIO;
diff --git a/drivers/i2c/busses/i2c-designware-core.c b/drivers/i2c/busses/i2c-designware-core.c
index edca99dbba23..23628b7bfb8d 100644
--- a/drivers/i2c/busses/i2c-designware-core.c
+++ b/drivers/i2c/busses/i2c-designware-core.c
@@ -359,7 +359,7 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
359 } 359 }
360 360
361 /* Configure Tx/Rx FIFO threshold levels */ 361 /* Configure Tx/Rx FIFO threshold levels */
362 dw_writel(dev, dev->tx_fifo_depth - 1, DW_IC_TX_TL); 362 dw_writel(dev, dev->tx_fifo_depth / 2, DW_IC_TX_TL);
363 dw_writel(dev, 0, DW_IC_RX_TL); 363 dw_writel(dev, 0, DW_IC_RX_TL);
364 364
365 /* configure the i2c master */ 365 /* configure the i2c master */
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index 26942c159de1..277a2288d4a8 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -922,14 +922,12 @@ omap_i2c_isr_thread(int this_irq, void *dev_id)
922 if (stat & OMAP_I2C_STAT_NACK) { 922 if (stat & OMAP_I2C_STAT_NACK) {
923 err |= OMAP_I2C_STAT_NACK; 923 err |= OMAP_I2C_STAT_NACK;
924 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_NACK); 924 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_NACK);
925 break;
926 } 925 }
927 926
928 if (stat & OMAP_I2C_STAT_AL) { 927 if (stat & OMAP_I2C_STAT_AL) {
929 dev_err(dev->dev, "Arbitration lost\n"); 928 dev_err(dev->dev, "Arbitration lost\n");
930 err |= OMAP_I2C_STAT_AL; 929 err |= OMAP_I2C_STAT_AL;
931 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_AL); 930 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_AL);
932 break;
933 } 931 }
934 932
935 /* 933 /*
@@ -954,11 +952,13 @@ omap_i2c_isr_thread(int this_irq, void *dev_id)
954 if (dev->fifo_size) 952 if (dev->fifo_size)
955 num_bytes = dev->buf_len; 953 num_bytes = dev->buf_len;
956 954
957 omap_i2c_receive_data(dev, num_bytes, true); 955 if (dev->errata & I2C_OMAP_ERRATA_I207) {
958
959 if (dev->errata & I2C_OMAP_ERRATA_I207)
960 i2c_omap_errata_i207(dev, stat); 956 i2c_omap_errata_i207(dev, stat);
957 num_bytes = (omap_i2c_read_reg(dev,
958 OMAP_I2C_BUFSTAT_REG) >> 8) & 0x3F;
959 }
961 960
961 omap_i2c_receive_data(dev, num_bytes, true);
962 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_RDR); 962 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_RDR);
963 continue; 963 continue;
964 } 964 }
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index f43b4e11647a..68aeb8eedae0 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -403,6 +403,7 @@ static int acpi_i2c_install_space_handler(struct i2c_adapter *adapter)
403 return -ENOMEM; 403 return -ENOMEM;
404 } 404 }
405 405
406 acpi_walk_dep_device_list(handle);
406 return 0; 407 return 0;
407} 408}
408 409
diff --git a/drivers/iio/accel/bmc150-accel.c b/drivers/iio/accel/bmc150-accel.c
index 22c096ce39ad..513bd6d14293 100644
--- a/drivers/iio/accel/bmc150-accel.c
+++ b/drivers/iio/accel/bmc150-accel.c
@@ -44,6 +44,9 @@
44 44
45#define BMC150_ACCEL_REG_INT_STATUS_2 0x0B 45#define BMC150_ACCEL_REG_INT_STATUS_2 0x0B
46#define BMC150_ACCEL_ANY_MOTION_MASK 0x07 46#define BMC150_ACCEL_ANY_MOTION_MASK 0x07
47#define BMC150_ACCEL_ANY_MOTION_BIT_X BIT(0)
48#define BMC150_ACCEL_ANY_MOTION_BIT_Y BIT(1)
49#define BMC150_ACCEL_ANY_MOTION_BIT_Z BIT(2)
47#define BMC150_ACCEL_ANY_MOTION_BIT_SIGN BIT(3) 50#define BMC150_ACCEL_ANY_MOTION_BIT_SIGN BIT(3)
48 51
49#define BMC150_ACCEL_REG_PMU_LPW 0x11 52#define BMC150_ACCEL_REG_PMU_LPW 0x11
@@ -92,9 +95,9 @@
92#define BMC150_ACCEL_SLOPE_THRES_MASK 0xFF 95#define BMC150_ACCEL_SLOPE_THRES_MASK 0xFF
93 96
94/* Slope duration in terms of number of samples */ 97/* Slope duration in terms of number of samples */
95#define BMC150_ACCEL_DEF_SLOPE_DURATION 2 98#define BMC150_ACCEL_DEF_SLOPE_DURATION 1
96/* in terms of multiples of g's/LSB, based on range */ 99/* in terms of multiples of g's/LSB, based on range */
97#define BMC150_ACCEL_DEF_SLOPE_THRESHOLD 5 100#define BMC150_ACCEL_DEF_SLOPE_THRESHOLD 1
98 101
99#define BMC150_ACCEL_REG_XOUT_L 0x02 102#define BMC150_ACCEL_REG_XOUT_L 0x02
100 103
@@ -536,6 +539,9 @@ static int bmc150_accel_set_power_state(struct bmc150_accel_data *data, bool on)
536 if (ret < 0) { 539 if (ret < 0) {
537 dev_err(&data->client->dev, 540 dev_err(&data->client->dev,
538 "Failed: bmc150_accel_set_power_state for %d\n", on); 541 "Failed: bmc150_accel_set_power_state for %d\n", on);
542 if (on)
543 pm_runtime_put_noidle(&data->client->dev);
544
539 return ret; 545 return ret;
540 } 546 }
541 547
@@ -811,6 +817,7 @@ static int bmc150_accel_write_event_config(struct iio_dev *indio_dev,
811 817
812 ret = bmc150_accel_setup_any_motion_interrupt(data, state); 818 ret = bmc150_accel_setup_any_motion_interrupt(data, state);
813 if (ret < 0) { 819 if (ret < 0) {
820 bmc150_accel_set_power_state(data, false);
814 mutex_unlock(&data->mutex); 821 mutex_unlock(&data->mutex);
815 return ret; 822 return ret;
816 } 823 }
@@ -846,7 +853,7 @@ static const struct attribute_group bmc150_accel_attrs_group = {
846 853
847static const struct iio_event_spec bmc150_accel_event = { 854static const struct iio_event_spec bmc150_accel_event = {
848 .type = IIO_EV_TYPE_ROC, 855 .type = IIO_EV_TYPE_ROC,
849 .dir = IIO_EV_DIR_RISING | IIO_EV_DIR_FALLING, 856 .dir = IIO_EV_DIR_EITHER,
850 .mask_separate = BIT(IIO_EV_INFO_VALUE) | 857 .mask_separate = BIT(IIO_EV_INFO_VALUE) |
851 BIT(IIO_EV_INFO_ENABLE) | 858 BIT(IIO_EV_INFO_ENABLE) |
852 BIT(IIO_EV_INFO_PERIOD) 859 BIT(IIO_EV_INFO_PERIOD)
@@ -1054,6 +1061,7 @@ static int bmc150_accel_data_rdy_trigger_set_state(struct iio_trigger *trig,
1054 else 1061 else
1055 ret = bmc150_accel_setup_new_data_interrupt(data, state); 1062 ret = bmc150_accel_setup_new_data_interrupt(data, state);
1056 if (ret < 0) { 1063 if (ret < 0) {
1064 bmc150_accel_set_power_state(data, false);
1057 mutex_unlock(&data->mutex); 1065 mutex_unlock(&data->mutex);
1058 return ret; 1066 return ret;
1059 } 1067 }
@@ -1092,12 +1100,26 @@ static irqreturn_t bmc150_accel_event_handler(int irq, void *private)
1092 else 1100 else
1093 dir = IIO_EV_DIR_RISING; 1101 dir = IIO_EV_DIR_RISING;
1094 1102
1095 if (ret & BMC150_ACCEL_ANY_MOTION_MASK) 1103 if (ret & BMC150_ACCEL_ANY_MOTION_BIT_X)
1104 iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL,
1105 0,
1106 IIO_MOD_X,
1107 IIO_EV_TYPE_ROC,
1108 dir),
1109 data->timestamp);
1110 if (ret & BMC150_ACCEL_ANY_MOTION_BIT_Y)
1096 iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL, 1111 iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL,
1097 0, 1112 0,
1098 IIO_MOD_X_OR_Y_OR_Z, 1113 IIO_MOD_Y,
1099 IIO_EV_TYPE_ROC, 1114 IIO_EV_TYPE_ROC,
1100 IIO_EV_DIR_EITHER), 1115 dir),
1116 data->timestamp);
1117 if (ret & BMC150_ACCEL_ANY_MOTION_BIT_Z)
1118 iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL,
1119 0,
1120 IIO_MOD_Z,
1121 IIO_EV_TYPE_ROC,
1122 dir),
1101 data->timestamp); 1123 data->timestamp);
1102ack_intr_status: 1124ack_intr_status:
1103 if (!data->dready_trigger_on) 1125 if (!data->dready_trigger_on)
@@ -1354,10 +1376,14 @@ static int bmc150_accel_runtime_suspend(struct device *dev)
1354{ 1376{
1355 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); 1377 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
1356 struct bmc150_accel_data *data = iio_priv(indio_dev); 1378 struct bmc150_accel_data *data = iio_priv(indio_dev);
1379 int ret;
1357 1380
1358 dev_dbg(&data->client->dev, __func__); 1381 dev_dbg(&data->client->dev, __func__);
1382 ret = bmc150_accel_set_mode(data, BMC150_ACCEL_SLEEP_MODE_SUSPEND, 0);
1383 if (ret < 0)
1384 return -EAGAIN;
1359 1385
1360 return bmc150_accel_set_mode(data, BMC150_ACCEL_SLEEP_MODE_SUSPEND, 0); 1386 return 0;
1361} 1387}
1362 1388
1363static int bmc150_accel_runtime_resume(struct device *dev) 1389static int bmc150_accel_runtime_resume(struct device *dev)
diff --git a/drivers/iio/accel/kxcjk-1013.c b/drivers/iio/accel/kxcjk-1013.c
index a23e58c4ed99..320aa72c0349 100644
--- a/drivers/iio/accel/kxcjk-1013.c
+++ b/drivers/iio/accel/kxcjk-1013.c
@@ -269,6 +269,8 @@ static int kxcjk1013_set_range(struct kxcjk1013_data *data, int range_index)
269 return ret; 269 return ret;
270 } 270 }
271 271
272 ret &= ~(KXCJK1013_REG_CTRL1_BIT_GSEL0 |
273 KXCJK1013_REG_CTRL1_BIT_GSEL1);
272 ret |= (KXCJK1013_scale_table[range_index].gsel_0 << 3); 274 ret |= (KXCJK1013_scale_table[range_index].gsel_0 << 3);
273 ret |= (KXCJK1013_scale_table[range_index].gsel_1 << 4); 275 ret |= (KXCJK1013_scale_table[range_index].gsel_1 << 4);
274 276
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 88bdc8f612e2..bc4e787096e8 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -127,6 +127,14 @@ config AT91_ADC
127 help 127 help
128 Say yes here to build support for Atmel AT91 ADC. 128 Say yes here to build support for Atmel AT91 ADC.
129 129
130config AXP288_ADC
131 tristate "X-Powers AXP288 ADC driver"
132 depends on MFD_AXP20X
133 help
134 Say yes here to have support for X-Powers power management IC (PMIC) ADC
135 device. Depending on platform configuration, this general purpose ADC can
136 be used for sampling sensors such as thermal resistors.
137
130config EXYNOS_ADC 138config EXYNOS_ADC
131 tristate "Exynos ADC driver support" 139 tristate "Exynos ADC driver support"
132 depends on ARCH_EXYNOS || ARCH_S3C24XX || ARCH_S3C64XX || (OF && COMPILE_TEST) 140 depends on ARCH_EXYNOS || ARCH_S3C24XX || ARCH_S3C64XX || (OF && COMPILE_TEST)
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index cb88a6a23b8f..f30093f5b67a 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -14,6 +14,7 @@ obj-$(CONFIG_AD7793) += ad7793.o
14obj-$(CONFIG_AD7887) += ad7887.o 14obj-$(CONFIG_AD7887) += ad7887.o
15obj-$(CONFIG_AD799X) += ad799x.o 15obj-$(CONFIG_AD799X) += ad799x.o
16obj-$(CONFIG_AT91_ADC) += at91_adc.o 16obj-$(CONFIG_AT91_ADC) += at91_adc.o
17obj-$(CONFIG_AXP288_ADC) += axp288_adc.o
17obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o 18obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o
18obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o 19obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o
19obj-$(CONFIG_MAX1027) += max1027.o 20obj-$(CONFIG_MAX1027) += max1027.o
diff --git a/drivers/iio/adc/axp288_adc.c b/drivers/iio/adc/axp288_adc.c
new file mode 100644
index 000000000000..08bcfb061ca5
--- /dev/null
+++ b/drivers/iio/adc/axp288_adc.c
@@ -0,0 +1,261 @@
1/*
2 * axp288_adc.c - X-Powers AXP288 PMIC ADC Driver
3 *
4 * Copyright (C) 2014 Intel Corporation
5 *
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 */
18
19#include <linux/module.h>
20#include <linux/kernel.h>
21#include <linux/device.h>
22#include <linux/regmap.h>
23#include <linux/mfd/axp20x.h>
24#include <linux/platform_device.h>
25
26#include <linux/iio/iio.h>
27#include <linux/iio/machine.h>
28#include <linux/iio/driver.h>
29
30#define AXP288_ADC_EN_MASK 0xF1
31#define AXP288_ADC_TS_PIN_GPADC 0xF2
32#define AXP288_ADC_TS_PIN_ON 0xF3
33
34enum axp288_adc_id {
35 AXP288_ADC_TS,
36 AXP288_ADC_PMIC,
37 AXP288_ADC_GP,
38 AXP288_ADC_BATT_CHRG_I,
39 AXP288_ADC_BATT_DISCHRG_I,
40 AXP288_ADC_BATT_V,
41 AXP288_ADC_NR_CHAN,
42};
43
44struct axp288_adc_info {
45 int irq;
46 struct regmap *regmap;
47};
48
49static const struct iio_chan_spec const axp288_adc_channels[] = {
50 {
51 .indexed = 1,
52 .type = IIO_TEMP,
53 .channel = 0,
54 .address = AXP288_TS_ADC_H,
55 .datasheet_name = "TS_PIN",
56 }, {
57 .indexed = 1,
58 .type = IIO_TEMP,
59 .channel = 1,
60 .address = AXP288_PMIC_ADC_H,
61 .datasheet_name = "PMIC_TEMP",
62 }, {
63 .indexed = 1,
64 .type = IIO_TEMP,
65 .channel = 2,
66 .address = AXP288_GP_ADC_H,
67 .datasheet_name = "GPADC",
68 }, {
69 .indexed = 1,
70 .type = IIO_CURRENT,
71 .channel = 3,
72 .address = AXP20X_BATT_CHRG_I_H,
73 .datasheet_name = "BATT_CHG_I",
74 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
75 }, {
76 .indexed = 1,
77 .type = IIO_CURRENT,
78 .channel = 4,
79 .address = AXP20X_BATT_DISCHRG_I_H,
80 .datasheet_name = "BATT_DISCHRG_I",
81 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
82 }, {
83 .indexed = 1,
84 .type = IIO_VOLTAGE,
85 .channel = 5,
86 .address = AXP20X_BATT_V_H,
87 .datasheet_name = "BATT_V",
88 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
89 },
90};
91
92#define AXP288_ADC_MAP(_adc_channel_label, _consumer_dev_name, \
93 _consumer_channel) \
94 { \
95 .adc_channel_label = _adc_channel_label, \
96 .consumer_dev_name = _consumer_dev_name, \
97 .consumer_channel = _consumer_channel, \
98 }
99
100/* for consumer drivers */
101static struct iio_map axp288_adc_default_maps[] = {
102 AXP288_ADC_MAP("TS_PIN", "axp288-batt", "axp288-batt-temp"),
103 AXP288_ADC_MAP("PMIC_TEMP", "axp288-pmic", "axp288-pmic-temp"),
104 AXP288_ADC_MAP("GPADC", "axp288-gpadc", "axp288-system-temp"),
105 AXP288_ADC_MAP("BATT_CHG_I", "axp288-chrg", "axp288-chrg-curr"),
106 AXP288_ADC_MAP("BATT_DISCHRG_I", "axp288-chrg", "axp288-chrg-d-curr"),
107 AXP288_ADC_MAP("BATT_V", "axp288-batt", "axp288-batt-volt"),
108 {},
109};
110
111static int axp288_adc_read_channel(int *val, unsigned long address,
112 struct regmap *regmap)
113{
114 u8 buf[2];
115
116 if (regmap_bulk_read(regmap, address, buf, 2))
117 return -EIO;
118 *val = (buf[0] << 4) + ((buf[1] >> 4) & 0x0F);
119
120 return IIO_VAL_INT;
121}
122
123static int axp288_adc_set_ts(struct regmap *regmap, unsigned int mode,
124 unsigned long address)
125{
126 /* channels other than GPADC do not need to switch TS pin */
127 if (address != AXP288_GP_ADC_H)
128 return 0;
129
130 return regmap_write(regmap, AXP288_ADC_TS_PIN_CTRL, mode);
131}
132
133static int axp288_adc_read_raw(struct iio_dev *indio_dev,
134 struct iio_chan_spec const *chan,
135 int *val, int *val2, long mask)
136{
137 int ret;
138 struct axp288_adc_info *info = iio_priv(indio_dev);
139
140 mutex_lock(&indio_dev->mlock);
141 switch (mask) {
142 case IIO_CHAN_INFO_RAW:
143 if (axp288_adc_set_ts(info->regmap, AXP288_ADC_TS_PIN_GPADC,
144 chan->address)) {
145 dev_err(&indio_dev->dev, "GPADC mode\n");
146 ret = -EINVAL;
147 break;
148 }
149 ret = axp288_adc_read_channel(val, chan->address, info->regmap);
150 if (axp288_adc_set_ts(info->regmap, AXP288_ADC_TS_PIN_ON,
151 chan->address))
152 dev_err(&indio_dev->dev, "TS pin restore\n");
153 break;
154 case IIO_CHAN_INFO_PROCESSED:
155 ret = axp288_adc_read_channel(val, chan->address, info->regmap);
156 break;
157 default:
158 ret = -EINVAL;
159 }
160 mutex_unlock(&indio_dev->mlock);
161
162 return ret;
163}
164
165static int axp288_adc_set_state(struct regmap *regmap)
166{
167 /* ADC should be always enabled for internal FG to function */
168 if (regmap_write(regmap, AXP288_ADC_TS_PIN_CTRL, AXP288_ADC_TS_PIN_ON))
169 return -EIO;
170
171 return regmap_write(regmap, AXP20X_ADC_EN1, AXP288_ADC_EN_MASK);
172}
173
174static const struct iio_info axp288_adc_iio_info = {
175 .read_raw = &axp288_adc_read_raw,
176 .driver_module = THIS_MODULE,
177};
178
179static int axp288_adc_probe(struct platform_device *pdev)
180{
181 int ret;
182 struct axp288_adc_info *info;
183 struct iio_dev *indio_dev;
184 struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent);
185
186 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*info));
187 if (!indio_dev)
188 return -ENOMEM;
189
190 info = iio_priv(indio_dev);
191 info->irq = platform_get_irq(pdev, 0);
192 if (info->irq < 0) {
193 dev_err(&pdev->dev, "no irq resource?\n");
194 return info->irq;
195 }
196 platform_set_drvdata(pdev, indio_dev);
197 info->regmap = axp20x->regmap;
198 /*
199 * Set ADC to enabled state at all time, including system suspend.
200 * otherwise internal fuel gauge functionality may be affected.
201 */
202 ret = axp288_adc_set_state(axp20x->regmap);
203 if (ret) {
204 dev_err(&pdev->dev, "unable to enable ADC device\n");
205 return ret;
206 }
207
208 indio_dev->dev.parent = &pdev->dev;
209 indio_dev->name = pdev->name;
210 indio_dev->channels = axp288_adc_channels;
211 indio_dev->num_channels = ARRAY_SIZE(axp288_adc_channels);
212 indio_dev->info = &axp288_adc_iio_info;
213 indio_dev->modes = INDIO_DIRECT_MODE;
214 ret = iio_map_array_register(indio_dev, axp288_adc_default_maps);
215 if (ret < 0)
216 return ret;
217
218 ret = iio_device_register(indio_dev);
219 if (ret < 0) {
220 dev_err(&pdev->dev, "unable to register iio device\n");
221 goto err_array_unregister;
222 }
223 return 0;
224
225err_array_unregister:
226 iio_map_array_unregister(indio_dev);
227
228 return ret;
229}
230
231static int axp288_adc_remove(struct platform_device *pdev)
232{
233 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
234
235 iio_device_unregister(indio_dev);
236 iio_map_array_unregister(indio_dev);
237
238 return 0;
239}
240
241static struct platform_device_id axp288_adc_id_table[] = {
242 { .name = "axp288_adc" },
243 {},
244};
245
246static struct platform_driver axp288_adc_driver = {
247 .probe = axp288_adc_probe,
248 .remove = axp288_adc_remove,
249 .id_table = axp288_adc_id_table,
250 .driver = {
251 .name = "axp288_adc",
252 },
253};
254
255MODULE_DEVICE_TABLE(platform, axp288_adc_id_table);
256
257module_platform_driver(axp288_adc_driver);
258
259MODULE_AUTHOR("Jacob Pan <jacob.jun.pan@linux.intel.com>");
260MODULE_DESCRIPTION("X-Powers AXP288 ADC Driver");
261MODULE_LICENSE("GPL");
diff --git a/drivers/iio/adc/men_z188_adc.c b/drivers/iio/adc/men_z188_adc.c
index b58d6302521f..d095efe1ba14 100644
--- a/drivers/iio/adc/men_z188_adc.c
+++ b/drivers/iio/adc/men_z188_adc.c
@@ -152,6 +152,7 @@ static void men_z188_remove(struct mcb_device *dev)
152 152
153static const struct mcb_device_id men_z188_ids[] = { 153static const struct mcb_device_id men_z188_ids[] = {
154 { .device = 0xbc }, 154 { .device = 0xbc },
155 { }
155}; 156};
156MODULE_DEVICE_TABLE(mcb, men_z188_ids); 157MODULE_DEVICE_TABLE(mcb, men_z188_ids);
157 158
diff --git a/drivers/iio/gyro/bmg160.c b/drivers/iio/gyro/bmg160.c
index 1f967e0d688e..d2fa526740ca 100644
--- a/drivers/iio/gyro/bmg160.c
+++ b/drivers/iio/gyro/bmg160.c
@@ -67,6 +67,9 @@
67#define BMG160_REG_INT_EN_0 0x15 67#define BMG160_REG_INT_EN_0 0x15
68#define BMG160_DATA_ENABLE_INT BIT(7) 68#define BMG160_DATA_ENABLE_INT BIT(7)
69 69
70#define BMG160_REG_INT_EN_1 0x16
71#define BMG160_INT1_BIT_OD BIT(1)
72
70#define BMG160_REG_XOUT_L 0x02 73#define BMG160_REG_XOUT_L 0x02
71#define BMG160_AXIS_TO_REG(axis) (BMG160_REG_XOUT_L + (axis * 2)) 74#define BMG160_AXIS_TO_REG(axis) (BMG160_REG_XOUT_L + (axis * 2))
72 75
@@ -82,6 +85,9 @@
82 85
83#define BMG160_REG_INT_STATUS_2 0x0B 86#define BMG160_REG_INT_STATUS_2 0x0B
84#define BMG160_ANY_MOTION_MASK 0x07 87#define BMG160_ANY_MOTION_MASK 0x07
88#define BMG160_ANY_MOTION_BIT_X BIT(0)
89#define BMG160_ANY_MOTION_BIT_Y BIT(1)
90#define BMG160_ANY_MOTION_BIT_Z BIT(2)
85 91
86#define BMG160_REG_TEMP 0x08 92#define BMG160_REG_TEMP 0x08
87#define BMG160_TEMP_CENTER_VAL 23 93#define BMG160_TEMP_CENTER_VAL 23
@@ -222,6 +228,19 @@ static int bmg160_chip_init(struct bmg160_data *data)
222 data->slope_thres = ret; 228 data->slope_thres = ret;
223 229
224 /* Set default interrupt mode */ 230 /* Set default interrupt mode */
231 ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_INT_EN_1);
232 if (ret < 0) {
233 dev_err(&data->client->dev, "Error reading reg_int_en_1\n");
234 return ret;
235 }
236 ret &= ~BMG160_INT1_BIT_OD;
237 ret = i2c_smbus_write_byte_data(data->client,
238 BMG160_REG_INT_EN_1, ret);
239 if (ret < 0) {
240 dev_err(&data->client->dev, "Error writing reg_int_en_1\n");
241 return ret;
242 }
243
225 ret = i2c_smbus_write_byte_data(data->client, 244 ret = i2c_smbus_write_byte_data(data->client,
226 BMG160_REG_INT_RST_LATCH, 245 BMG160_REG_INT_RST_LATCH,
227 BMG160_INT_MODE_LATCH_INT | 246 BMG160_INT_MODE_LATCH_INT |
@@ -250,6 +269,9 @@ static int bmg160_set_power_state(struct bmg160_data *data, bool on)
250 if (ret < 0) { 269 if (ret < 0) {
251 dev_err(&data->client->dev, 270 dev_err(&data->client->dev,
252 "Failed: bmg160_set_power_state for %d\n", on); 271 "Failed: bmg160_set_power_state for %d\n", on);
272 if (on)
273 pm_runtime_put_noidle(&data->client->dev);
274
253 return ret; 275 return ret;
254 } 276 }
255#endif 277#endif
@@ -705,6 +727,7 @@ static int bmg160_write_event_config(struct iio_dev *indio_dev,
705 727
706 ret = bmg160_setup_any_motion_interrupt(data, state); 728 ret = bmg160_setup_any_motion_interrupt(data, state);
707 if (ret < 0) { 729 if (ret < 0) {
730 bmg160_set_power_state(data, false);
708 mutex_unlock(&data->mutex); 731 mutex_unlock(&data->mutex);
709 return ret; 732 return ret;
710 } 733 }
@@ -743,7 +766,7 @@ static const struct attribute_group bmg160_attrs_group = {
743 766
744static const struct iio_event_spec bmg160_event = { 767static const struct iio_event_spec bmg160_event = {
745 .type = IIO_EV_TYPE_ROC, 768 .type = IIO_EV_TYPE_ROC,
746 .dir = IIO_EV_DIR_RISING | IIO_EV_DIR_FALLING, 769 .dir = IIO_EV_DIR_EITHER,
747 .mask_shared_by_type = BIT(IIO_EV_INFO_VALUE) | 770 .mask_shared_by_type = BIT(IIO_EV_INFO_VALUE) |
748 BIT(IIO_EV_INFO_ENABLE) 771 BIT(IIO_EV_INFO_ENABLE)
749}; 772};
@@ -871,6 +894,7 @@ static int bmg160_data_rdy_trigger_set_state(struct iio_trigger *trig,
871 else 894 else
872 ret = bmg160_setup_new_data_interrupt(data, state); 895 ret = bmg160_setup_new_data_interrupt(data, state);
873 if (ret < 0) { 896 if (ret < 0) {
897 bmg160_set_power_state(data, false);
874 mutex_unlock(&data->mutex); 898 mutex_unlock(&data->mutex);
875 return ret; 899 return ret;
876 } 900 }
@@ -908,10 +932,24 @@ static irqreturn_t bmg160_event_handler(int irq, void *private)
908 else 932 else
909 dir = IIO_EV_DIR_FALLING; 933 dir = IIO_EV_DIR_FALLING;
910 934
911 if (ret & BMG160_ANY_MOTION_MASK) 935 if (ret & BMG160_ANY_MOTION_BIT_X)
912 iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL, 936 iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL,
913 0, 937 0,
914 IIO_MOD_X_OR_Y_OR_Z, 938 IIO_MOD_X,
939 IIO_EV_TYPE_ROC,
940 dir),
941 data->timestamp);
942 if (ret & BMG160_ANY_MOTION_BIT_Y)
943 iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL,
944 0,
945 IIO_MOD_Y,
946 IIO_EV_TYPE_ROC,
947 dir),
948 data->timestamp);
949 if (ret & BMG160_ANY_MOTION_BIT_Z)
950 iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL,
951 0,
952 IIO_MOD_Z,
915 IIO_EV_TYPE_ROC, 953 IIO_EV_TYPE_ROC,
916 dir), 954 dir),
917 data->timestamp); 955 data->timestamp);
@@ -1169,8 +1207,15 @@ static int bmg160_runtime_suspend(struct device *dev)
1169{ 1207{
1170 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); 1208 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
1171 struct bmg160_data *data = iio_priv(indio_dev); 1209 struct bmg160_data *data = iio_priv(indio_dev);
1210 int ret;
1211
1212 ret = bmg160_set_mode(data, BMG160_MODE_SUSPEND);
1213 if (ret < 0) {
1214 dev_err(&data->client->dev, "set mode failed\n");
1215 return -EAGAIN;
1216 }
1172 1217
1173 return bmg160_set_mode(data, BMG160_MODE_SUSPEND); 1218 return 0;
1174} 1219}
1175 1220
1176static int bmg160_runtime_resume(struct device *dev) 1221static int bmg160_runtime_resume(struct device *dev)
diff --git a/drivers/infiniband/ulp/isert/ib_isert.c b/drivers/infiniband/ulp/isert/ib_isert.c
index 3effa931fce2..10641b7816f4 100644
--- a/drivers/infiniband/ulp/isert/ib_isert.c
+++ b/drivers/infiniband/ulp/isert/ib_isert.c
@@ -115,9 +115,12 @@ isert_conn_setup_qp(struct isert_conn *isert_conn, struct rdma_cm_id *cma_id,
115 attr.cap.max_recv_wr = ISERT_QP_MAX_RECV_DTOS; 115 attr.cap.max_recv_wr = ISERT_QP_MAX_RECV_DTOS;
116 /* 116 /*
117 * FIXME: Use devattr.max_sge - 2 for max_send_sge as 117 * FIXME: Use devattr.max_sge - 2 for max_send_sge as
118 * work-around for RDMA_READ.. 118 * work-around for RDMA_READs with ConnectX-2.
119 *
120 * Also, still make sure to have at least two SGEs for
121 * outgoing control PDU responses.
119 */ 122 */
120 attr.cap.max_send_sge = device->dev_attr.max_sge - 2; 123 attr.cap.max_send_sge = max(2, device->dev_attr.max_sge - 2);
121 isert_conn->max_sge = attr.cap.max_send_sge; 124 isert_conn->max_sge = attr.cap.max_send_sge;
122 125
123 attr.cap.max_recv_sge = 1; 126 attr.cap.max_recv_sge = 1;
@@ -225,12 +228,16 @@ isert_create_device_ib_res(struct isert_device *device)
225 struct isert_cq_desc *cq_desc; 228 struct isert_cq_desc *cq_desc;
226 struct ib_device_attr *dev_attr; 229 struct ib_device_attr *dev_attr;
227 int ret = 0, i, j; 230 int ret = 0, i, j;
231 int max_rx_cqe, max_tx_cqe;
228 232
229 dev_attr = &device->dev_attr; 233 dev_attr = &device->dev_attr;
230 ret = isert_query_device(ib_dev, dev_attr); 234 ret = isert_query_device(ib_dev, dev_attr);
231 if (ret) 235 if (ret)
232 return ret; 236 return ret;
233 237
238 max_rx_cqe = min(ISER_MAX_RX_CQ_LEN, dev_attr->max_cqe);
239 max_tx_cqe = min(ISER_MAX_TX_CQ_LEN, dev_attr->max_cqe);
240
234 /* asign function handlers */ 241 /* asign function handlers */
235 if (dev_attr->device_cap_flags & IB_DEVICE_MEM_MGT_EXTENSIONS && 242 if (dev_attr->device_cap_flags & IB_DEVICE_MEM_MGT_EXTENSIONS &&
236 dev_attr->device_cap_flags & IB_DEVICE_SIGNATURE_HANDOVER) { 243 dev_attr->device_cap_flags & IB_DEVICE_SIGNATURE_HANDOVER) {
@@ -272,7 +279,7 @@ isert_create_device_ib_res(struct isert_device *device)
272 isert_cq_rx_callback, 279 isert_cq_rx_callback,
273 isert_cq_event_callback, 280 isert_cq_event_callback,
274 (void *)&cq_desc[i], 281 (void *)&cq_desc[i],
275 ISER_MAX_RX_CQ_LEN, i); 282 max_rx_cqe, i);
276 if (IS_ERR(device->dev_rx_cq[i])) { 283 if (IS_ERR(device->dev_rx_cq[i])) {
277 ret = PTR_ERR(device->dev_rx_cq[i]); 284 ret = PTR_ERR(device->dev_rx_cq[i]);
278 device->dev_rx_cq[i] = NULL; 285 device->dev_rx_cq[i] = NULL;
@@ -284,7 +291,7 @@ isert_create_device_ib_res(struct isert_device *device)
284 isert_cq_tx_callback, 291 isert_cq_tx_callback,
285 isert_cq_event_callback, 292 isert_cq_event_callback,
286 (void *)&cq_desc[i], 293 (void *)&cq_desc[i],
287 ISER_MAX_TX_CQ_LEN, i); 294 max_tx_cqe, i);
288 if (IS_ERR(device->dev_tx_cq[i])) { 295 if (IS_ERR(device->dev_tx_cq[i])) {
289 ret = PTR_ERR(device->dev_tx_cq[i]); 296 ret = PTR_ERR(device->dev_tx_cq[i]);
290 device->dev_tx_cq[i] = NULL; 297 device->dev_tx_cq[i] = NULL;
@@ -803,14 +810,25 @@ wake_up:
803 complete(&isert_conn->conn_wait); 810 complete(&isert_conn->conn_wait);
804} 811}
805 812
806static void 813static int
807isert_disconnected_handler(struct rdma_cm_id *cma_id, bool disconnect) 814isert_disconnected_handler(struct rdma_cm_id *cma_id, bool disconnect)
808{ 815{
809 struct isert_conn *isert_conn = (struct isert_conn *)cma_id->context; 816 struct isert_conn *isert_conn;
817
818 if (!cma_id->qp) {
819 struct isert_np *isert_np = cma_id->context;
820
821 isert_np->np_cm_id = NULL;
822 return -1;
823 }
824
825 isert_conn = (struct isert_conn *)cma_id->context;
810 826
811 isert_conn->disconnect = disconnect; 827 isert_conn->disconnect = disconnect;
812 INIT_WORK(&isert_conn->conn_logout_work, isert_disconnect_work); 828 INIT_WORK(&isert_conn->conn_logout_work, isert_disconnect_work);
813 schedule_work(&isert_conn->conn_logout_work); 829 schedule_work(&isert_conn->conn_logout_work);
830
831 return 0;
814} 832}
815 833
816static int 834static int
@@ -825,6 +843,9 @@ isert_cma_handler(struct rdma_cm_id *cma_id, struct rdma_cm_event *event)
825 switch (event->event) { 843 switch (event->event) {
826 case RDMA_CM_EVENT_CONNECT_REQUEST: 844 case RDMA_CM_EVENT_CONNECT_REQUEST:
827 ret = isert_connect_request(cma_id, event); 845 ret = isert_connect_request(cma_id, event);
846 if (ret)
847 pr_err("isert_cma_handler failed RDMA_CM_EVENT: 0x%08x %d\n",
848 event->event, ret);
828 break; 849 break;
829 case RDMA_CM_EVENT_ESTABLISHED: 850 case RDMA_CM_EVENT_ESTABLISHED:
830 isert_connected_handler(cma_id); 851 isert_connected_handler(cma_id);
@@ -834,7 +855,7 @@ isert_cma_handler(struct rdma_cm_id *cma_id, struct rdma_cm_event *event)
834 case RDMA_CM_EVENT_DEVICE_REMOVAL: /* FALLTHRU */ 855 case RDMA_CM_EVENT_DEVICE_REMOVAL: /* FALLTHRU */
835 disconnect = true; 856 disconnect = true;
836 case RDMA_CM_EVENT_TIMEWAIT_EXIT: /* FALLTHRU */ 857 case RDMA_CM_EVENT_TIMEWAIT_EXIT: /* FALLTHRU */
837 isert_disconnected_handler(cma_id, disconnect); 858 ret = isert_disconnected_handler(cma_id, disconnect);
838 break; 859 break;
839 case RDMA_CM_EVENT_CONNECT_ERROR: 860 case RDMA_CM_EVENT_CONNECT_ERROR:
840 default: 861 default:
@@ -842,12 +863,6 @@ isert_cma_handler(struct rdma_cm_id *cma_id, struct rdma_cm_event *event)
842 break; 863 break;
843 } 864 }
844 865
845 if (ret != 0) {
846 pr_err("isert_cma_handler failed RDMA_CM_EVENT: 0x%08x %d\n",
847 event->event, ret);
848 dump_stack();
849 }
850
851 return ret; 866 return ret;
852} 867}
853 868
@@ -3190,7 +3205,8 @@ isert_free_np(struct iscsi_np *np)
3190{ 3205{
3191 struct isert_np *isert_np = (struct isert_np *)np->np_context; 3206 struct isert_np *isert_np = (struct isert_np *)np->np_context;
3192 3207
3193 rdma_destroy_id(isert_np->np_cm_id); 3208 if (isert_np->np_cm_id)
3209 rdma_destroy_id(isert_np->np_cm_id);
3194 3210
3195 np->np_context = NULL; 3211 np->np_context = NULL;
3196 kfree(isert_np); 3212 kfree(isert_np);
diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
index 7206547c13ce..dc829682701a 100644
--- a/drivers/infiniband/ulp/srpt/ib_srpt.c
+++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
@@ -2092,6 +2092,7 @@ static int srpt_create_ch_ib(struct srpt_rdma_ch *ch)
2092 if (!qp_init) 2092 if (!qp_init)
2093 goto out; 2093 goto out;
2094 2094
2095retry:
2095 ch->cq = ib_create_cq(sdev->device, srpt_completion, NULL, ch, 2096 ch->cq = ib_create_cq(sdev->device, srpt_completion, NULL, ch,
2096 ch->rq_size + srp_sq_size, 0); 2097 ch->rq_size + srp_sq_size, 0);
2097 if (IS_ERR(ch->cq)) { 2098 if (IS_ERR(ch->cq)) {
@@ -2115,6 +2116,13 @@ static int srpt_create_ch_ib(struct srpt_rdma_ch *ch)
2115 ch->qp = ib_create_qp(sdev->pd, qp_init); 2116 ch->qp = ib_create_qp(sdev->pd, qp_init);
2116 if (IS_ERR(ch->qp)) { 2117 if (IS_ERR(ch->qp)) {
2117 ret = PTR_ERR(ch->qp); 2118 ret = PTR_ERR(ch->qp);
2119 if (ret == -ENOMEM) {
2120 srp_sq_size /= 2;
2121 if (srp_sq_size >= MIN_SRPT_SQ_SIZE) {
2122 ib_destroy_cq(ch->cq);
2123 goto retry;
2124 }
2125 }
2118 printk(KERN_ERR "failed to create_qp ret= %d\n", ret); 2126 printk(KERN_ERR "failed to create_qp ret= %d\n", ret);
2119 goto err_destroy_cq; 2127 goto err_destroy_cq;
2120 } 2128 }
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index bc203485716d..8afa28e4570e 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -421,7 +421,7 @@ static int evdev_open(struct inode *inode, struct file *file)
421 421
422 err_free_client: 422 err_free_client:
423 evdev_detach_client(evdev, client); 423 evdev_detach_client(evdev, client);
424 kfree(client); 424 kvfree(client);
425 return error; 425 return error;
426} 426}
427 427
diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
index 2ed7905a068f..fc55f0d15b70 100644
--- a/drivers/input/joystick/xpad.c
+++ b/drivers/input/joystick/xpad.c
@@ -1179,9 +1179,19 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
1179 } 1179 }
1180 1180
1181 ep_irq_in = &intf->cur_altsetting->endpoint[1].desc; 1181 ep_irq_in = &intf->cur_altsetting->endpoint[1].desc;
1182 usb_fill_bulk_urb(xpad->bulk_out, udev, 1182 if (usb_endpoint_is_bulk_out(ep_irq_in)) {
1183 usb_sndbulkpipe(udev, ep_irq_in->bEndpointAddress), 1183 usb_fill_bulk_urb(xpad->bulk_out, udev,
1184 xpad->bdata, XPAD_PKT_LEN, xpad_bulk_out, xpad); 1184 usb_sndbulkpipe(udev,
1185 ep_irq_in->bEndpointAddress),
1186 xpad->bdata, XPAD_PKT_LEN,
1187 xpad_bulk_out, xpad);
1188 } else {
1189 usb_fill_int_urb(xpad->bulk_out, udev,
1190 usb_sndintpipe(udev,
1191 ep_irq_in->bEndpointAddress),
1192 xpad->bdata, XPAD_PKT_LEN,
1193 xpad_bulk_out, xpad, 0);
1194 }
1185 1195
1186 /* 1196 /*
1187 * Submit the int URB immediately rather than waiting for open 1197 * Submit the int URB immediately rather than waiting for open
diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c
index 432d36395f35..c9c1c8ca7267 100644
--- a/drivers/input/keyboard/gpio_keys_polled.c
+++ b/drivers/input/keyboard/gpio_keys_polled.c
@@ -23,10 +23,9 @@
23#include <linux/ioport.h> 23#include <linux/ioport.h>
24#include <linux/platform_device.h> 24#include <linux/platform_device.h>
25#include <linux/gpio.h> 25#include <linux/gpio.h>
26#include <linux/gpio/consumer.h>
26#include <linux/gpio_keys.h> 27#include <linux/gpio_keys.h>
27#include <linux/of.h> 28#include <linux/property.h>
28#include <linux/of_platform.h>
29#include <linux/of_gpio.h>
30 29
31#define DRV_NAME "gpio-keys-polled" 30#define DRV_NAME "gpio-keys-polled"
32 31
@@ -51,15 +50,14 @@ static void gpio_keys_polled_check_state(struct input_dev *input,
51 int state; 50 int state;
52 51
53 if (bdata->can_sleep) 52 if (bdata->can_sleep)
54 state = !!gpio_get_value_cansleep(button->gpio); 53 state = !!gpiod_get_value_cansleep(button->gpiod);
55 else 54 else
56 state = !!gpio_get_value(button->gpio); 55 state = !!gpiod_get_value(button->gpiod);
57 56
58 if (state != bdata->last_state) { 57 if (state != bdata->last_state) {
59 unsigned int type = button->type ?: EV_KEY; 58 unsigned int type = button->type ?: EV_KEY;
60 59
61 input_event(input, type, button->code, 60 input_event(input, type, button->code, state);
62 !!(state ^ button->active_low));
63 input_sync(input); 61 input_sync(input);
64 bdata->count = 0; 62 bdata->count = 0;
65 bdata->last_state = state; 63 bdata->last_state = state;
@@ -102,21 +100,15 @@ static void gpio_keys_polled_close(struct input_polled_dev *dev)
102 pdata->disable(bdev->dev); 100 pdata->disable(bdev->dev);
103} 101}
104 102
105#ifdef CONFIG_OF
106static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct device *dev) 103static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct device *dev)
107{ 104{
108 struct device_node *node, *pp;
109 struct gpio_keys_platform_data *pdata; 105 struct gpio_keys_platform_data *pdata;
110 struct gpio_keys_button *button; 106 struct gpio_keys_button *button;
107 struct fwnode_handle *child;
111 int error; 108 int error;
112 int nbuttons; 109 int nbuttons;
113 int i;
114
115 node = dev->of_node;
116 if (!node)
117 return NULL;
118 110
119 nbuttons = of_get_child_count(node); 111 nbuttons = device_get_child_node_count(dev);
120 if (nbuttons == 0) 112 if (nbuttons == 0)
121 return NULL; 113 return NULL;
122 114
@@ -126,52 +118,44 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct
126 return ERR_PTR(-ENOMEM); 118 return ERR_PTR(-ENOMEM);
127 119
128 pdata->buttons = (struct gpio_keys_button *)(pdata + 1); 120 pdata->buttons = (struct gpio_keys_button *)(pdata + 1);
129 pdata->nbuttons = nbuttons;
130 121
131 pdata->rep = !!of_get_property(node, "autorepeat", NULL); 122 pdata->rep = device_property_present(dev, "autorepeat");
132 of_property_read_u32(node, "poll-interval", &pdata->poll_interval); 123 device_property_read_u32(dev, "poll-interval", &pdata->poll_interval);
133 124
134 i = 0; 125 device_for_each_child_node(dev, child) {
135 for_each_child_of_node(node, pp) { 126 struct gpio_desc *desc;
136 int gpio;
137 enum of_gpio_flags flags;
138 127
139 if (!of_find_property(pp, "gpios", NULL)) { 128 desc = devm_get_gpiod_from_child(dev, child);
140 pdata->nbuttons--; 129 if (IS_ERR(desc)) {
141 dev_warn(dev, "Found button without gpios\n"); 130 error = PTR_ERR(desc);
142 continue;
143 }
144
145 gpio = of_get_gpio_flags(pp, 0, &flags);
146 if (gpio < 0) {
147 error = gpio;
148 if (error != -EPROBE_DEFER) 131 if (error != -EPROBE_DEFER)
149 dev_err(dev, 132 dev_err(dev,
150 "Failed to get gpio flags, error: %d\n", 133 "Failed to get gpio flags, error: %d\n",
151 error); 134 error);
135 fwnode_handle_put(child);
152 return ERR_PTR(error); 136 return ERR_PTR(error);
153 } 137 }
154 138
155 button = &pdata->buttons[i++]; 139 button = &pdata->buttons[pdata->nbuttons++];
156 140 button->gpiod = desc;
157 button->gpio = gpio;
158 button->active_low = flags & OF_GPIO_ACTIVE_LOW;
159 141
160 if (of_property_read_u32(pp, "linux,code", &button->code)) { 142 if (fwnode_property_read_u32(child, "linux,code", &button->code)) {
161 dev_err(dev, "Button without keycode: 0x%x\n", 143 dev_err(dev, "Button without keycode: %d\n",
162 button->gpio); 144 pdata->nbuttons - 1);
145 fwnode_handle_put(child);
163 return ERR_PTR(-EINVAL); 146 return ERR_PTR(-EINVAL);
164 } 147 }
165 148
166 button->desc = of_get_property(pp, "label", NULL); 149 fwnode_property_read_string(child, "label", &button->desc);
167 150
168 if (of_property_read_u32(pp, "linux,input-type", &button->type)) 151 if (fwnode_property_read_u32(child, "linux,input-type",
152 &button->type))
169 button->type = EV_KEY; 153 button->type = EV_KEY;
170 154
171 button->wakeup = !!of_get_property(pp, "gpio-key,wakeup", NULL); 155 button->wakeup = fwnode_property_present(child, "gpio-key,wakeup");
172 156
173 if (of_property_read_u32(pp, "debounce-interval", 157 if (fwnode_property_read_u32(child, "debounce-interval",
174 &button->debounce_interval)) 158 &button->debounce_interval))
175 button->debounce_interval = 5; 159 button->debounce_interval = 5;
176 } 160 }
177 161
@@ -187,15 +171,6 @@ static const struct of_device_id gpio_keys_polled_of_match[] = {
187}; 171};
188MODULE_DEVICE_TABLE(of, gpio_keys_polled_of_match); 172MODULE_DEVICE_TABLE(of, gpio_keys_polled_of_match);
189 173
190#else
191
192static inline struct gpio_keys_platform_data *
193gpio_keys_polled_get_devtree_pdata(struct device *dev)
194{
195 return NULL;
196}
197#endif
198
199static int gpio_keys_polled_probe(struct platform_device *pdev) 174static int gpio_keys_polled_probe(struct platform_device *pdev)
200{ 175{
201 struct device *dev = &pdev->dev; 176 struct device *dev = &pdev->dev;
@@ -259,7 +234,6 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
259 for (i = 0; i < pdata->nbuttons; i++) { 234 for (i = 0; i < pdata->nbuttons; i++) {
260 struct gpio_keys_button *button = &pdata->buttons[i]; 235 struct gpio_keys_button *button = &pdata->buttons[i];
261 struct gpio_keys_button_data *bdata = &bdev->data[i]; 236 struct gpio_keys_button_data *bdata = &bdev->data[i];
262 unsigned int gpio = button->gpio;
263 unsigned int type = button->type ?: EV_KEY; 237 unsigned int type = button->type ?: EV_KEY;
264 238
265 if (button->wakeup) { 239 if (button->wakeup) {
@@ -267,15 +241,31 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
267 return -EINVAL; 241 return -EINVAL;
268 } 242 }
269 243
270 error = devm_gpio_request_one(&pdev->dev, gpio, GPIOF_IN, 244 /*
271 button->desc ? : DRV_NAME); 245 * Legacy GPIO number so request the GPIO here and
272 if (error) { 246 * convert it to descriptor.
273 dev_err(dev, "unable to claim gpio %u, err=%d\n", 247 */
274 gpio, error); 248 if (!button->gpiod && gpio_is_valid(button->gpio)) {
275 return error; 249 unsigned flags = 0;
250
251 if (button->active_low)
252 flags |= GPIOF_ACTIVE_LOW;
253
254 error = devm_gpio_request_one(&pdev->dev, button->gpio,
255 flags, button->desc ? : DRV_NAME);
256 if (error) {
257 dev_err(dev, "unable to claim gpio %u, err=%d\n",
258 button->gpio, error);
259 return error;
260 }
261
262 button->gpiod = gpio_to_desc(button->gpio);
276 } 263 }
277 264
278 bdata->can_sleep = gpio_cansleep(gpio); 265 if (IS_ERR(button->gpiod))
266 return PTR_ERR(button->gpiod);
267
268 bdata->can_sleep = gpiod_cansleep(button->gpiod);
279 bdata->last_state = -1; 269 bdata->last_state = -1;
280 bdata->threshold = DIV_ROUND_UP(button->debounce_interval, 270 bdata->threshold = DIV_ROUND_UP(button->debounce_interval,
281 pdata->poll_interval); 271 pdata->poll_interval);
@@ -308,7 +298,7 @@ static struct platform_driver gpio_keys_polled_driver = {
308 .driver = { 298 .driver = {
309 .name = DRV_NAME, 299 .name = DRV_NAME,
310 .owner = THIS_MODULE, 300 .owner = THIS_MODULE,
311 .of_match_table = of_match_ptr(gpio_keys_polled_of_match), 301 .of_match_table = gpio_keys_polled_of_match,
312 }, 302 },
313}; 303};
314module_platform_driver(gpio_keys_polled_driver); 304module_platform_driver(gpio_keys_polled_driver);
diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c
index 3fcb6b3cb0bd..f2b978026407 100644
--- a/drivers/input/mouse/elantech.c
+++ b/drivers/input/mouse/elantech.c
@@ -428,14 +428,6 @@ static void elantech_report_trackpoint(struct psmouse *psmouse,
428 int x, y; 428 int x, y;
429 u32 t; 429 u32 t;
430 430
431 if (dev_WARN_ONCE(&psmouse->ps2dev.serio->dev,
432 !tp_dev,
433 psmouse_fmt("Unexpected trackpoint message\n"))) {
434 if (etd->debug == 1)
435 elantech_packet_dump(psmouse);
436 return;
437 }
438
439 t = get_unaligned_le32(&packet[0]); 431 t = get_unaligned_le32(&packet[0]);
440 432
441 switch (t & ~7U) { 433 switch (t & ~7U) {
@@ -793,7 +785,7 @@ static int elantech_packet_check_v4(struct psmouse *psmouse)
793 unsigned char packet_type = packet[3] & 0x03; 785 unsigned char packet_type = packet[3] & 0x03;
794 bool sanity_check; 786 bool sanity_check;
795 787
796 if ((packet[3] & 0x0f) == 0x06) 788 if (etd->tp_dev && (packet[3] & 0x0f) == 0x06)
797 return PACKET_TRACKPOINT; 789 return PACKET_TRACKPOINT;
798 790
799 /* 791 /*
diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
index 2a7a9174c702..f9472920d986 100644
--- a/drivers/input/mouse/synaptics.c
+++ b/drivers/input/mouse/synaptics.c
@@ -143,6 +143,10 @@ static const struct min_max_quirk min_max_pnpid_table[] = {
143 (const char * const []){"LEN2001", NULL}, 143 (const char * const []){"LEN2001", NULL},
144 1024, 5022, 2508, 4832 144 1024, 5022, 2508, 4832
145 }, 145 },
146 {
147 (const char * const []){"LEN2006", NULL},
148 1264, 5675, 1171, 4688
149 },
146 { } 150 { }
147}; 151};
148 152
diff --git a/drivers/irqchip/irq-atmel-aic-common.c b/drivers/irqchip/irq-atmel-aic-common.c
index 6ae3cdee0681..cc4f9d80122e 100644
--- a/drivers/irqchip/irq-atmel-aic-common.c
+++ b/drivers/irqchip/irq-atmel-aic-common.c
@@ -217,8 +217,9 @@ struct irq_domain *__init aic_common_of_init(struct device_node *node,
217 } 217 }
218 218
219 ret = irq_alloc_domain_generic_chips(domain, 32, 1, name, 219 ret = irq_alloc_domain_generic_chips(domain, 32, 1, name,
220 handle_level_irq, 0, 0, 220 handle_fasteoi_irq,
221 IRQCHIP_SKIP_SET_WAKE); 221 IRQ_NOREQUEST | IRQ_NOPROBE |
222 IRQ_NOAUTOEN, 0, 0);
222 if (ret) 223 if (ret)
223 goto err_domain_remove; 224 goto err_domain_remove;
224 225
@@ -230,7 +231,6 @@ struct irq_domain *__init aic_common_of_init(struct device_node *node,
230 gc->unused = 0; 231 gc->unused = 0;
231 gc->wake_enabled = ~0; 232 gc->wake_enabled = ~0;
232 gc->chip_types[0].type = IRQ_TYPE_SENSE_MASK; 233 gc->chip_types[0].type = IRQ_TYPE_SENSE_MASK;
233 gc->chip_types[0].handler = handle_fasteoi_irq;
234 gc->chip_types[0].chip.irq_eoi = irq_gc_eoi; 234 gc->chip_types[0].chip.irq_eoi = irq_gc_eoi;
235 gc->chip_types[0].chip.irq_set_wake = irq_gc_set_wake; 235 gc->chip_types[0].chip.irq_set_wake = irq_gc_set_wake;
236 gc->chip_types[0].chip.irq_shutdown = aic_common_shutdown; 236 gc->chip_types[0].chip.irq_shutdown = aic_common_shutdown;
diff --git a/drivers/irqchip/irq-bcm7120-l2.c b/drivers/irqchip/irq-bcm7120-l2.c
index b9f4fb808e49..5fb38a2ac226 100644
--- a/drivers/irqchip/irq-bcm7120-l2.c
+++ b/drivers/irqchip/irq-bcm7120-l2.c
@@ -101,9 +101,9 @@ static int bcm7120_l2_intc_init_one(struct device_node *dn,
101 int parent_irq; 101 int parent_irq;
102 102
103 parent_irq = irq_of_parse_and_map(dn, irq); 103 parent_irq = irq_of_parse_and_map(dn, irq);
104 if (parent_irq < 0) { 104 if (!parent_irq) {
105 pr_err("failed to map interrupt %d\n", irq); 105 pr_err("failed to map interrupt %d\n", irq);
106 return parent_irq; 106 return -EINVAL;
107 } 107 }
108 108
109 data->irq_map_mask |= be32_to_cpup(map_mask + irq); 109 data->irq_map_mask |= be32_to_cpup(map_mask + irq);
diff --git a/drivers/irqchip/irq-brcmstb-l2.c b/drivers/irqchip/irq-brcmstb-l2.c
index c15c840987d2..14691a4cb84c 100644
--- a/drivers/irqchip/irq-brcmstb-l2.c
+++ b/drivers/irqchip/irq-brcmstb-l2.c
@@ -135,9 +135,9 @@ int __init brcmstb_l2_intc_of_init(struct device_node *np,
135 __raw_writel(0xffffffff, data->base + CPU_CLEAR); 135 __raw_writel(0xffffffff, data->base + CPU_CLEAR);
136 136
137 data->parent_irq = irq_of_parse_and_map(np, 0); 137 data->parent_irq = irq_of_parse_and_map(np, 0);
138 if (data->parent_irq < 0) { 138 if (!data->parent_irq) {
139 pr_err("failed to find parent interrupt\n"); 139 pr_err("failed to find parent interrupt\n");
140 ret = data->parent_irq; 140 ret = -EINVAL;
141 goto out_unmap; 141 goto out_unmap;
142 } 142 }
143 143
diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index b4518c8751c8..868e6fc17cba 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -12,25 +12,23 @@
12 */ 12 */
13#include <linux/err.h> 13#include <linux/err.h>
14#include <linux/gpio.h> 14#include <linux/gpio.h>
15#include <linux/gpio/consumer.h>
15#include <linux/kernel.h> 16#include <linux/kernel.h>
16#include <linux/leds.h> 17#include <linux/leds.h>
17#include <linux/module.h> 18#include <linux/module.h>
18#include <linux/of.h>
19#include <linux/of_gpio.h>
20#include <linux/of_platform.h>
21#include <linux/platform_device.h> 19#include <linux/platform_device.h>
20#include <linux/property.h>
22#include <linux/slab.h> 21#include <linux/slab.h>
23#include <linux/workqueue.h> 22#include <linux/workqueue.h>
24 23
25struct gpio_led_data { 24struct gpio_led_data {
26 struct led_classdev cdev; 25 struct led_classdev cdev;
27 unsigned gpio; 26 struct gpio_desc *gpiod;
28 struct work_struct work; 27 struct work_struct work;
29 u8 new_level; 28 u8 new_level;
30 u8 can_sleep; 29 u8 can_sleep;
31 u8 active_low;
32 u8 blinking; 30 u8 blinking;
33 int (*platform_gpio_blink_set)(unsigned gpio, int state, 31 int (*platform_gpio_blink_set)(struct gpio_desc *desc, int state,
34 unsigned long *delay_on, unsigned long *delay_off); 32 unsigned long *delay_on, unsigned long *delay_off);
35}; 33};
36 34
@@ -40,12 +38,11 @@ static void gpio_led_work(struct work_struct *work)
40 container_of(work, struct gpio_led_data, work); 38 container_of(work, struct gpio_led_data, work);
41 39
42 if (led_dat->blinking) { 40 if (led_dat->blinking) {
43 led_dat->platform_gpio_blink_set(led_dat->gpio, 41 led_dat->platform_gpio_blink_set(led_dat->gpiod,
44 led_dat->new_level, 42 led_dat->new_level, NULL, NULL);
45 NULL, NULL);
46 led_dat->blinking = 0; 43 led_dat->blinking = 0;
47 } else 44 } else
48 gpio_set_value_cansleep(led_dat->gpio, led_dat->new_level); 45 gpiod_set_value_cansleep(led_dat->gpiod, led_dat->new_level);
49} 46}
50 47
51static void gpio_led_set(struct led_classdev *led_cdev, 48static void gpio_led_set(struct led_classdev *led_cdev,
@@ -60,9 +57,6 @@ static void gpio_led_set(struct led_classdev *led_cdev,
60 else 57 else
61 level = 1; 58 level = 1;
62 59
63 if (led_dat->active_low)
64 level = !level;
65
66 /* Setting GPIOs with I2C/etc requires a task context, and we don't 60 /* Setting GPIOs with I2C/etc requires a task context, and we don't
67 * seem to have a reliable way to know if we're already in one; so 61 * seem to have a reliable way to know if we're already in one; so
68 * let's just assume the worst. 62 * let's just assume the worst.
@@ -72,11 +66,11 @@ static void gpio_led_set(struct led_classdev *led_cdev,
72 schedule_work(&led_dat->work); 66 schedule_work(&led_dat->work);
73 } else { 67 } else {
74 if (led_dat->blinking) { 68 if (led_dat->blinking) {
75 led_dat->platform_gpio_blink_set(led_dat->gpio, level, 69 led_dat->platform_gpio_blink_set(led_dat->gpiod, level,
76 NULL, NULL); 70 NULL, NULL);
77 led_dat->blinking = 0; 71 led_dat->blinking = 0;
78 } else 72 } else
79 gpio_set_value(led_dat->gpio, level); 73 gpiod_set_value(led_dat->gpiod, level);
80 } 74 }
81} 75}
82 76
@@ -87,34 +81,49 @@ static int gpio_blink_set(struct led_classdev *led_cdev,
87 container_of(led_cdev, struct gpio_led_data, cdev); 81 container_of(led_cdev, struct gpio_led_data, cdev);
88 82
89 led_dat->blinking = 1; 83 led_dat->blinking = 1;
90 return led_dat->platform_gpio_blink_set(led_dat->gpio, GPIO_LED_BLINK, 84 return led_dat->platform_gpio_blink_set(led_dat->gpiod, GPIO_LED_BLINK,
91 delay_on, delay_off); 85 delay_on, delay_off);
92} 86}
93 87
94static int create_gpio_led(const struct gpio_led *template, 88static int create_gpio_led(const struct gpio_led *template,
95 struct gpio_led_data *led_dat, struct device *parent, 89 struct gpio_led_data *led_dat, struct device *parent,
96 int (*blink_set)(unsigned, int, unsigned long *, unsigned long *)) 90 int (*blink_set)(struct gpio_desc *, int, unsigned long *,
91 unsigned long *))
97{ 92{
98 int ret, state; 93 int ret, state;
99 94
100 led_dat->gpio = -1; 95 led_dat->gpiod = template->gpiod;
96 if (!led_dat->gpiod) {
97 /*
98 * This is the legacy code path for platform code that
99 * still uses GPIO numbers. Ultimately we would like to get
100 * rid of this block completely.
101 */
102 unsigned long flags = 0;
103
104 /* skip leds that aren't available */
105 if (!gpio_is_valid(template->gpio)) {
106 dev_info(parent, "Skipping unavailable LED gpio %d (%s)\n",
107 template->gpio, template->name);
108 return 0;
109 }
101 110
102 /* skip leds that aren't available */ 111 if (template->active_low)
103 if (!gpio_is_valid(template->gpio)) { 112 flags |= GPIOF_ACTIVE_LOW;
104 dev_info(parent, "Skipping unavailable LED gpio %d (%s)\n",
105 template->gpio, template->name);
106 return 0;
107 }
108 113
109 ret = devm_gpio_request(parent, template->gpio, template->name); 114 ret = devm_gpio_request_one(parent, template->gpio, flags,
110 if (ret < 0) 115 template->name);
111 return ret; 116 if (ret < 0)
117 return ret;
118
119 led_dat->gpiod = gpio_to_desc(template->gpio);
120 if (IS_ERR(led_dat->gpiod))
121 return PTR_ERR(led_dat->gpiod);
122 }
112 123
113 led_dat->cdev.name = template->name; 124 led_dat->cdev.name = template->name;
114 led_dat->cdev.default_trigger = template->default_trigger; 125 led_dat->cdev.default_trigger = template->default_trigger;
115 led_dat->gpio = template->gpio; 126 led_dat->can_sleep = gpiod_cansleep(led_dat->gpiod);
116 led_dat->can_sleep = gpio_cansleep(template->gpio);
117 led_dat->active_low = template->active_low;
118 led_dat->blinking = 0; 127 led_dat->blinking = 0;
119 if (blink_set) { 128 if (blink_set) {
120 led_dat->platform_gpio_blink_set = blink_set; 129 led_dat->platform_gpio_blink_set = blink_set;
@@ -122,30 +131,24 @@ static int create_gpio_led(const struct gpio_led *template,
122 } 131 }
123 led_dat->cdev.brightness_set = gpio_led_set; 132 led_dat->cdev.brightness_set = gpio_led_set;
124 if (template->default_state == LEDS_GPIO_DEFSTATE_KEEP) 133 if (template->default_state == LEDS_GPIO_DEFSTATE_KEEP)
125 state = !!gpio_get_value_cansleep(led_dat->gpio) ^ led_dat->active_low; 134 state = !!gpiod_get_value_cansleep(led_dat->gpiod);
126 else 135 else
127 state = (template->default_state == LEDS_GPIO_DEFSTATE_ON); 136 state = (template->default_state == LEDS_GPIO_DEFSTATE_ON);
128 led_dat->cdev.brightness = state ? LED_FULL : LED_OFF; 137 led_dat->cdev.brightness = state ? LED_FULL : LED_OFF;
129 if (!template->retain_state_suspended) 138 if (!template->retain_state_suspended)
130 led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME; 139 led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME;
131 140
132 ret = gpio_direction_output(led_dat->gpio, led_dat->active_low ^ state); 141 ret = gpiod_direction_output(led_dat->gpiod, state);
133 if (ret < 0) 142 if (ret < 0)
134 return ret; 143 return ret;
135 144
136 INIT_WORK(&led_dat->work, gpio_led_work); 145 INIT_WORK(&led_dat->work, gpio_led_work);
137 146
138 ret = led_classdev_register(parent, &led_dat->cdev); 147 return led_classdev_register(parent, &led_dat->cdev);
139 if (ret < 0)
140 return ret;
141
142 return 0;
143} 148}
144 149
145static void delete_gpio_led(struct gpio_led_data *led) 150static void delete_gpio_led(struct gpio_led_data *led)
146{ 151{
147 if (!gpio_is_valid(led->gpio))
148 return;
149 led_classdev_unregister(&led->cdev); 152 led_classdev_unregister(&led->cdev);
150 cancel_work_sync(&led->work); 153 cancel_work_sync(&led->work);
151} 154}
@@ -161,40 +164,47 @@ static inline int sizeof_gpio_leds_priv(int num_leds)
161 (sizeof(struct gpio_led_data) * num_leds); 164 (sizeof(struct gpio_led_data) * num_leds);
162} 165}
163 166
164/* Code to create from OpenFirmware platform devices */ 167static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev)
165#ifdef CONFIG_OF_GPIO
166static struct gpio_leds_priv *gpio_leds_create_of(struct platform_device *pdev)
167{ 168{
168 struct device_node *np = pdev->dev.of_node, *child; 169 struct device *dev = &pdev->dev;
170 struct fwnode_handle *child;
169 struct gpio_leds_priv *priv; 171 struct gpio_leds_priv *priv;
170 int count, ret; 172 int count, ret;
173 struct device_node *np;
171 174
172 /* count LEDs in this device, so we know how much to allocate */ 175 count = device_get_child_node_count(dev);
173 count = of_get_available_child_count(np);
174 if (!count) 176 if (!count)
175 return ERR_PTR(-ENODEV); 177 return ERR_PTR(-ENODEV);
176 178
177 for_each_available_child_of_node(np, child) 179 priv = devm_kzalloc(dev, sizeof_gpio_leds_priv(count), GFP_KERNEL);
178 if (of_get_gpio(child, 0) == -EPROBE_DEFER)
179 return ERR_PTR(-EPROBE_DEFER);
180
181 priv = devm_kzalloc(&pdev->dev, sizeof_gpio_leds_priv(count),
182 GFP_KERNEL);
183 if (!priv) 180 if (!priv)
184 return ERR_PTR(-ENOMEM); 181 return ERR_PTR(-ENOMEM);
185 182
186 for_each_available_child_of_node(np, child) { 183 device_for_each_child_node(dev, child) {
187 struct gpio_led led = {}; 184 struct gpio_led led = {};
188 enum of_gpio_flags flags; 185 const char *state = NULL;
189 const char *state; 186
190 187 led.gpiod = devm_get_gpiod_from_child(dev, child);
191 led.gpio = of_get_gpio_flags(child, 0, &flags); 188 if (IS_ERR(led.gpiod)) {
192 led.active_low = flags & OF_GPIO_ACTIVE_LOW; 189 fwnode_handle_put(child);
193 led.name = of_get_property(child, "label", NULL) ? : child->name; 190 goto err;
194 led.default_trigger = 191 }
195 of_get_property(child, "linux,default-trigger", NULL); 192
196 state = of_get_property(child, "default-state", NULL); 193 np = of_node(child);
197 if (state) { 194
195 if (fwnode_property_present(child, "label")) {
196 fwnode_property_read_string(child, "label", &led.name);
197 } else {
198 if (IS_ENABLED(CONFIG_OF) && !led.name && np)
199 led.name = np->name;
200 if (!led.name)
201 return ERR_PTR(-EINVAL);
202 }
203 fwnode_property_read_string(child, "linux,default-trigger",
204 &led.default_trigger);
205
206 if (!fwnode_property_read_string(child, "linux,default_state",
207 &state)) {
198 if (!strcmp(state, "keep")) 208 if (!strcmp(state, "keep"))
199 led.default_state = LEDS_GPIO_DEFSTATE_KEEP; 209 led.default_state = LEDS_GPIO_DEFSTATE_KEEP;
200 else if (!strcmp(state, "on")) 210 else if (!strcmp(state, "on"))
@@ -203,13 +213,13 @@ static struct gpio_leds_priv *gpio_leds_create_of(struct platform_device *pdev)
203 led.default_state = LEDS_GPIO_DEFSTATE_OFF; 213 led.default_state = LEDS_GPIO_DEFSTATE_OFF;
204 } 214 }
205 215
206 if (of_get_property(child, "retain-state-suspended", NULL)) 216 if (fwnode_property_present(child, "retain-state-suspended"))
207 led.retain_state_suspended = 1; 217 led.retain_state_suspended = 1;
208 218
209 ret = create_gpio_led(&led, &priv->leds[priv->num_leds++], 219 ret = create_gpio_led(&led, &priv->leds[priv->num_leds++],
210 &pdev->dev, NULL); 220 dev, NULL);
211 if (ret < 0) { 221 if (ret < 0) {
212 of_node_put(child); 222 fwnode_handle_put(child);
213 goto err; 223 goto err;
214 } 224 }
215 } 225 }
@@ -228,12 +238,6 @@ static const struct of_device_id of_gpio_leds_match[] = {
228}; 238};
229 239
230MODULE_DEVICE_TABLE(of, of_gpio_leds_match); 240MODULE_DEVICE_TABLE(of, of_gpio_leds_match);
231#else /* CONFIG_OF_GPIO */
232static struct gpio_leds_priv *gpio_leds_create_of(struct platform_device *pdev)
233{
234 return ERR_PTR(-ENODEV);
235}
236#endif /* CONFIG_OF_GPIO */
237 241
238static int gpio_led_probe(struct platform_device *pdev) 242static int gpio_led_probe(struct platform_device *pdev)
239{ 243{
@@ -261,7 +265,7 @@ static int gpio_led_probe(struct platform_device *pdev)
261 } 265 }
262 } 266 }
263 } else { 267 } else {
264 priv = gpio_leds_create_of(pdev); 268 priv = gpio_leds_create(pdev);
265 if (IS_ERR(priv)) 269 if (IS_ERR(priv))
266 return PTR_ERR(priv); 270 return PTR_ERR(priv);
267 } 271 }
@@ -288,7 +292,7 @@ static struct platform_driver gpio_led_driver = {
288 .driver = { 292 .driver = {
289 .name = "leds-gpio", 293 .name = "leds-gpio",
290 .owner = THIS_MODULE, 294 .owner = THIS_MODULE,
291 .of_match_table = of_match_ptr(of_gpio_leds_match), 295 .of_match_table = of_gpio_leds_match,
292 }, 296 },
293}; 297};
294 298
diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
index 932ed9be9ff3..b10aaeda2bb4 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -2190,7 +2190,7 @@ static int smiapp_set_selection(struct v4l2_subdev *subdev,
2190 ret = smiapp_set_compose(subdev, fh, sel); 2190 ret = smiapp_set_compose(subdev, fh, sel);
2191 break; 2191 break;
2192 default: 2192 default:
2193 BUG(); 2193 ret = -EINVAL;
2194 } 2194 }
2195 2195
2196 mutex_unlock(&sensor->mutex); 2196 mutex_unlock(&sensor->mutex);
diff --git a/drivers/media/pci/cx23885/cx23885-core.c b/drivers/media/pci/cx23885/cx23885-core.c
index 331eddac7222..3bd386c371f7 100644
--- a/drivers/media/pci/cx23885/cx23885-core.c
+++ b/drivers/media/pci/cx23885/cx23885-core.c
@@ -1078,7 +1078,7 @@ static __le32 *cx23885_risc_field(__le32 *rp, struct scatterlist *sglist,
1078 for (line = 0; line < lines; line++) { 1078 for (line = 0; line < lines; line++) {
1079 while (offset && offset >= sg_dma_len(sg)) { 1079 while (offset && offset >= sg_dma_len(sg)) {
1080 offset -= sg_dma_len(sg); 1080 offset -= sg_dma_len(sg);
1081 sg++; 1081 sg = sg_next(sg);
1082 } 1082 }
1083 1083
1084 if (lpi && line > 0 && !(line % lpi)) 1084 if (lpi && line > 0 && !(line % lpi))
@@ -1101,14 +1101,14 @@ static __le32 *cx23885_risc_field(__le32 *rp, struct scatterlist *sglist,
1101 *(rp++) = cpu_to_le32(0); /* bits 63-32 */ 1101 *(rp++) = cpu_to_le32(0); /* bits 63-32 */
1102 todo -= (sg_dma_len(sg)-offset); 1102 todo -= (sg_dma_len(sg)-offset);
1103 offset = 0; 1103 offset = 0;
1104 sg++; 1104 sg = sg_next(sg);
1105 while (todo > sg_dma_len(sg)) { 1105 while (todo > sg_dma_len(sg)) {
1106 *(rp++) = cpu_to_le32(RISC_WRITE| 1106 *(rp++) = cpu_to_le32(RISC_WRITE|
1107 sg_dma_len(sg)); 1107 sg_dma_len(sg));
1108 *(rp++) = cpu_to_le32(sg_dma_address(sg)); 1108 *(rp++) = cpu_to_le32(sg_dma_address(sg));
1109 *(rp++) = cpu_to_le32(0); /* bits 63-32 */ 1109 *(rp++) = cpu_to_le32(0); /* bits 63-32 */
1110 todo -= sg_dma_len(sg); 1110 todo -= sg_dma_len(sg);
1111 sg++; 1111 sg = sg_next(sg);
1112 } 1112 }
1113 *(rp++) = cpu_to_le32(RISC_WRITE|RISC_EOL|todo); 1113 *(rp++) = cpu_to_le32(RISC_WRITE|RISC_EOL|todo);
1114 *(rp++) = cpu_to_le32(sg_dma_address(sg)); 1114 *(rp++) = cpu_to_le32(sg_dma_address(sg));
diff --git a/drivers/media/pci/solo6x10/solo6x10-core.c b/drivers/media/pci/solo6x10/solo6x10-core.c
index 172583d736fe..8cbe6b49f4c2 100644
--- a/drivers/media/pci/solo6x10/solo6x10-core.c
+++ b/drivers/media/pci/solo6x10/solo6x10-core.c
@@ -105,11 +105,8 @@ static irqreturn_t solo_isr(int irq, void *data)
105 if (!status) 105 if (!status)
106 return IRQ_NONE; 106 return IRQ_NONE;
107 107
108 if (status & ~solo_dev->irq_mask) { 108 /* Acknowledge all interrupts immediately */
109 solo_reg_write(solo_dev, SOLO_IRQ_STAT, 109 solo_reg_write(solo_dev, SOLO_IRQ_STAT, status);
110 status & ~solo_dev->irq_mask);
111 status &= solo_dev->irq_mask;
112 }
113 110
114 if (status & SOLO_IRQ_PCI_ERR) 111 if (status & SOLO_IRQ_PCI_ERR)
115 solo_p2m_error_isr(solo_dev); 112 solo_p2m_error_isr(solo_dev);
@@ -132,9 +129,6 @@ static irqreturn_t solo_isr(int irq, void *data)
132 if (status & SOLO_IRQ_G723) 129 if (status & SOLO_IRQ_G723)
133 solo_g723_isr(solo_dev); 130 solo_g723_isr(solo_dev);
134 131
135 /* Clear all interrupts handled */
136 solo_reg_write(solo_dev, SOLO_IRQ_STAT, status);
137
138 return IRQ_HANDLED; 132 return IRQ_HANDLED;
139} 133}
140 134
diff --git a/drivers/media/rc/ir-rc6-decoder.c b/drivers/media/rc/ir-rc6-decoder.c
index f1f098e22f7e..d16bc67af732 100644
--- a/drivers/media/rc/ir-rc6-decoder.c
+++ b/drivers/media/rc/ir-rc6-decoder.c
@@ -259,8 +259,8 @@ again:
259 case 32: 259 case 32:
260 if ((scancode & RC6_6A_LCC_MASK) == RC6_6A_MCE_CC) { 260 if ((scancode & RC6_6A_LCC_MASK) == RC6_6A_MCE_CC) {
261 protocol = RC_TYPE_RC6_MCE; 261 protocol = RC_TYPE_RC6_MCE;
262 scancode &= ~RC6_6A_MCE_TOGGLE_MASK;
263 toggle = !!(scancode & RC6_6A_MCE_TOGGLE_MASK); 262 toggle = !!(scancode & RC6_6A_MCE_TOGGLE_MASK);
263 scancode &= ~RC6_6A_MCE_TOGGLE_MASK;
264 } else { 264 } else {
265 protocol = RC_BIT_RC6_6A_32; 265 protocol = RC_BIT_RC6_6A_32;
266 toggle = 0; 266 toggle = 0;
diff --git a/drivers/media/usb/s2255/s2255drv.c b/drivers/media/usb/s2255/s2255drv.c
index ccc00099b261..1c0dbf428a3a 100644
--- a/drivers/media/usb/s2255/s2255drv.c
+++ b/drivers/media/usb/s2255/s2255drv.c
@@ -632,7 +632,7 @@ static void s2255_fillbuff(struct s2255_vc *vc,
632 break; 632 break;
633 case V4L2_PIX_FMT_JPEG: 633 case V4L2_PIX_FMT_JPEG:
634 case V4L2_PIX_FMT_MJPEG: 634 case V4L2_PIX_FMT_MJPEG:
635 buf->vb.v4l2_buf.length = jpgsize; 635 vb2_set_plane_payload(&buf->vb, 0, jpgsize);
636 memcpy(vbuf, tmpbuf, jpgsize); 636 memcpy(vbuf, tmpbuf, jpgsize);
637 break; 637 break;
638 case V4L2_PIX_FMT_YUV422P: 638 case V4L2_PIX_FMT_YUV422P:
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 1456ea70bbc7..9af299ba711a 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -74,7 +74,8 @@ config MFD_AXP20X
74 select REGMAP_IRQ 74 select REGMAP_IRQ
75 depends on I2C=y 75 depends on I2C=y
76 help 76 help
77 If you say Y here you get support for the X-Powers AXP202 and AXP209. 77 If you say Y here you get support for the X-Powers AXP202, AXP209 and
78 AXP288 power management IC (PMIC).
78 This driver include only the core APIs. You have to select individual 79 This driver include only the core APIs. You have to select individual
79 components like regulators or the PEK (Power Enable Key) under the 80 components like regulators or the PEK (Power Enable Key) under the
80 corresponding menus. 81 corresponding menus.
diff --git a/drivers/mfd/axp20x.c b/drivers/mfd/axp20x.c
index 6231adbb295d..1df18d188342 100644
--- a/drivers/mfd/axp20x.c
+++ b/drivers/mfd/axp20x.c
@@ -1,9 +1,9 @@
1/* 1/*
2 * axp20x.c - MFD core driver for the X-Powers AXP202 and AXP209 2 * axp20x.c - MFD core driver for the X-Powers' Power Management ICs
3 * 3 *
4 * AXP20x comprises an adaptive USB-Compatible PWM charger, 2 BUCK DC-DC 4 * AXP20x typically comprises an adaptive USB-Compatible PWM charger, BUCK DC-DC
5 * converters, 5 LDOs, multiple 12-bit ADCs of voltage, current and temperature 5 * converters, LDOs, multiple 12-bit ADCs of voltage, current and temperature
6 * as well as 4 configurable GPIOs. 6 * as well as configurable GPIOs.
7 * 7 *
8 * Author: Carlo Caione <carlo@caione.org> 8 * Author: Carlo Caione <carlo@caione.org>
9 * 9 *
@@ -25,9 +25,16 @@
25#include <linux/mfd/core.h> 25#include <linux/mfd/core.h>
26#include <linux/of_device.h> 26#include <linux/of_device.h>
27#include <linux/of_irq.h> 27#include <linux/of_irq.h>
28#include <linux/acpi.h>
28 29
29#define AXP20X_OFF 0x80 30#define AXP20X_OFF 0x80
30 31
32static const char const *axp20x_model_names[] = {
33 "AXP202",
34 "AXP209",
35 "AXP288",
36};
37
31static const struct regmap_range axp20x_writeable_ranges[] = { 38static const struct regmap_range axp20x_writeable_ranges[] = {
32 regmap_reg_range(AXP20X_DATACACHE(0), AXP20X_IRQ5_STATE), 39 regmap_reg_range(AXP20X_DATACACHE(0), AXP20X_IRQ5_STATE),
33 regmap_reg_range(AXP20X_DCDC_MODE, AXP20X_FG_RES), 40 regmap_reg_range(AXP20X_DCDC_MODE, AXP20X_FG_RES),
@@ -47,6 +54,25 @@ static const struct regmap_access_table axp20x_volatile_table = {
47 .n_yes_ranges = ARRAY_SIZE(axp20x_volatile_ranges), 54 .n_yes_ranges = ARRAY_SIZE(axp20x_volatile_ranges),
48}; 55};
49 56
57static const struct regmap_range axp288_writeable_ranges[] = {
58 regmap_reg_range(AXP20X_DATACACHE(0), AXP20X_IRQ6_STATE),
59 regmap_reg_range(AXP20X_DCDC_MODE, AXP288_FG_TUNE5),
60};
61
62static const struct regmap_range axp288_volatile_ranges[] = {
63 regmap_reg_range(AXP20X_IRQ1_EN, AXP20X_IPSOUT_V_HIGH_L),
64};
65
66static const struct regmap_access_table axp288_writeable_table = {
67 .yes_ranges = axp288_writeable_ranges,
68 .n_yes_ranges = ARRAY_SIZE(axp288_writeable_ranges),
69};
70
71static const struct regmap_access_table axp288_volatile_table = {
72 .yes_ranges = axp288_volatile_ranges,
73 .n_yes_ranges = ARRAY_SIZE(axp288_volatile_ranges),
74};
75
50static struct resource axp20x_pek_resources[] = { 76static struct resource axp20x_pek_resources[] = {
51 { 77 {
52 .name = "PEK_DBR", 78 .name = "PEK_DBR",
@@ -61,6 +87,39 @@ static struct resource axp20x_pek_resources[] = {
61 }, 87 },
62}; 88};
63 89
90static struct resource axp288_battery_resources[] = {
91 {
92 .start = AXP288_IRQ_QWBTU,
93 .end = AXP288_IRQ_QWBTU,
94 .flags = IORESOURCE_IRQ,
95 },
96 {
97 .start = AXP288_IRQ_WBTU,
98 .end = AXP288_IRQ_WBTU,
99 .flags = IORESOURCE_IRQ,
100 },
101 {
102 .start = AXP288_IRQ_QWBTO,
103 .end = AXP288_IRQ_QWBTO,
104 .flags = IORESOURCE_IRQ,
105 },
106 {
107 .start = AXP288_IRQ_WBTO,
108 .end = AXP288_IRQ_WBTO,
109 .flags = IORESOURCE_IRQ,
110 },
111 {
112 .start = AXP288_IRQ_WL2,
113 .end = AXP288_IRQ_WL2,
114 .flags = IORESOURCE_IRQ,
115 },
116 {
117 .start = AXP288_IRQ_WL1,
118 .end = AXP288_IRQ_WL1,
119 .flags = IORESOURCE_IRQ,
120 },
121};
122
64static const struct regmap_config axp20x_regmap_config = { 123static const struct regmap_config axp20x_regmap_config = {
65 .reg_bits = 8, 124 .reg_bits = 8,
66 .val_bits = 8, 125 .val_bits = 8,
@@ -70,47 +129,96 @@ static const struct regmap_config axp20x_regmap_config = {
70 .cache_type = REGCACHE_RBTREE, 129 .cache_type = REGCACHE_RBTREE,
71}; 130};
72 131
73#define AXP20X_IRQ(_irq, _off, _mask) \ 132static const struct regmap_config axp288_regmap_config = {
74 [AXP20X_IRQ_##_irq] = { .reg_offset = (_off), .mask = BIT(_mask) } 133 .reg_bits = 8,
134 .val_bits = 8,
135 .wr_table = &axp288_writeable_table,
136 .volatile_table = &axp288_volatile_table,
137 .max_register = AXP288_FG_TUNE5,
138 .cache_type = REGCACHE_RBTREE,
139};
140
141#define INIT_REGMAP_IRQ(_variant, _irq, _off, _mask) \
142 [_variant##_IRQ_##_irq] = { .reg_offset = (_off), .mask = BIT(_mask) }
75 143
76static const struct regmap_irq axp20x_regmap_irqs[] = { 144static const struct regmap_irq axp20x_regmap_irqs[] = {
77 AXP20X_IRQ(ACIN_OVER_V, 0, 7), 145 INIT_REGMAP_IRQ(AXP20X, ACIN_OVER_V, 0, 7),
78 AXP20X_IRQ(ACIN_PLUGIN, 0, 6), 146 INIT_REGMAP_IRQ(AXP20X, ACIN_PLUGIN, 0, 6),
79 AXP20X_IRQ(ACIN_REMOVAL, 0, 5), 147 INIT_REGMAP_IRQ(AXP20X, ACIN_REMOVAL, 0, 5),
80 AXP20X_IRQ(VBUS_OVER_V, 0, 4), 148 INIT_REGMAP_IRQ(AXP20X, VBUS_OVER_V, 0, 4),
81 AXP20X_IRQ(VBUS_PLUGIN, 0, 3), 149 INIT_REGMAP_IRQ(AXP20X, VBUS_PLUGIN, 0, 3),
82 AXP20X_IRQ(VBUS_REMOVAL, 0, 2), 150 INIT_REGMAP_IRQ(AXP20X, VBUS_REMOVAL, 0, 2),
83 AXP20X_IRQ(VBUS_V_LOW, 0, 1), 151 INIT_REGMAP_IRQ(AXP20X, VBUS_V_LOW, 0, 1),
84 AXP20X_IRQ(BATT_PLUGIN, 1, 7), 152 INIT_REGMAP_IRQ(AXP20X, BATT_PLUGIN, 1, 7),
85 AXP20X_IRQ(BATT_REMOVAL, 1, 6), 153 INIT_REGMAP_IRQ(AXP20X, BATT_REMOVAL, 1, 6),
86 AXP20X_IRQ(BATT_ENT_ACT_MODE, 1, 5), 154 INIT_REGMAP_IRQ(AXP20X, BATT_ENT_ACT_MODE, 1, 5),
87 AXP20X_IRQ(BATT_EXIT_ACT_MODE, 1, 4), 155 INIT_REGMAP_IRQ(AXP20X, BATT_EXIT_ACT_MODE, 1, 4),
88 AXP20X_IRQ(CHARG, 1, 3), 156 INIT_REGMAP_IRQ(AXP20X, CHARG, 1, 3),
89 AXP20X_IRQ(CHARG_DONE, 1, 2), 157 INIT_REGMAP_IRQ(AXP20X, CHARG_DONE, 1, 2),
90 AXP20X_IRQ(BATT_TEMP_HIGH, 1, 1), 158 INIT_REGMAP_IRQ(AXP20X, BATT_TEMP_HIGH, 1, 1),
91 AXP20X_IRQ(BATT_TEMP_LOW, 1, 0), 159 INIT_REGMAP_IRQ(AXP20X, BATT_TEMP_LOW, 1, 0),
92 AXP20X_IRQ(DIE_TEMP_HIGH, 2, 7), 160 INIT_REGMAP_IRQ(AXP20X, DIE_TEMP_HIGH, 2, 7),
93 AXP20X_IRQ(CHARG_I_LOW, 2, 6), 161 INIT_REGMAP_IRQ(AXP20X, CHARG_I_LOW, 2, 6),
94 AXP20X_IRQ(DCDC1_V_LONG, 2, 5), 162 INIT_REGMAP_IRQ(AXP20X, DCDC1_V_LONG, 2, 5),
95 AXP20X_IRQ(DCDC2_V_LONG, 2, 4), 163 INIT_REGMAP_IRQ(AXP20X, DCDC2_V_LONG, 2, 4),
96 AXP20X_IRQ(DCDC3_V_LONG, 2, 3), 164 INIT_REGMAP_IRQ(AXP20X, DCDC3_V_LONG, 2, 3),
97 AXP20X_IRQ(PEK_SHORT, 2, 1), 165 INIT_REGMAP_IRQ(AXP20X, PEK_SHORT, 2, 1),
98 AXP20X_IRQ(PEK_LONG, 2, 0), 166 INIT_REGMAP_IRQ(AXP20X, PEK_LONG, 2, 0),
99 AXP20X_IRQ(N_OE_PWR_ON, 3, 7), 167 INIT_REGMAP_IRQ(AXP20X, N_OE_PWR_ON, 3, 7),
100 AXP20X_IRQ(N_OE_PWR_OFF, 3, 6), 168 INIT_REGMAP_IRQ(AXP20X, N_OE_PWR_OFF, 3, 6),
101 AXP20X_IRQ(VBUS_VALID, 3, 5), 169 INIT_REGMAP_IRQ(AXP20X, VBUS_VALID, 3, 5),
102 AXP20X_IRQ(VBUS_NOT_VALID, 3, 4), 170 INIT_REGMAP_IRQ(AXP20X, VBUS_NOT_VALID, 3, 4),
103 AXP20X_IRQ(VBUS_SESS_VALID, 3, 3), 171 INIT_REGMAP_IRQ(AXP20X, VBUS_SESS_VALID, 3, 3),
104 AXP20X_IRQ(VBUS_SESS_END, 3, 2), 172 INIT_REGMAP_IRQ(AXP20X, VBUS_SESS_END, 3, 2),
105 AXP20X_IRQ(LOW_PWR_LVL1, 3, 1), 173 INIT_REGMAP_IRQ(AXP20X, LOW_PWR_LVL1, 3, 1),
106 AXP20X_IRQ(LOW_PWR_LVL2, 3, 0), 174 INIT_REGMAP_IRQ(AXP20X, LOW_PWR_LVL2, 3, 0),
107 AXP20X_IRQ(TIMER, 4, 7), 175 INIT_REGMAP_IRQ(AXP20X, TIMER, 4, 7),
108 AXP20X_IRQ(PEK_RIS_EDGE, 4, 6), 176 INIT_REGMAP_IRQ(AXP20X, PEK_RIS_EDGE, 4, 6),
109 AXP20X_IRQ(PEK_FAL_EDGE, 4, 5), 177 INIT_REGMAP_IRQ(AXP20X, PEK_FAL_EDGE, 4, 5),
110 AXP20X_IRQ(GPIO3_INPUT, 4, 3), 178 INIT_REGMAP_IRQ(AXP20X, GPIO3_INPUT, 4, 3),
111 AXP20X_IRQ(GPIO2_INPUT, 4, 2), 179 INIT_REGMAP_IRQ(AXP20X, GPIO2_INPUT, 4, 2),
112 AXP20X_IRQ(GPIO1_INPUT, 4, 1), 180 INIT_REGMAP_IRQ(AXP20X, GPIO1_INPUT, 4, 1),
113 AXP20X_IRQ(GPIO0_INPUT, 4, 0), 181 INIT_REGMAP_IRQ(AXP20X, GPIO0_INPUT, 4, 0),
182};
183
184/* some IRQs are compatible with axp20x models */
185static const struct regmap_irq axp288_regmap_irqs[] = {
186 INIT_REGMAP_IRQ(AXP288, VBUS_FALL, 0, 2),
187 INIT_REGMAP_IRQ(AXP288, VBUS_RISE, 0, 3),
188 INIT_REGMAP_IRQ(AXP288, OV, 0, 4),
189
190 INIT_REGMAP_IRQ(AXP288, DONE, 1, 2),
191 INIT_REGMAP_IRQ(AXP288, CHARGING, 1, 3),
192 INIT_REGMAP_IRQ(AXP288, SAFE_QUIT, 1, 4),
193 INIT_REGMAP_IRQ(AXP288, SAFE_ENTER, 1, 5),
194 INIT_REGMAP_IRQ(AXP288, ABSENT, 1, 6),
195 INIT_REGMAP_IRQ(AXP288, APPEND, 1, 7),
196
197 INIT_REGMAP_IRQ(AXP288, QWBTU, 2, 0),
198 INIT_REGMAP_IRQ(AXP288, WBTU, 2, 1),
199 INIT_REGMAP_IRQ(AXP288, QWBTO, 2, 2),
200 INIT_REGMAP_IRQ(AXP288, WBTO, 2, 3),
201 INIT_REGMAP_IRQ(AXP288, QCBTU, 2, 4),
202 INIT_REGMAP_IRQ(AXP288, CBTU, 2, 5),
203 INIT_REGMAP_IRQ(AXP288, QCBTO, 2, 6),
204 INIT_REGMAP_IRQ(AXP288, CBTO, 2, 7),
205
206 INIT_REGMAP_IRQ(AXP288, WL2, 3, 0),
207 INIT_REGMAP_IRQ(AXP288, WL1, 3, 1),
208 INIT_REGMAP_IRQ(AXP288, GPADC, 3, 2),
209 INIT_REGMAP_IRQ(AXP288, OT, 3, 7),
210
211 INIT_REGMAP_IRQ(AXP288, GPIO0, 4, 0),
212 INIT_REGMAP_IRQ(AXP288, GPIO1, 4, 1),
213 INIT_REGMAP_IRQ(AXP288, POKO, 4, 2),
214 INIT_REGMAP_IRQ(AXP288, POKL, 4, 3),
215 INIT_REGMAP_IRQ(AXP288, POKS, 4, 4),
216 INIT_REGMAP_IRQ(AXP288, POKN, 4, 5),
217 INIT_REGMAP_IRQ(AXP288, POKP, 4, 6),
218 INIT_REGMAP_IRQ(AXP288, TIMER, 4, 7),
219
220 INIT_REGMAP_IRQ(AXP288, MV_CHNG, 5, 0),
221 INIT_REGMAP_IRQ(AXP288, BC_USB_CHNG, 5, 1),
114}; 222};
115 223
116static const struct of_device_id axp20x_of_match[] = { 224static const struct of_device_id axp20x_of_match[] = {
@@ -128,16 +236,39 @@ static const struct i2c_device_id axp20x_i2c_id[] = {
128}; 236};
129MODULE_DEVICE_TABLE(i2c, axp20x_i2c_id); 237MODULE_DEVICE_TABLE(i2c, axp20x_i2c_id);
130 238
239static struct acpi_device_id axp20x_acpi_match[] = {
240 {
241 .id = "INT33F4",
242 .driver_data = AXP288_ID,
243 },
244 { },
245};
246MODULE_DEVICE_TABLE(acpi, axp20x_acpi_match);
247
131static const struct regmap_irq_chip axp20x_regmap_irq_chip = { 248static const struct regmap_irq_chip axp20x_regmap_irq_chip = {
132 .name = "axp20x_irq_chip", 249 .name = "axp20x_irq_chip",
133 .status_base = AXP20X_IRQ1_STATE, 250 .status_base = AXP20X_IRQ1_STATE,
134 .ack_base = AXP20X_IRQ1_STATE, 251 .ack_base = AXP20X_IRQ1_STATE,
135 .mask_base = AXP20X_IRQ1_EN, 252 .mask_base = AXP20X_IRQ1_EN,
136 .num_regs = 5, 253 .mask_invert = true,
254 .init_ack_masked = true,
137 .irqs = axp20x_regmap_irqs, 255 .irqs = axp20x_regmap_irqs,
138 .num_irqs = ARRAY_SIZE(axp20x_regmap_irqs), 256 .num_irqs = ARRAY_SIZE(axp20x_regmap_irqs),
257 .num_regs = 5,
258
259};
260
261static const struct regmap_irq_chip axp288_regmap_irq_chip = {
262 .name = "axp288_irq_chip",
263 .status_base = AXP20X_IRQ1_STATE,
264 .ack_base = AXP20X_IRQ1_STATE,
265 .mask_base = AXP20X_IRQ1_EN,
139 .mask_invert = true, 266 .mask_invert = true,
140 .init_ack_masked = true, 267 .init_ack_masked = true,
268 .irqs = axp288_regmap_irqs,
269 .num_irqs = ARRAY_SIZE(axp288_regmap_irqs),
270 .num_regs = 6,
271
141}; 272};
142 273
143static struct mfd_cell axp20x_cells[] = { 274static struct mfd_cell axp20x_cells[] = {
@@ -150,36 +281,158 @@ static struct mfd_cell axp20x_cells[] = {
150 }, 281 },
151}; 282};
152 283
284static struct resource axp288_adc_resources[] = {
285 {
286 .name = "GPADC",
287 .start = AXP288_IRQ_GPADC,
288 .end = AXP288_IRQ_GPADC,
289 .flags = IORESOURCE_IRQ,
290 },
291};
292
293static struct resource axp288_charger_resources[] = {
294 {
295 .start = AXP288_IRQ_OV,
296 .end = AXP288_IRQ_OV,
297 .flags = IORESOURCE_IRQ,
298 },
299 {
300 .start = AXP288_IRQ_DONE,
301 .end = AXP288_IRQ_DONE,
302 .flags = IORESOURCE_IRQ,
303 },
304 {
305 .start = AXP288_IRQ_CHARGING,
306 .end = AXP288_IRQ_CHARGING,
307 .flags = IORESOURCE_IRQ,
308 },
309 {
310 .start = AXP288_IRQ_SAFE_QUIT,
311 .end = AXP288_IRQ_SAFE_QUIT,
312 .flags = IORESOURCE_IRQ,
313 },
314 {
315 .start = AXP288_IRQ_SAFE_ENTER,
316 .end = AXP288_IRQ_SAFE_ENTER,
317 .flags = IORESOURCE_IRQ,
318 },
319 {
320 .start = AXP288_IRQ_QCBTU,
321 .end = AXP288_IRQ_QCBTU,
322 .flags = IORESOURCE_IRQ,
323 },
324 {
325 .start = AXP288_IRQ_CBTU,
326 .end = AXP288_IRQ_CBTU,
327 .flags = IORESOURCE_IRQ,
328 },
329 {
330 .start = AXP288_IRQ_QCBTO,
331 .end = AXP288_IRQ_QCBTO,
332 .flags = IORESOURCE_IRQ,
333 },
334 {
335 .start = AXP288_IRQ_CBTO,
336 .end = AXP288_IRQ_CBTO,
337 .flags = IORESOURCE_IRQ,
338 },
339};
340
341static struct mfd_cell axp288_cells[] = {
342 {
343 .name = "axp288_adc",
344 .num_resources = ARRAY_SIZE(axp288_adc_resources),
345 .resources = axp288_adc_resources,
346 },
347 {
348 .name = "axp288_charger",
349 .num_resources = ARRAY_SIZE(axp288_charger_resources),
350 .resources = axp288_charger_resources,
351 },
352 {
353 .name = "axp288_battery",
354 .num_resources = ARRAY_SIZE(axp288_battery_resources),
355 .resources = axp288_battery_resources,
356 },
357 {
358 .name = "axp288_pmic_acpi",
359 },
360};
361
153static struct axp20x_dev *axp20x_pm_power_off; 362static struct axp20x_dev *axp20x_pm_power_off;
154static void axp20x_power_off(void) 363static void axp20x_power_off(void)
155{ 364{
365 if (axp20x_pm_power_off->variant == AXP288_ID)
366 return;
367
156 regmap_write(axp20x_pm_power_off->regmap, AXP20X_OFF_CTRL, 368 regmap_write(axp20x_pm_power_off->regmap, AXP20X_OFF_CTRL,
157 AXP20X_OFF); 369 AXP20X_OFF);
158} 370}
159 371
372static int axp20x_match_device(struct axp20x_dev *axp20x, struct device *dev)
373{
374 const struct acpi_device_id *acpi_id;
375 const struct of_device_id *of_id;
376
377 if (dev->of_node) {
378 of_id = of_match_device(axp20x_of_match, dev);
379 if (!of_id) {
380 dev_err(dev, "Unable to match OF ID\n");
381 return -ENODEV;
382 }
383 axp20x->variant = (long) of_id->data;
384 } else {
385 acpi_id = acpi_match_device(dev->driver->acpi_match_table, dev);
386 if (!acpi_id || !acpi_id->driver_data) {
387 dev_err(dev, "Unable to match ACPI ID and data\n");
388 return -ENODEV;
389 }
390 axp20x->variant = (long) acpi_id->driver_data;
391 }
392
393 switch (axp20x->variant) {
394 case AXP202_ID:
395 case AXP209_ID:
396 axp20x->nr_cells = ARRAY_SIZE(axp20x_cells);
397 axp20x->cells = axp20x_cells;
398 axp20x->regmap_cfg = &axp20x_regmap_config;
399 axp20x->regmap_irq_chip = &axp20x_regmap_irq_chip;
400 break;
401 case AXP288_ID:
402 axp20x->cells = axp288_cells;
403 axp20x->nr_cells = ARRAY_SIZE(axp288_cells);
404 axp20x->regmap_cfg = &axp288_regmap_config;
405 axp20x->regmap_irq_chip = &axp288_regmap_irq_chip;
406 break;
407 default:
408 dev_err(dev, "unsupported AXP20X ID %lu\n", axp20x->variant);
409 return -EINVAL;
410 }
411 dev_info(dev, "AXP20x variant %s found\n",
412 axp20x_model_names[axp20x->variant]);
413
414 return 0;
415}
416
160static int axp20x_i2c_probe(struct i2c_client *i2c, 417static int axp20x_i2c_probe(struct i2c_client *i2c,
161 const struct i2c_device_id *id) 418 const struct i2c_device_id *id)
162{ 419{
163 struct axp20x_dev *axp20x; 420 struct axp20x_dev *axp20x;
164 const struct of_device_id *of_id;
165 int ret; 421 int ret;
166 422
167 axp20x = devm_kzalloc(&i2c->dev, sizeof(*axp20x), GFP_KERNEL); 423 axp20x = devm_kzalloc(&i2c->dev, sizeof(*axp20x), GFP_KERNEL);
168 if (!axp20x) 424 if (!axp20x)
169 return -ENOMEM; 425 return -ENOMEM;
170 426
171 of_id = of_match_device(axp20x_of_match, &i2c->dev); 427 ret = axp20x_match_device(axp20x, &i2c->dev);
172 if (!of_id) { 428 if (ret)
173 dev_err(&i2c->dev, "Unable to setup AXP20X data\n"); 429 return ret;
174 return -ENODEV;
175 }
176 axp20x->variant = (long) of_id->data;
177 430
178 axp20x->i2c_client = i2c; 431 axp20x->i2c_client = i2c;
179 axp20x->dev = &i2c->dev; 432 axp20x->dev = &i2c->dev;
180 dev_set_drvdata(axp20x->dev, axp20x); 433 dev_set_drvdata(axp20x->dev, axp20x);
181 434
182 axp20x->regmap = devm_regmap_init_i2c(i2c, &axp20x_regmap_config); 435 axp20x->regmap = devm_regmap_init_i2c(i2c, axp20x->regmap_cfg);
183 if (IS_ERR(axp20x->regmap)) { 436 if (IS_ERR(axp20x->regmap)) {
184 ret = PTR_ERR(axp20x->regmap); 437 ret = PTR_ERR(axp20x->regmap);
185 dev_err(&i2c->dev, "regmap init failed: %d\n", ret); 438 dev_err(&i2c->dev, "regmap init failed: %d\n", ret);
@@ -188,15 +441,15 @@ static int axp20x_i2c_probe(struct i2c_client *i2c,
188 441
189 ret = regmap_add_irq_chip(axp20x->regmap, i2c->irq, 442 ret = regmap_add_irq_chip(axp20x->regmap, i2c->irq,
190 IRQF_ONESHOT | IRQF_SHARED, -1, 443 IRQF_ONESHOT | IRQF_SHARED, -1,
191 &axp20x_regmap_irq_chip, 444 axp20x->regmap_irq_chip,
192 &axp20x->regmap_irqc); 445 &axp20x->regmap_irqc);
193 if (ret) { 446 if (ret) {
194 dev_err(&i2c->dev, "failed to add irq chip: %d\n", ret); 447 dev_err(&i2c->dev, "failed to add irq chip: %d\n", ret);
195 return ret; 448 return ret;
196 } 449 }
197 450
198 ret = mfd_add_devices(axp20x->dev, -1, axp20x_cells, 451 ret = mfd_add_devices(axp20x->dev, -1, axp20x->cells,
199 ARRAY_SIZE(axp20x_cells), NULL, 0, NULL); 452 axp20x->nr_cells, NULL, 0, NULL);
200 453
201 if (ret) { 454 if (ret) {
202 dev_err(&i2c->dev, "failed to add MFD devices: %d\n", ret); 455 dev_err(&i2c->dev, "failed to add MFD devices: %d\n", ret);
@@ -234,6 +487,7 @@ static struct i2c_driver axp20x_i2c_driver = {
234 .name = "axp20x", 487 .name = "axp20x",
235 .owner = THIS_MODULE, 488 .owner = THIS_MODULE,
236 .of_match_table = of_match_ptr(axp20x_of_match), 489 .of_match_table = of_match_ptr(axp20x_of_match),
490 .acpi_match_table = ACPI_PTR(axp20x_acpi_match),
237 }, 491 },
238 .probe = axp20x_i2c_probe, 492 .probe = axp20x_i2c_probe,
239 .remove = axp20x_i2c_remove, 493 .remove = axp20x_i2c_remove,
diff --git a/drivers/mfd/intel_soc_pmic_crc.c b/drivers/mfd/intel_soc_pmic_crc.c
index 7107cab832e6..c85e2ecb868a 100644
--- a/drivers/mfd/intel_soc_pmic_crc.c
+++ b/drivers/mfd/intel_soc_pmic_crc.c
@@ -106,6 +106,9 @@ static struct mfd_cell crystal_cove_dev[] = {
106 .num_resources = ARRAY_SIZE(gpio_resources), 106 .num_resources = ARRAY_SIZE(gpio_resources),
107 .resources = gpio_resources, 107 .resources = gpio_resources,
108 }, 108 },
109 {
110 .name = "crystal_cove_pmic",
111 },
109}; 112};
110 113
111static struct regmap_config crystal_cove_regmap_config = { 114static struct regmap_config crystal_cove_regmap_config = {
diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c
index 634f72929e12..0a1af93ec638 100644
--- a/drivers/misc/eeprom/at25.c
+++ b/drivers/misc/eeprom/at25.c
@@ -18,7 +18,7 @@
18 18
19#include <linux/spi/spi.h> 19#include <linux/spi/spi.h>
20#include <linux/spi/eeprom.h> 20#include <linux/spi/eeprom.h>
21#include <linux/of.h> 21#include <linux/property.h>
22 22
23/* 23/*
24 * NOTE: this is an *EEPROM* driver. The vagaries of product naming 24 * NOTE: this is an *EEPROM* driver. The vagaries of product naming
@@ -301,35 +301,33 @@ static ssize_t at25_mem_write(struct memory_accessor *mem, const char *buf,
301 301
302/*-------------------------------------------------------------------------*/ 302/*-------------------------------------------------------------------------*/
303 303
304static int at25_np_to_chip(struct device *dev, 304static int at25_fw_to_chip(struct device *dev, struct spi_eeprom *chip)
305 struct device_node *np,
306 struct spi_eeprom *chip)
307{ 305{
308 u32 val; 306 u32 val;
309 307
310 memset(chip, 0, sizeof(*chip)); 308 memset(chip, 0, sizeof(*chip));
311 strncpy(chip->name, np->name, sizeof(chip->name)); 309 strncpy(chip->name, "at25", sizeof(chip->name));
312 310
313 if (of_property_read_u32(np, "size", &val) == 0 || 311 if (device_property_read_u32(dev, "size", &val) == 0 ||
314 of_property_read_u32(np, "at25,byte-len", &val) == 0) { 312 device_property_read_u32(dev, "at25,byte-len", &val) == 0) {
315 chip->byte_len = val; 313 chip->byte_len = val;
316 } else { 314 } else {
317 dev_err(dev, "Error: missing \"size\" property\n"); 315 dev_err(dev, "Error: missing \"size\" property\n");
318 return -ENODEV; 316 return -ENODEV;
319 } 317 }
320 318
321 if (of_property_read_u32(np, "pagesize", &val) == 0 || 319 if (device_property_read_u32(dev, "pagesize", &val) == 0 ||
322 of_property_read_u32(np, "at25,page-size", &val) == 0) { 320 device_property_read_u32(dev, "at25,page-size", &val) == 0) {
323 chip->page_size = (u16)val; 321 chip->page_size = (u16)val;
324 } else { 322 } else {
325 dev_err(dev, "Error: missing \"pagesize\" property\n"); 323 dev_err(dev, "Error: missing \"pagesize\" property\n");
326 return -ENODEV; 324 return -ENODEV;
327 } 325 }
328 326
329 if (of_property_read_u32(np, "at25,addr-mode", &val) == 0) { 327 if (device_property_read_u32(dev, "at25,addr-mode", &val) == 0) {
330 chip->flags = (u16)val; 328 chip->flags = (u16)val;
331 } else { 329 } else {
332 if (of_property_read_u32(np, "address-width", &val)) { 330 if (device_property_read_u32(dev, "address-width", &val)) {
333 dev_err(dev, 331 dev_err(dev,
334 "Error: missing \"address-width\" property\n"); 332 "Error: missing \"address-width\" property\n");
335 return -ENODEV; 333 return -ENODEV;
@@ -350,7 +348,7 @@ static int at25_np_to_chip(struct device *dev,
350 val); 348 val);
351 return -ENODEV; 349 return -ENODEV;
352 } 350 }
353 if (of_find_property(np, "read-only", NULL)) 351 if (device_property_present(dev, "read-only"))
354 chip->flags |= EE_READONLY; 352 chip->flags |= EE_READONLY;
355 } 353 }
356 return 0; 354 return 0;
@@ -360,21 +358,15 @@ static int at25_probe(struct spi_device *spi)
360{ 358{
361 struct at25_data *at25 = NULL; 359 struct at25_data *at25 = NULL;
362 struct spi_eeprom chip; 360 struct spi_eeprom chip;
363 struct device_node *np = spi->dev.of_node;
364 int err; 361 int err;
365 int sr; 362 int sr;
366 int addrlen; 363 int addrlen;
367 364
368 /* Chip description */ 365 /* Chip description */
369 if (!spi->dev.platform_data) { 366 if (!spi->dev.platform_data) {
370 if (np) { 367 err = at25_fw_to_chip(&spi->dev, &chip);
371 err = at25_np_to_chip(&spi->dev, np, &chip); 368 if (err)
372 if (err) 369 return err;
373 return err;
374 } else {
375 dev_err(&spi->dev, "Error: no chip description\n");
376 return -ENODEV;
377 }
378 } else 370 } else
379 chip = *(struct spi_eeprom *)spi->dev.platform_data; 371 chip = *(struct spi_eeprom *)spi->dev.platform_data;
380 372
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index c9ac06cfe6b7..a5115fb7cf33 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -2471,7 +2471,8 @@ static void bond_loadbalance_arp_mon(struct work_struct *work)
2471 bond_slave_state_change(bond); 2471 bond_slave_state_change(bond);
2472 if (BOND_MODE(bond) == BOND_MODE_XOR) 2472 if (BOND_MODE(bond) == BOND_MODE_XOR)
2473 bond_update_slave_arr(bond, NULL); 2473 bond_update_slave_arr(bond, NULL);
2474 } else if (do_failover) { 2474 }
2475 if (do_failover) {
2475 block_netpoll_tx(); 2476 block_netpoll_tx();
2476 bond_select_active_slave(bond); 2477 bond_select_active_slave(bond);
2477 unblock_netpoll_tx(); 2478 unblock_netpoll_tx();
diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
index c13d83e15ace..45f09a66e6c9 100644
--- a/drivers/net/bonding/bond_netlink.c
+++ b/drivers/net/bonding/bond_netlink.c
@@ -225,7 +225,12 @@ static int bond_changelink(struct net_device *bond_dev,
225 225
226 bond_option_arp_ip_targets_clear(bond); 226 bond_option_arp_ip_targets_clear(bond);
227 nla_for_each_nested(attr, data[IFLA_BOND_ARP_IP_TARGET], rem) { 227 nla_for_each_nested(attr, data[IFLA_BOND_ARP_IP_TARGET], rem) {
228 __be32 target = nla_get_be32(attr); 228 __be32 target;
229
230 if (nla_len(attr) < sizeof(target))
231 return -EINVAL;
232
233 target = nla_get_be32(attr);
229 234
230 bond_opt_initval(&newval, (__force u64)target); 235 bond_opt_initval(&newval, (__force u64)target);
231 err = __bond_opt_set(bond, BOND_OPT_ARP_TARGETS, 236 err = __bond_opt_set(bond, BOND_OPT_ARP_TARGETS,
diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index 02492d241e4c..2cfe5012e4e5 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -110,7 +110,7 @@ static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,
110 long rate; 110 long rate;
111 u64 v64; 111 u64 v64;
112 112
113 /* Use CIA recommended sample points */ 113 /* Use CiA recommended sample points */
114 if (bt->sample_point) { 114 if (bt->sample_point) {
115 sampl_pt = bt->sample_point; 115 sampl_pt = bt->sample_point;
116 } else { 116 } else {
@@ -382,7 +382,7 @@ void can_free_echo_skb(struct net_device *dev, unsigned int idx)
382 BUG_ON(idx >= priv->echo_skb_max); 382 BUG_ON(idx >= priv->echo_skb_max);
383 383
384 if (priv->echo_skb[idx]) { 384 if (priv->echo_skb[idx]) {
385 kfree_skb(priv->echo_skb[idx]); 385 dev_kfree_skb_any(priv->echo_skb[idx]);
386 priv->echo_skb[idx] = NULL; 386 priv->echo_skb[idx] = NULL;
387 } 387 }
388} 388}
diff --git a/drivers/net/can/m_can/Kconfig b/drivers/net/can/m_can/Kconfig
index fca5482c09ac..04f20dd39007 100644
--- a/drivers/net/can/m_can/Kconfig
+++ b/drivers/net/can/m_can/Kconfig
@@ -1,4 +1,5 @@
1config CAN_M_CAN 1config CAN_M_CAN
2 depends on HAS_IOMEM
2 tristate "Bosch M_CAN devices" 3 tristate "Bosch M_CAN devices"
3 ---help--- 4 ---help---
4 Say Y here if you want to support for Bosch M_CAN controller. 5 Say Y here if you want to support for Bosch M_CAN controller.
diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 10d571eaed85..d7bc462aafdc 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -105,14 +105,36 @@ enum m_can_mram_cfg {
105 MRAM_CFG_NUM, 105 MRAM_CFG_NUM,
106}; 106};
107 107
108/* Fast Bit Timing & Prescaler Register (FBTP) */
109#define FBTR_FBRP_MASK 0x1f
110#define FBTR_FBRP_SHIFT 16
111#define FBTR_FTSEG1_SHIFT 8
112#define FBTR_FTSEG1_MASK (0xf << FBTR_FTSEG1_SHIFT)
113#define FBTR_FTSEG2_SHIFT 4
114#define FBTR_FTSEG2_MASK (0x7 << FBTR_FTSEG2_SHIFT)
115#define FBTR_FSJW_SHIFT 0
116#define FBTR_FSJW_MASK 0x3
117
108/* Test Register (TEST) */ 118/* Test Register (TEST) */
109#define TEST_LBCK BIT(4) 119#define TEST_LBCK BIT(4)
110 120
111/* CC Control Register(CCCR) */ 121/* CC Control Register(CCCR) */
112#define CCCR_TEST BIT(7) 122#define CCCR_TEST BIT(7)
113#define CCCR_MON BIT(5) 123#define CCCR_CMR_MASK 0x3
114#define CCCR_CCE BIT(1) 124#define CCCR_CMR_SHIFT 10
115#define CCCR_INIT BIT(0) 125#define CCCR_CMR_CANFD 0x1
126#define CCCR_CMR_CANFD_BRS 0x2
127#define CCCR_CMR_CAN 0x3
128#define CCCR_CME_MASK 0x3
129#define CCCR_CME_SHIFT 8
130#define CCCR_CME_CAN 0
131#define CCCR_CME_CANFD 0x1
132#define CCCR_CME_CANFD_BRS 0x2
133#define CCCR_TEST BIT(7)
134#define CCCR_MON BIT(5)
135#define CCCR_CCE BIT(1)
136#define CCCR_INIT BIT(0)
137#define CCCR_CANFD 0x10
116 138
117/* Bit Timing & Prescaler Register (BTP) */ 139/* Bit Timing & Prescaler Register (BTP) */
118#define BTR_BRP_MASK 0x3ff 140#define BTR_BRP_MASK 0x3ff
@@ -204,6 +226,7 @@ enum m_can_mram_cfg {
204 226
205/* Rx Buffer / FIFO Element Size Configuration (RXESC) */ 227/* Rx Buffer / FIFO Element Size Configuration (RXESC) */
206#define M_CAN_RXESC_8BYTES 0x0 228#define M_CAN_RXESC_8BYTES 0x0
229#define M_CAN_RXESC_64BYTES 0x777
207 230
208/* Tx Buffer Configuration(TXBC) */ 231/* Tx Buffer Configuration(TXBC) */
209#define TXBC_NDTB_OFF 16 232#define TXBC_NDTB_OFF 16
@@ -211,6 +234,7 @@ enum m_can_mram_cfg {
211 234
212/* Tx Buffer Element Size Configuration(TXESC) */ 235/* Tx Buffer Element Size Configuration(TXESC) */
213#define TXESC_TBDS_8BYTES 0x0 236#define TXESC_TBDS_8BYTES 0x0
237#define TXESC_TBDS_64BYTES 0x7
214 238
215/* Tx Event FIFO Con.guration (TXEFC) */ 239/* Tx Event FIFO Con.guration (TXEFC) */
216#define TXEFC_EFS_OFF 16 240#define TXEFC_EFS_OFF 16
@@ -219,11 +243,11 @@ enum m_can_mram_cfg {
219/* Message RAM Configuration (in bytes) */ 243/* Message RAM Configuration (in bytes) */
220#define SIDF_ELEMENT_SIZE 4 244#define SIDF_ELEMENT_SIZE 4
221#define XIDF_ELEMENT_SIZE 8 245#define XIDF_ELEMENT_SIZE 8
222#define RXF0_ELEMENT_SIZE 16 246#define RXF0_ELEMENT_SIZE 72
223#define RXF1_ELEMENT_SIZE 16 247#define RXF1_ELEMENT_SIZE 72
224#define RXB_ELEMENT_SIZE 16 248#define RXB_ELEMENT_SIZE 16
225#define TXE_ELEMENT_SIZE 8 249#define TXE_ELEMENT_SIZE 8
226#define TXB_ELEMENT_SIZE 16 250#define TXB_ELEMENT_SIZE 72
227 251
228/* Message RAM Elements */ 252/* Message RAM Elements */
229#define M_CAN_FIFO_ID 0x0 253#define M_CAN_FIFO_ID 0x0
@@ -231,11 +255,17 @@ enum m_can_mram_cfg {
231#define M_CAN_FIFO_DATA(n) (0x8 + ((n) << 2)) 255#define M_CAN_FIFO_DATA(n) (0x8 + ((n) << 2))
232 256
233/* Rx Buffer Element */ 257/* Rx Buffer Element */
258/* R0 */
234#define RX_BUF_ESI BIT(31) 259#define RX_BUF_ESI BIT(31)
235#define RX_BUF_XTD BIT(30) 260#define RX_BUF_XTD BIT(30)
236#define RX_BUF_RTR BIT(29) 261#define RX_BUF_RTR BIT(29)
262/* R1 */
263#define RX_BUF_ANMF BIT(31)
264#define RX_BUF_EDL BIT(21)
265#define RX_BUF_BRS BIT(20)
237 266
238/* Tx Buffer Element */ 267/* Tx Buffer Element */
268/* R0 */
239#define TX_BUF_XTD BIT(30) 269#define TX_BUF_XTD BIT(30)
240#define TX_BUF_RTR BIT(29) 270#define TX_BUF_RTR BIT(29)
241 271
@@ -296,6 +326,7 @@ static inline void m_can_config_endisable(const struct m_can_priv *priv,
296 if (enable) { 326 if (enable) {
297 /* enable m_can configuration */ 327 /* enable m_can configuration */
298 m_can_write(priv, M_CAN_CCCR, cccr | CCCR_INIT); 328 m_can_write(priv, M_CAN_CCCR, cccr | CCCR_INIT);
329 udelay(5);
299 /* CCCR.CCE can only be set/reset while CCCR.INIT = '1' */ 330 /* CCCR.CCE can only be set/reset while CCCR.INIT = '1' */
300 m_can_write(priv, M_CAN_CCCR, cccr | CCCR_INIT | CCCR_CCE); 331 m_can_write(priv, M_CAN_CCCR, cccr | CCCR_INIT | CCCR_CCE);
301 } else { 332 } else {
@@ -326,41 +357,67 @@ static inline void m_can_disable_all_interrupts(const struct m_can_priv *priv)
326 m_can_write(priv, M_CAN_ILE, 0x0); 357 m_can_write(priv, M_CAN_ILE, 0x0);
327} 358}
328 359
329static void m_can_read_fifo(const struct net_device *dev, struct can_frame *cf, 360static void m_can_read_fifo(struct net_device *dev, u32 rxfs)
330 u32 rxfs)
331{ 361{
362 struct net_device_stats *stats = &dev->stats;
332 struct m_can_priv *priv = netdev_priv(dev); 363 struct m_can_priv *priv = netdev_priv(dev);
333 u32 id, fgi; 364 struct canfd_frame *cf;
365 struct sk_buff *skb;
366 u32 id, fgi, dlc;
367 int i;
334 368
335 /* calculate the fifo get index for where to read data */ 369 /* calculate the fifo get index for where to read data */
336 fgi = (rxfs & RXFS_FGI_MASK) >> RXFS_FGI_OFF; 370 fgi = (rxfs & RXFS_FGI_MASK) >> RXFS_FGI_OFF;
371 dlc = m_can_fifo_read(priv, fgi, M_CAN_FIFO_DLC);
372 if (dlc & RX_BUF_EDL)
373 skb = alloc_canfd_skb(dev, &cf);
374 else
375 skb = alloc_can_skb(dev, (struct can_frame **)&cf);
376 if (!skb) {
377 stats->rx_dropped++;
378 return;
379 }
380
381 if (dlc & RX_BUF_EDL)
382 cf->len = can_dlc2len((dlc >> 16) & 0x0F);
383 else
384 cf->len = get_can_dlc((dlc >> 16) & 0x0F);
385
337 id = m_can_fifo_read(priv, fgi, M_CAN_FIFO_ID); 386 id = m_can_fifo_read(priv, fgi, M_CAN_FIFO_ID);
338 if (id & RX_BUF_XTD) 387 if (id & RX_BUF_XTD)
339 cf->can_id = (id & CAN_EFF_MASK) | CAN_EFF_FLAG; 388 cf->can_id = (id & CAN_EFF_MASK) | CAN_EFF_FLAG;
340 else 389 else
341 cf->can_id = (id >> 18) & CAN_SFF_MASK; 390 cf->can_id = (id >> 18) & CAN_SFF_MASK;
342 391
343 if (id & RX_BUF_RTR) { 392 if (id & RX_BUF_ESI) {
393 cf->flags |= CANFD_ESI;
394 netdev_dbg(dev, "ESI Error\n");
395 }
396
397 if (!(dlc & RX_BUF_EDL) && (id & RX_BUF_RTR)) {
344 cf->can_id |= CAN_RTR_FLAG; 398 cf->can_id |= CAN_RTR_FLAG;
345 } else { 399 } else {
346 id = m_can_fifo_read(priv, fgi, M_CAN_FIFO_DLC); 400 if (dlc & RX_BUF_BRS)
347 cf->can_dlc = get_can_dlc((id >> 16) & 0x0F); 401 cf->flags |= CANFD_BRS;
348 *(u32 *)(cf->data + 0) = m_can_fifo_read(priv, fgi, 402
349 M_CAN_FIFO_DATA(0)); 403 for (i = 0; i < cf->len; i += 4)
350 *(u32 *)(cf->data + 4) = m_can_fifo_read(priv, fgi, 404 *(u32 *)(cf->data + i) =
351 M_CAN_FIFO_DATA(1)); 405 m_can_fifo_read(priv, fgi,
406 M_CAN_FIFO_DATA(i / 4));
352 } 407 }
353 408
354 /* acknowledge rx fifo 0 */ 409 /* acknowledge rx fifo 0 */
355 m_can_write(priv, M_CAN_RXF0A, fgi); 410 m_can_write(priv, M_CAN_RXF0A, fgi);
411
412 stats->rx_packets++;
413 stats->rx_bytes += cf->len;
414
415 netif_receive_skb(skb);
356} 416}
357 417
358static int m_can_do_rx_poll(struct net_device *dev, int quota) 418static int m_can_do_rx_poll(struct net_device *dev, int quota)
359{ 419{
360 struct m_can_priv *priv = netdev_priv(dev); 420 struct m_can_priv *priv = netdev_priv(dev);
361 struct net_device_stats *stats = &dev->stats;
362 struct sk_buff *skb;
363 struct can_frame *frame;
364 u32 pkts = 0; 421 u32 pkts = 0;
365 u32 rxfs; 422 u32 rxfs;
366 423
@@ -374,18 +431,7 @@ static int m_can_do_rx_poll(struct net_device *dev, int quota)
374 if (rxfs & RXFS_RFL) 431 if (rxfs & RXFS_RFL)
375 netdev_warn(dev, "Rx FIFO 0 Message Lost\n"); 432 netdev_warn(dev, "Rx FIFO 0 Message Lost\n");
376 433
377 skb = alloc_can_skb(dev, &frame); 434 m_can_read_fifo(dev, rxfs);
378 if (!skb) {
379 stats->rx_dropped++;
380 return pkts;
381 }
382
383 m_can_read_fifo(dev, frame, rxfs);
384
385 stats->rx_packets++;
386 stats->rx_bytes += frame->can_dlc;
387
388 netif_receive_skb(skb);
389 435
390 quota--; 436 quota--;
391 pkts++; 437 pkts++;
@@ -481,11 +527,23 @@ static int m_can_handle_lec_err(struct net_device *dev,
481 return 1; 527 return 1;
482} 528}
483 529
530static int __m_can_get_berr_counter(const struct net_device *dev,
531 struct can_berr_counter *bec)
532{
533 struct m_can_priv *priv = netdev_priv(dev);
534 unsigned int ecr;
535
536 ecr = m_can_read(priv, M_CAN_ECR);
537 bec->rxerr = (ecr & ECR_REC_MASK) >> ECR_REC_SHIFT;
538 bec->txerr = ecr & ECR_TEC_MASK;
539
540 return 0;
541}
542
484static int m_can_get_berr_counter(const struct net_device *dev, 543static int m_can_get_berr_counter(const struct net_device *dev,
485 struct can_berr_counter *bec) 544 struct can_berr_counter *bec)
486{ 545{
487 struct m_can_priv *priv = netdev_priv(dev); 546 struct m_can_priv *priv = netdev_priv(dev);
488 unsigned int ecr;
489 int err; 547 int err;
490 548
491 err = clk_prepare_enable(priv->hclk); 549 err = clk_prepare_enable(priv->hclk);
@@ -498,9 +556,7 @@ static int m_can_get_berr_counter(const struct net_device *dev,
498 return err; 556 return err;
499 } 557 }
500 558
501 ecr = m_can_read(priv, M_CAN_ECR); 559 __m_can_get_berr_counter(dev, bec);
502 bec->rxerr = (ecr & ECR_REC_MASK) >> ECR_REC_SHIFT;
503 bec->txerr = ecr & ECR_TEC_MASK;
504 560
505 clk_disable_unprepare(priv->cclk); 561 clk_disable_unprepare(priv->cclk);
506 clk_disable_unprepare(priv->hclk); 562 clk_disable_unprepare(priv->hclk);
@@ -544,7 +600,7 @@ static int m_can_handle_state_change(struct net_device *dev,
544 if (unlikely(!skb)) 600 if (unlikely(!skb))
545 return 0; 601 return 0;
546 602
547 m_can_get_berr_counter(dev, &bec); 603 __m_can_get_berr_counter(dev, &bec);
548 604
549 switch (new_state) { 605 switch (new_state) {
550 case CAN_STATE_ERROR_ACTIVE: 606 case CAN_STATE_ERROR_ACTIVE:
@@ -596,14 +652,14 @@ static int m_can_handle_state_errors(struct net_device *dev, u32 psr)
596 652
597 if ((psr & PSR_EP) && 653 if ((psr & PSR_EP) &&
598 (priv->can.state != CAN_STATE_ERROR_PASSIVE)) { 654 (priv->can.state != CAN_STATE_ERROR_PASSIVE)) {
599 netdev_dbg(dev, "entered error warning state\n"); 655 netdev_dbg(dev, "entered error passive state\n");
600 work_done += m_can_handle_state_change(dev, 656 work_done += m_can_handle_state_change(dev,
601 CAN_STATE_ERROR_PASSIVE); 657 CAN_STATE_ERROR_PASSIVE);
602 } 658 }
603 659
604 if ((psr & PSR_BO) && 660 if ((psr & PSR_BO) &&
605 (priv->can.state != CAN_STATE_BUS_OFF)) { 661 (priv->can.state != CAN_STATE_BUS_OFF)) {
606 netdev_dbg(dev, "entered error warning state\n"); 662 netdev_dbg(dev, "entered error bus off state\n");
607 work_done += m_can_handle_state_change(dev, 663 work_done += m_can_handle_state_change(dev,
608 CAN_STATE_BUS_OFF); 664 CAN_STATE_BUS_OFF);
609 } 665 }
@@ -615,7 +671,7 @@ static void m_can_handle_other_err(struct net_device *dev, u32 irqstatus)
615{ 671{
616 if (irqstatus & IR_WDI) 672 if (irqstatus & IR_WDI)
617 netdev_err(dev, "Message RAM Watchdog event due to missing READY\n"); 673 netdev_err(dev, "Message RAM Watchdog event due to missing READY\n");
618 if (irqstatus & IR_BEU) 674 if (irqstatus & IR_ELO)
619 netdev_err(dev, "Error Logging Overflow\n"); 675 netdev_err(dev, "Error Logging Overflow\n");
620 if (irqstatus & IR_BEU) 676 if (irqstatus & IR_BEU)
621 netdev_err(dev, "Bit Error Uncorrected\n"); 677 netdev_err(dev, "Bit Error Uncorrected\n");
@@ -733,10 +789,23 @@ static const struct can_bittiming_const m_can_bittiming_const = {
733 .brp_inc = 1, 789 .brp_inc = 1,
734}; 790};
735 791
792static const struct can_bittiming_const m_can_data_bittiming_const = {
793 .name = KBUILD_MODNAME,
794 .tseg1_min = 2, /* Time segment 1 = prop_seg + phase_seg1 */
795 .tseg1_max = 16,
796 .tseg2_min = 1, /* Time segment 2 = phase_seg2 */
797 .tseg2_max = 8,
798 .sjw_max = 4,
799 .brp_min = 1,
800 .brp_max = 32,
801 .brp_inc = 1,
802};
803
736static int m_can_set_bittiming(struct net_device *dev) 804static int m_can_set_bittiming(struct net_device *dev)
737{ 805{
738 struct m_can_priv *priv = netdev_priv(dev); 806 struct m_can_priv *priv = netdev_priv(dev);
739 const struct can_bittiming *bt = &priv->can.bittiming; 807 const struct can_bittiming *bt = &priv->can.bittiming;
808 const struct can_bittiming *dbt = &priv->can.data_bittiming;
740 u16 brp, sjw, tseg1, tseg2; 809 u16 brp, sjw, tseg1, tseg2;
741 u32 reg_btp; 810 u32 reg_btp;
742 811
@@ -747,7 +816,17 @@ static int m_can_set_bittiming(struct net_device *dev)
747 reg_btp = (brp << BTR_BRP_SHIFT) | (sjw << BTR_SJW_SHIFT) | 816 reg_btp = (brp << BTR_BRP_SHIFT) | (sjw << BTR_SJW_SHIFT) |
748 (tseg1 << BTR_TSEG1_SHIFT) | (tseg2 << BTR_TSEG2_SHIFT); 817 (tseg1 << BTR_TSEG1_SHIFT) | (tseg2 << BTR_TSEG2_SHIFT);
749 m_can_write(priv, M_CAN_BTP, reg_btp); 818 m_can_write(priv, M_CAN_BTP, reg_btp);
750 netdev_dbg(dev, "setting BTP 0x%x\n", reg_btp); 819
820 if (priv->can.ctrlmode & CAN_CTRLMODE_FD) {
821 brp = dbt->brp - 1;
822 sjw = dbt->sjw - 1;
823 tseg1 = dbt->prop_seg + dbt->phase_seg1 - 1;
824 tseg2 = dbt->phase_seg2 - 1;
825 reg_btp = (brp << FBTR_FBRP_SHIFT) | (sjw << FBTR_FSJW_SHIFT) |
826 (tseg1 << FBTR_FTSEG1_SHIFT) |
827 (tseg2 << FBTR_FTSEG2_SHIFT);
828 m_can_write(priv, M_CAN_FBTP, reg_btp);
829 }
751 830
752 return 0; 831 return 0;
753} 832}
@@ -767,8 +846,8 @@ static void m_can_chip_config(struct net_device *dev)
767 846
768 m_can_config_endisable(priv, true); 847 m_can_config_endisable(priv, true);
769 848
770 /* RX Buffer/FIFO Element Size 8 bytes data field */ 849 /* RX Buffer/FIFO Element Size 64 bytes data field */
771 m_can_write(priv, M_CAN_RXESC, M_CAN_RXESC_8BYTES); 850 m_can_write(priv, M_CAN_RXESC, M_CAN_RXESC_64BYTES);
772 851
773 /* Accept Non-matching Frames Into FIFO 0 */ 852 /* Accept Non-matching Frames Into FIFO 0 */
774 m_can_write(priv, M_CAN_GFC, 0x0); 853 m_can_write(priv, M_CAN_GFC, 0x0);
@@ -777,8 +856,8 @@ static void m_can_chip_config(struct net_device *dev)
777 m_can_write(priv, M_CAN_TXBC, (1 << TXBC_NDTB_OFF) | 856 m_can_write(priv, M_CAN_TXBC, (1 << TXBC_NDTB_OFF) |
778 priv->mcfg[MRAM_TXB].off); 857 priv->mcfg[MRAM_TXB].off);
779 858
780 /* only support 8 bytes firstly */ 859 /* support 64 bytes payload */
781 m_can_write(priv, M_CAN_TXESC, TXESC_TBDS_8BYTES); 860 m_can_write(priv, M_CAN_TXESC, TXESC_TBDS_64BYTES);
782 861
783 m_can_write(priv, M_CAN_TXEFC, (1 << TXEFC_EFS_OFF) | 862 m_can_write(priv, M_CAN_TXEFC, (1 << TXEFC_EFS_OFF) |
784 priv->mcfg[MRAM_TXE].off); 863 priv->mcfg[MRAM_TXE].off);
@@ -793,7 +872,8 @@ static void m_can_chip_config(struct net_device *dev)
793 RXFC_FWM_1 | priv->mcfg[MRAM_RXF1].off); 872 RXFC_FWM_1 | priv->mcfg[MRAM_RXF1].off);
794 873
795 cccr = m_can_read(priv, M_CAN_CCCR); 874 cccr = m_can_read(priv, M_CAN_CCCR);
796 cccr &= ~(CCCR_TEST | CCCR_MON); 875 cccr &= ~(CCCR_TEST | CCCR_MON | (CCCR_CMR_MASK << CCCR_CMR_SHIFT) |
876 (CCCR_CME_MASK << CCCR_CME_SHIFT));
797 test = m_can_read(priv, M_CAN_TEST); 877 test = m_can_read(priv, M_CAN_TEST);
798 test &= ~TEST_LBCK; 878 test &= ~TEST_LBCK;
799 879
@@ -805,6 +885,9 @@ static void m_can_chip_config(struct net_device *dev)
805 test |= TEST_LBCK; 885 test |= TEST_LBCK;
806 } 886 }
807 887
888 if (priv->can.ctrlmode & CAN_CTRLMODE_FD)
889 cccr |= CCCR_CME_CANFD_BRS << CCCR_CME_SHIFT;
890
808 m_can_write(priv, M_CAN_CCCR, cccr); 891 m_can_write(priv, M_CAN_CCCR, cccr);
809 m_can_write(priv, M_CAN_TEST, test); 892 m_can_write(priv, M_CAN_TEST, test);
810 893
@@ -869,11 +952,13 @@ static struct net_device *alloc_m_can_dev(void)
869 952
870 priv->dev = dev; 953 priv->dev = dev;
871 priv->can.bittiming_const = &m_can_bittiming_const; 954 priv->can.bittiming_const = &m_can_bittiming_const;
955 priv->can.data_bittiming_const = &m_can_data_bittiming_const;
872 priv->can.do_set_mode = m_can_set_mode; 956 priv->can.do_set_mode = m_can_set_mode;
873 priv->can.do_get_berr_counter = m_can_get_berr_counter; 957 priv->can.do_get_berr_counter = m_can_get_berr_counter;
874 priv->can.ctrlmode_supported = CAN_CTRLMODE_LOOPBACK | 958 priv->can.ctrlmode_supported = CAN_CTRLMODE_LOOPBACK |
875 CAN_CTRLMODE_LISTENONLY | 959 CAN_CTRLMODE_LISTENONLY |
876 CAN_CTRLMODE_BERR_REPORTING; 960 CAN_CTRLMODE_BERR_REPORTING |
961 CAN_CTRLMODE_FD;
877 962
878 return dev; 963 return dev;
879} 964}
@@ -956,8 +1041,9 @@ static netdev_tx_t m_can_start_xmit(struct sk_buff *skb,
956 struct net_device *dev) 1041 struct net_device *dev)
957{ 1042{
958 struct m_can_priv *priv = netdev_priv(dev); 1043 struct m_can_priv *priv = netdev_priv(dev);
959 struct can_frame *cf = (struct can_frame *)skb->data; 1044 struct canfd_frame *cf = (struct canfd_frame *)skb->data;
960 u32 id; 1045 u32 id, cccr;
1046 int i;
961 1047
962 if (can_dropped_invalid_skb(dev, skb)) 1048 if (can_dropped_invalid_skb(dev, skb))
963 return NETDEV_TX_OK; 1049 return NETDEV_TX_OK;
@@ -976,11 +1062,28 @@ static netdev_tx_t m_can_start_xmit(struct sk_buff *skb,
976 1062
977 /* message ram configuration */ 1063 /* message ram configuration */
978 m_can_fifo_write(priv, 0, M_CAN_FIFO_ID, id); 1064 m_can_fifo_write(priv, 0, M_CAN_FIFO_ID, id);
979 m_can_fifo_write(priv, 0, M_CAN_FIFO_DLC, cf->can_dlc << 16); 1065 m_can_fifo_write(priv, 0, M_CAN_FIFO_DLC, can_len2dlc(cf->len) << 16);
980 m_can_fifo_write(priv, 0, M_CAN_FIFO_DATA(0), *(u32 *)(cf->data + 0)); 1066
981 m_can_fifo_write(priv, 0, M_CAN_FIFO_DATA(1), *(u32 *)(cf->data + 4)); 1067 for (i = 0; i < cf->len; i += 4)
1068 m_can_fifo_write(priv, 0, M_CAN_FIFO_DATA(i / 4),
1069 *(u32 *)(cf->data + i));
1070
982 can_put_echo_skb(skb, dev, 0); 1071 can_put_echo_skb(skb, dev, 0);
983 1072
1073 if (priv->can.ctrlmode & CAN_CTRLMODE_FD) {
1074 cccr = m_can_read(priv, M_CAN_CCCR);
1075 cccr &= ~(CCCR_CMR_MASK << CCCR_CMR_SHIFT);
1076 if (can_is_canfd_skb(skb)) {
1077 if (cf->flags & CANFD_BRS)
1078 cccr |= CCCR_CMR_CANFD_BRS << CCCR_CMR_SHIFT;
1079 else
1080 cccr |= CCCR_CMR_CANFD << CCCR_CMR_SHIFT;
1081 } else {
1082 cccr |= CCCR_CMR_CAN << CCCR_CMR_SHIFT;
1083 }
1084 m_can_write(priv, M_CAN_CCCR, cccr);
1085 }
1086
984 /* enable first TX buffer to start transfer */ 1087 /* enable first TX buffer to start transfer */
985 m_can_write(priv, M_CAN_TXBTIE, 0x1); 1088 m_can_write(priv, M_CAN_TXBTIE, 0x1);
986 m_can_write(priv, M_CAN_TXBAR, 0x1); 1089 m_can_write(priv, M_CAN_TXBAR, 0x1);
@@ -992,6 +1095,7 @@ static const struct net_device_ops m_can_netdev_ops = {
992 .ndo_open = m_can_open, 1095 .ndo_open = m_can_open,
993 .ndo_stop = m_can_close, 1096 .ndo_stop = m_can_close,
994 .ndo_start_xmit = m_can_start_xmit, 1097 .ndo_start_xmit = m_can_start_xmit,
1098 .ndo_change_mtu = can_change_mtu,
995}; 1099};
996 1100
997static int register_m_can_dev(struct net_device *dev) 1101static int register_m_can_dev(struct net_device *dev)
@@ -1009,7 +1113,7 @@ static int m_can_of_parse_mram(struct platform_device *pdev,
1009 struct resource *res; 1113 struct resource *res;
1010 void __iomem *addr; 1114 void __iomem *addr;
1011 u32 out_val[MRAM_CFG_LEN]; 1115 u32 out_val[MRAM_CFG_LEN];
1012 int ret; 1116 int i, start, end, ret;
1013 1117
1014 /* message ram could be shared */ 1118 /* message ram could be shared */
1015 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "message_ram"); 1119 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "message_ram");
@@ -1060,6 +1164,15 @@ static int m_can_of_parse_mram(struct platform_device *pdev,
1060 priv->mcfg[MRAM_TXE].off, priv->mcfg[MRAM_TXE].num, 1164 priv->mcfg[MRAM_TXE].off, priv->mcfg[MRAM_TXE].num,
1061 priv->mcfg[MRAM_TXB].off, priv->mcfg[MRAM_TXB].num); 1165 priv->mcfg[MRAM_TXB].off, priv->mcfg[MRAM_TXB].num);
1062 1166
1167 /* initialize the entire Message RAM in use to avoid possible
1168 * ECC/parity checksum errors when reading an uninitialized buffer
1169 */
1170 start = priv->mcfg[MRAM_SIDF].off;
1171 end = priv->mcfg[MRAM_TXB].off +
1172 priv->mcfg[MRAM_TXB].num * TXB_ELEMENT_SIZE;
1173 for (i = start; i < end; i += 4)
1174 writel(0x0, priv->mram_base + i);
1175
1063 return 0; 1176 return 0;
1064} 1177}
1065 1178
diff --git a/drivers/net/can/rcar_can.c b/drivers/net/can/rcar_can.c
index 1abe133d1594..9718248e55f1 100644
--- a/drivers/net/can/rcar_can.c
+++ b/drivers/net/can/rcar_can.c
@@ -628,6 +628,7 @@ static const struct net_device_ops rcar_can_netdev_ops = {
628 .ndo_open = rcar_can_open, 628 .ndo_open = rcar_can_open,
629 .ndo_stop = rcar_can_close, 629 .ndo_stop = rcar_can_close,
630 .ndo_start_xmit = rcar_can_start_xmit, 630 .ndo_start_xmit = rcar_can_start_xmit,
631 .ndo_change_mtu = can_change_mtu,
631}; 632};
632 633
633static void rcar_can_rx_pkt(struct rcar_can_priv *priv) 634static void rcar_can_rx_pkt(struct rcar_can_priv *priv)
diff --git a/drivers/net/can/sja1000/kvaser_pci.c b/drivers/net/can/sja1000/kvaser_pci.c
index 8ff3424d5147..15c00faeec61 100644
--- a/drivers/net/can/sja1000/kvaser_pci.c
+++ b/drivers/net/can/sja1000/kvaser_pci.c
@@ -214,7 +214,7 @@ static int kvaser_pci_add_chan(struct pci_dev *pdev, int channel,
214 struct net_device *dev; 214 struct net_device *dev;
215 struct sja1000_priv *priv; 215 struct sja1000_priv *priv;
216 struct kvaser_pci *board; 216 struct kvaser_pci *board;
217 int err, init_step; 217 int err;
218 218
219 dev = alloc_sja1000dev(sizeof(struct kvaser_pci)); 219 dev = alloc_sja1000dev(sizeof(struct kvaser_pci));
220 if (dev == NULL) 220 if (dev == NULL)
@@ -235,7 +235,6 @@ static int kvaser_pci_add_chan(struct pci_dev *pdev, int channel,
235 if (channel == 0) { 235 if (channel == 0) {
236 board->xilinx_ver = 236 board->xilinx_ver =
237 ioread8(board->res_addr + XILINX_VERINT) >> 4; 237 ioread8(board->res_addr + XILINX_VERINT) >> 4;
238 init_step = 2;
239 238
240 /* Assert PTADR# - we're in passive mode so the other bits are 239 /* Assert PTADR# - we're in passive mode so the other bits are
241 not important */ 240 not important */
@@ -264,8 +263,6 @@ static int kvaser_pci_add_chan(struct pci_dev *pdev, int channel,
264 priv->irq_flags = IRQF_SHARED; 263 priv->irq_flags = IRQF_SHARED;
265 dev->irq = pdev->irq; 264 dev->irq = pdev->irq;
266 265
267 init_step = 4;
268
269 dev_info(&pdev->dev, "reg_base=%p conf_addr=%p irq=%d\n", 266 dev_info(&pdev->dev, "reg_base=%p conf_addr=%p irq=%d\n",
270 priv->reg_base, board->conf_addr, dev->irq); 267 priv->reg_base, board->conf_addr, dev->irq);
271 268
diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c
index 00f2534dde73..29d3f0938eb8 100644
--- a/drivers/net/can/usb/ems_usb.c
+++ b/drivers/net/can/usb/ems_usb.c
@@ -434,10 +434,9 @@ static void ems_usb_read_bulk_callback(struct urb *urb)
434 if (urb->actual_length > CPC_HEADER_SIZE) { 434 if (urb->actual_length > CPC_HEADER_SIZE) {
435 struct ems_cpc_msg *msg; 435 struct ems_cpc_msg *msg;
436 u8 *ibuf = urb->transfer_buffer; 436 u8 *ibuf = urb->transfer_buffer;
437 u8 msg_count, again, start; 437 u8 msg_count, start;
438 438
439 msg_count = ibuf[0] & ~0x80; 439 msg_count = ibuf[0] & ~0x80;
440 again = ibuf[0] & 0x80;
441 440
442 start = CPC_HEADER_SIZE; 441 start = CPC_HEADER_SIZE;
443 442
diff --git a/drivers/net/can/usb/esd_usb2.c b/drivers/net/can/usb/esd_usb2.c
index b7c9e8b11460..c063a54ab8dd 100644
--- a/drivers/net/can/usb/esd_usb2.c
+++ b/drivers/net/can/usb/esd_usb2.c
@@ -464,7 +464,6 @@ static void esd_usb2_write_bulk_callback(struct urb *urb)
464{ 464{
465 struct esd_tx_urb_context *context = urb->context; 465 struct esd_tx_urb_context *context = urb->context;
466 struct esd_usb2_net_priv *priv; 466 struct esd_usb2_net_priv *priv;
467 struct esd_usb2 *dev;
468 struct net_device *netdev; 467 struct net_device *netdev;
469 size_t size = sizeof(struct esd_usb2_msg); 468 size_t size = sizeof(struct esd_usb2_msg);
470 469
@@ -472,7 +471,6 @@ static void esd_usb2_write_bulk_callback(struct urb *urb)
472 471
473 priv = context->priv; 472 priv = context->priv;
474 netdev = priv->netdev; 473 netdev = priv->netdev;
475 dev = priv->usb2;
476 474
477 /* free up our allocated buffer */ 475 /* free up our allocated buffer */
478 usb_free_coherent(urb->dev, size, 476 usb_free_coherent(urb->dev, size,
@@ -1143,6 +1141,7 @@ static void esd_usb2_disconnect(struct usb_interface *intf)
1143 } 1141 }
1144 } 1142 }
1145 unlink_all_urbs(dev); 1143 unlink_all_urbs(dev);
1144 kfree(dev);
1146 } 1145 }
1147} 1146}
1148 1147
diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
index 04b0f84612f0..009acc8641fc 100644
--- a/drivers/net/can/usb/gs_usb.c
+++ b/drivers/net/can/usb/gs_usb.c
@@ -718,6 +718,7 @@ static const struct net_device_ops gs_usb_netdev_ops = {
718 .ndo_open = gs_can_open, 718 .ndo_open = gs_can_open,
719 .ndo_stop = gs_can_close, 719 .ndo_stop = gs_can_close,
720 .ndo_start_xmit = gs_can_start_xmit, 720 .ndo_start_xmit = gs_can_start_xmit,
721 .ndo_change_mtu = can_change_mtu,
721}; 722};
722 723
723static struct gs_can *gs_make_candev(unsigned int channel, struct usb_interface *intf) 724static struct gs_can *gs_make_candev(unsigned int channel, struct usb_interface *intf)
diff --git a/drivers/net/can/xilinx_can.c b/drivers/net/can/xilinx_can.c
index 5e8b5609c067..8a998e3884ce 100644
--- a/drivers/net/can/xilinx_can.c
+++ b/drivers/net/can/xilinx_can.c
@@ -300,7 +300,8 @@ static int xcan_set_bittiming(struct net_device *ndev)
300static int xcan_chip_start(struct net_device *ndev) 300static int xcan_chip_start(struct net_device *ndev)
301{ 301{
302 struct xcan_priv *priv = netdev_priv(ndev); 302 struct xcan_priv *priv = netdev_priv(ndev);
303 u32 err, reg_msr, reg_sr_mask; 303 u32 reg_msr, reg_sr_mask;
304 int err;
304 unsigned long timeout; 305 unsigned long timeout;
305 306
306 /* Check if it is in reset mode */ 307 /* Check if it is in reset mode */
@@ -961,6 +962,7 @@ static const struct net_device_ops xcan_netdev_ops = {
961 .ndo_open = xcan_open, 962 .ndo_open = xcan_open,
962 .ndo_stop = xcan_close, 963 .ndo_stop = xcan_close,
963 .ndo_start_xmit = xcan_start_xmit, 964 .ndo_start_xmit = xcan_start_xmit,
965 .ndo_change_mtu = can_change_mtu,
964}; 966};
965 967
966/** 968/**
diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
index b9625968daac..4f4c2a7888e5 100644
--- a/drivers/net/dsa/bcm_sf2.c
+++ b/drivers/net/dsa/bcm_sf2.c
@@ -377,6 +377,29 @@ static irqreturn_t bcm_sf2_switch_1_isr(int irq, void *dev_id)
377 return IRQ_HANDLED; 377 return IRQ_HANDLED;
378} 378}
379 379
380static int bcm_sf2_sw_rst(struct bcm_sf2_priv *priv)
381{
382 unsigned int timeout = 1000;
383 u32 reg;
384
385 reg = core_readl(priv, CORE_WATCHDOG_CTRL);
386 reg |= SOFTWARE_RESET | EN_CHIP_RST | EN_SW_RESET;
387 core_writel(priv, reg, CORE_WATCHDOG_CTRL);
388
389 do {
390 reg = core_readl(priv, CORE_WATCHDOG_CTRL);
391 if (!(reg & SOFTWARE_RESET))
392 break;
393
394 usleep_range(1000, 2000);
395 } while (timeout-- > 0);
396
397 if (timeout == 0)
398 return -ETIMEDOUT;
399
400 return 0;
401}
402
380static int bcm_sf2_sw_setup(struct dsa_switch *ds) 403static int bcm_sf2_sw_setup(struct dsa_switch *ds)
381{ 404{
382 const char *reg_names[BCM_SF2_REGS_NUM] = BCM_SF2_REGS_NAME; 405 const char *reg_names[BCM_SF2_REGS_NUM] = BCM_SF2_REGS_NAME;
@@ -404,11 +427,18 @@ static int bcm_sf2_sw_setup(struct dsa_switch *ds)
404 *base = of_iomap(dn, i); 427 *base = of_iomap(dn, i);
405 if (*base == NULL) { 428 if (*base == NULL) {
406 pr_err("unable to find register: %s\n", reg_names[i]); 429 pr_err("unable to find register: %s\n", reg_names[i]);
407 return -ENODEV; 430 ret = -ENOMEM;
431 goto out_unmap;
408 } 432 }
409 base++; 433 base++;
410 } 434 }
411 435
436 ret = bcm_sf2_sw_rst(priv);
437 if (ret) {
438 pr_err("unable to software reset switch: %d\n", ret);
439 goto out_unmap;
440 }
441
412 /* Disable all interrupts and request them */ 442 /* Disable all interrupts and request them */
413 intrl2_0_writel(priv, 0xffffffff, INTRL2_CPU_MASK_SET); 443 intrl2_0_writel(priv, 0xffffffff, INTRL2_CPU_MASK_SET);
414 intrl2_0_writel(priv, 0xffffffff, INTRL2_CPU_CLEAR); 444 intrl2_0_writel(priv, 0xffffffff, INTRL2_CPU_CLEAR);
@@ -484,7 +514,8 @@ out_free_irq0:
484out_unmap: 514out_unmap:
485 base = &priv->core; 515 base = &priv->core;
486 for (i = 0; i < BCM_SF2_REGS_NUM; i++) { 516 for (i = 0; i < BCM_SF2_REGS_NUM; i++) {
487 iounmap(*base); 517 if (*base)
518 iounmap(*base);
488 base++; 519 base++;
489 } 520 }
490 return ret; 521 return ret;
@@ -733,29 +764,6 @@ static int bcm_sf2_sw_suspend(struct dsa_switch *ds)
733 return 0; 764 return 0;
734} 765}
735 766
736static int bcm_sf2_sw_rst(struct bcm_sf2_priv *priv)
737{
738 unsigned int timeout = 1000;
739 u32 reg;
740
741 reg = core_readl(priv, CORE_WATCHDOG_CTRL);
742 reg |= SOFTWARE_RESET | EN_CHIP_RST | EN_SW_RESET;
743 core_writel(priv, reg, CORE_WATCHDOG_CTRL);
744
745 do {
746 reg = core_readl(priv, CORE_WATCHDOG_CTRL);
747 if (!(reg & SOFTWARE_RESET))
748 break;
749
750 usleep_range(1000, 2000);
751 } while (timeout-- > 0);
752
753 if (timeout == 0)
754 return -ETIMEDOUT;
755
756 return 0;
757}
758
759static int bcm_sf2_sw_resume(struct dsa_switch *ds) 767static int bcm_sf2_sw_resume(struct dsa_switch *ds)
760{ 768{
761 struct bcm_sf2_priv *priv = ds_to_priv(ds); 769 struct bcm_sf2_priv *priv = ds_to_priv(ds);
diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index dbb41c1923e6..77f8f836cbbe 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -8563,7 +8563,8 @@ static int tg3_init_rings(struct tg3 *tp)
8563 if (tnapi->rx_rcb) 8563 if (tnapi->rx_rcb)
8564 memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp)); 8564 memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp));
8565 8565
8566 if (tg3_rx_prodring_alloc(tp, &tnapi->prodring)) { 8566 if (tnapi->prodring.rx_std &&
8567 tg3_rx_prodring_alloc(tp, &tnapi->prodring)) {
8567 tg3_free_rings(tp); 8568 tg3_free_rings(tp);
8568 return -ENOMEM; 8569 return -ENOMEM;
8569 } 8570 }
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_dcb.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_dcb.c
index cca604994003..4fe33606f372 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_dcb.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_dcb.c
@@ -1082,7 +1082,7 @@ static int cxgb4_cee_peer_getpg(struct net_device *dev, struct cee_pg *pg)
1082 pgid = be32_to_cpu(pcmd.u.dcb.pgid.pgid); 1082 pgid = be32_to_cpu(pcmd.u.dcb.pgid.pgid);
1083 1083
1084 for (i = 0; i < CXGB4_MAX_PRIORITY; i++) 1084 for (i = 0; i < CXGB4_MAX_PRIORITY; i++)
1085 pg->prio_pg[i] = (pgid >> (i * 4)) & 0xF; 1085 pg->prio_pg[7 - i] = (pgid >> (i * 4)) & 0xF;
1086 1086
1087 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id); 1087 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
1088 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE; 1088 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
index 8520d5529df8..279873cb6e3a 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
@@ -2442,9 +2442,13 @@ static unsigned int from_fw_linkcaps(unsigned int type, unsigned int caps)
2442 SUPPORTED_10000baseKR_Full | SUPPORTED_1000baseKX_Full | 2442 SUPPORTED_10000baseKR_Full | SUPPORTED_1000baseKX_Full |
2443 SUPPORTED_10000baseKX4_Full; 2443 SUPPORTED_10000baseKX4_Full;
2444 else if (type == FW_PORT_TYPE_FIBER_XFI || 2444 else if (type == FW_PORT_TYPE_FIBER_XFI ||
2445 type == FW_PORT_TYPE_FIBER_XAUI || type == FW_PORT_TYPE_SFP) 2445 type == FW_PORT_TYPE_FIBER_XAUI || type == FW_PORT_TYPE_SFP) {
2446 v |= SUPPORTED_FIBRE; 2446 v |= SUPPORTED_FIBRE;
2447 else if (type == FW_PORT_TYPE_BP40_BA) 2447 if (caps & FW_PORT_CAP_SPEED_1G)
2448 v |= SUPPORTED_1000baseT_Full;
2449 if (caps & FW_PORT_CAP_SPEED_10G)
2450 v |= SUPPORTED_10000baseT_Full;
2451 } else if (type == FW_PORT_TYPE_BP40_BA)
2448 v |= SUPPORTED_40000baseSR4_Full; 2452 v |= SUPPORTED_40000baseSR4_Full;
2449 2453
2450 if (caps & FW_PORT_CAP_ANEG) 2454 if (caps & FW_PORT_CAP_ANEG)
diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
index 9a18e7930b31..597c463e384d 100644
--- a/drivers/net/ethernet/emulex/benet/be_main.c
+++ b/drivers/net/ethernet/emulex/benet/be_main.c
@@ -4309,11 +4309,16 @@ static int be_ndo_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh)
4309 return -EOPNOTSUPP; 4309 return -EOPNOTSUPP;
4310 4310
4311 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); 4311 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
4312 if (!br_spec)
4313 return -EINVAL;
4312 4314
4313 nla_for_each_nested(attr, br_spec, rem) { 4315 nla_for_each_nested(attr, br_spec, rem) {
4314 if (nla_type(attr) != IFLA_BRIDGE_MODE) 4316 if (nla_type(attr) != IFLA_BRIDGE_MODE)
4315 continue; 4317 continue;
4316 4318
4319 if (nla_len(attr) < sizeof(mode))
4320 return -EINVAL;
4321
4317 mode = nla_get_u16(attr); 4322 mode = nla_get_u16(attr);
4318 if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB) 4323 if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB)
4319 return -EINVAL; 4324 return -EINVAL;
@@ -4421,6 +4426,11 @@ static void be_del_vxlan_port(struct net_device *netdev, sa_family_t sa_family,
4421 "Disabled VxLAN offloads for UDP port %d\n", 4426 "Disabled VxLAN offloads for UDP port %d\n",
4422 be16_to_cpu(port)); 4427 be16_to_cpu(port));
4423} 4428}
4429
4430static bool be_gso_check(struct sk_buff *skb, struct net_device *dev)
4431{
4432 return vxlan_gso_check(skb);
4433}
4424#endif 4434#endif
4425 4435
4426static const struct net_device_ops be_netdev_ops = { 4436static const struct net_device_ops be_netdev_ops = {
@@ -4450,6 +4460,7 @@ static const struct net_device_ops be_netdev_ops = {
4450#ifdef CONFIG_BE2NET_VXLAN 4460#ifdef CONFIG_BE2NET_VXLAN
4451 .ndo_add_vxlan_port = be_add_vxlan_port, 4461 .ndo_add_vxlan_port = be_add_vxlan_port,
4452 .ndo_del_vxlan_port = be_del_vxlan_port, 4462 .ndo_del_vxlan_port = be_del_vxlan_port,
4463 .ndo_gso_check = be_gso_check,
4453#endif 4464#endif
4454}; 4465};
4455 4466
diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index a2d72a87cbde..487cd9c4ac0d 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -1012,7 +1012,8 @@ static void igb_free_q_vector(struct igb_adapter *adapter, int v_idx)
1012 /* igb_get_stats64() might access the rings on this vector, 1012 /* igb_get_stats64() might access the rings on this vector,
1013 * we must wait a grace period before freeing it. 1013 * we must wait a grace period before freeing it.
1014 */ 1014 */
1015 kfree_rcu(q_vector, rcu); 1015 if (q_vector)
1016 kfree_rcu(q_vector, rcu);
1016} 1017}
1017 1018
1018/** 1019/**
@@ -1792,8 +1793,10 @@ void igb_down(struct igb_adapter *adapter)
1792 adapter->flags &= ~IGB_FLAG_NEED_LINK_UPDATE; 1793 adapter->flags &= ~IGB_FLAG_NEED_LINK_UPDATE;
1793 1794
1794 for (i = 0; i < adapter->num_q_vectors; i++) { 1795 for (i = 0; i < adapter->num_q_vectors; i++) {
1795 napi_synchronize(&(adapter->q_vector[i]->napi)); 1796 if (adapter->q_vector[i]) {
1796 napi_disable(&(adapter->q_vector[i]->napi)); 1797 napi_synchronize(&adapter->q_vector[i]->napi);
1798 napi_disable(&adapter->q_vector[i]->napi);
1799 }
1797 } 1800 }
1798 1801
1799 1802
@@ -3717,7 +3720,8 @@ static void igb_free_all_tx_resources(struct igb_adapter *adapter)
3717 int i; 3720 int i;
3718 3721
3719 for (i = 0; i < adapter->num_tx_queues; i++) 3722 for (i = 0; i < adapter->num_tx_queues; i++)
3720 igb_free_tx_resources(adapter->tx_ring[i]); 3723 if (adapter->tx_ring[i])
3724 igb_free_tx_resources(adapter->tx_ring[i]);
3721} 3725}
3722 3726
3723void igb_unmap_and_free_tx_resource(struct igb_ring *ring, 3727void igb_unmap_and_free_tx_resource(struct igb_ring *ring,
@@ -3782,7 +3786,8 @@ static void igb_clean_all_tx_rings(struct igb_adapter *adapter)
3782 int i; 3786 int i;
3783 3787
3784 for (i = 0; i < adapter->num_tx_queues; i++) 3788 for (i = 0; i < adapter->num_tx_queues; i++)
3785 igb_clean_tx_ring(adapter->tx_ring[i]); 3789 if (adapter->tx_ring[i])
3790 igb_clean_tx_ring(adapter->tx_ring[i]);
3786} 3791}
3787 3792
3788/** 3793/**
@@ -3819,7 +3824,8 @@ static void igb_free_all_rx_resources(struct igb_adapter *adapter)
3819 int i; 3824 int i;
3820 3825
3821 for (i = 0; i < adapter->num_rx_queues; i++) 3826 for (i = 0; i < adapter->num_rx_queues; i++)
3822 igb_free_rx_resources(adapter->rx_ring[i]); 3827 if (adapter->rx_ring[i])
3828 igb_free_rx_resources(adapter->rx_ring[i]);
3823} 3829}
3824 3830
3825/** 3831/**
@@ -3874,7 +3880,8 @@ static void igb_clean_all_rx_rings(struct igb_adapter *adapter)
3874 int i; 3880 int i;
3875 3881
3876 for (i = 0; i < adapter->num_rx_queues; i++) 3882 for (i = 0; i < adapter->num_rx_queues; i++)
3877 igb_clean_rx_ring(adapter->rx_ring[i]); 3883 if (adapter->rx_ring[i])
3884 igb_clean_rx_ring(adapter->rx_ring[i]);
3878} 3885}
3879 3886
3880/** 3887/**
@@ -7404,6 +7411,8 @@ static int igb_resume(struct device *dev)
7404 pci_restore_state(pdev); 7411 pci_restore_state(pdev);
7405 pci_save_state(pdev); 7412 pci_save_state(pdev);
7406 7413
7414 if (!pci_device_is_present(pdev))
7415 return -ENODEV;
7407 err = pci_enable_device_mem(pdev); 7416 err = pci_enable_device_mem(pdev);
7408 if (err) { 7417 if (err) {
7409 dev_err(&pdev->dev, 7418 dev_err(&pdev->dev,
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
index d2df4e3d1032..cc51554c9e99 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
@@ -3936,8 +3936,8 @@ void ixgbe_set_rx_mode(struct net_device *netdev)
3936 * if SR-IOV and VMDQ are disabled - otherwise ensure 3936 * if SR-IOV and VMDQ are disabled - otherwise ensure
3937 * that hardware VLAN filters remain enabled. 3937 * that hardware VLAN filters remain enabled.
3938 */ 3938 */
3939 if (!(adapter->flags & (IXGBE_FLAG_VMDQ_ENABLED | 3939 if (adapter->flags & (IXGBE_FLAG_VMDQ_ENABLED |
3940 IXGBE_FLAG_SRIOV_ENABLED))) 3940 IXGBE_FLAG_SRIOV_ENABLED))
3941 vlnctrl |= (IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN); 3941 vlnctrl |= (IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3942 } else { 3942 } else {
3943 if (netdev->flags & IFF_ALLMULTI) { 3943 if (netdev->flags & IFF_ALLMULTI) {
@@ -7669,6 +7669,8 @@ static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
7669 return -EOPNOTSUPP; 7669 return -EOPNOTSUPP;
7670 7670
7671 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); 7671 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
7672 if (!br_spec)
7673 return -EINVAL;
7672 7674
7673 nla_for_each_nested(attr, br_spec, rem) { 7675 nla_for_each_nested(attr, br_spec, rem) {
7674 __u16 mode; 7676 __u16 mode;
@@ -7677,6 +7679,9 @@ static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
7677 if (nla_type(attr) != IFLA_BRIDGE_MODE) 7679 if (nla_type(attr) != IFLA_BRIDGE_MODE)
7678 continue; 7680 continue;
7679 7681
7682 if (nla_len(attr) < sizeof(mode))
7683 return -EINVAL;
7684
7680 mode = nla_get_u16(attr); 7685 mode = nla_get_u16(attr);
7681 if (mode == BRIDGE_MODE_VEPA) { 7686 if (mode == BRIDGE_MODE_VEPA) {
7682 reg = 0; 7687 reg = 0;
@@ -7979,6 +7984,7 @@ static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
7979 int i, err, pci_using_dac, expected_gts; 7984 int i, err, pci_using_dac, expected_gts;
7980 unsigned int indices = MAX_TX_QUEUES; 7985 unsigned int indices = MAX_TX_QUEUES;
7981 u8 part_str[IXGBE_PBANUM_LENGTH]; 7986 u8 part_str[IXGBE_PBANUM_LENGTH];
7987 bool disable_dev = false;
7982#ifdef IXGBE_FCOE 7988#ifdef IXGBE_FCOE
7983 u16 device_caps; 7989 u16 device_caps;
7984#endif 7990#endif
@@ -8369,13 +8375,14 @@ err_sw_init:
8369 iounmap(adapter->io_addr); 8375 iounmap(adapter->io_addr);
8370 kfree(adapter->mac_table); 8376 kfree(adapter->mac_table);
8371err_ioremap: 8377err_ioremap:
8378 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
8372 free_netdev(netdev); 8379 free_netdev(netdev);
8373err_alloc_etherdev: 8380err_alloc_etherdev:
8374 pci_release_selected_regions(pdev, 8381 pci_release_selected_regions(pdev,
8375 pci_select_bars(pdev, IORESOURCE_MEM)); 8382 pci_select_bars(pdev, IORESOURCE_MEM));
8376err_pci_reg: 8383err_pci_reg:
8377err_dma: 8384err_dma:
8378 if (!adapter || !test_and_set_bit(__IXGBE_DISABLED, &adapter->state)) 8385 if (!adapter || disable_dev)
8379 pci_disable_device(pdev); 8386 pci_disable_device(pdev);
8380 return err; 8387 return err;
8381} 8388}
@@ -8393,6 +8400,7 @@ static void ixgbe_remove(struct pci_dev *pdev)
8393{ 8400{
8394 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); 8401 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8395 struct net_device *netdev = adapter->netdev; 8402 struct net_device *netdev = adapter->netdev;
8403 bool disable_dev;
8396 8404
8397 ixgbe_dbg_adapter_exit(adapter); 8405 ixgbe_dbg_adapter_exit(adapter);
8398 8406
@@ -8442,11 +8450,12 @@ static void ixgbe_remove(struct pci_dev *pdev)
8442 e_dev_info("complete\n"); 8450 e_dev_info("complete\n");
8443 8451
8444 kfree(adapter->mac_table); 8452 kfree(adapter->mac_table);
8453 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
8445 free_netdev(netdev); 8454 free_netdev(netdev);
8446 8455
8447 pci_disable_pcie_error_reporting(pdev); 8456 pci_disable_pcie_error_reporting(pdev);
8448 8457
8449 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state)) 8458 if (disable_dev)
8450 pci_disable_device(pdev); 8459 pci_disable_device(pdev);
8451} 8460}
8452 8461
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
index 02266e3de514..4d69e382b4e5 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
@@ -1693,7 +1693,7 @@ int mlx4_en_start_port(struct net_device *dev)
1693 mlx4_set_stats_bitmap(mdev->dev, &priv->stats_bitmap); 1693 mlx4_set_stats_bitmap(mdev->dev, &priv->stats_bitmap);
1694 1694
1695#ifdef CONFIG_MLX4_EN_VXLAN 1695#ifdef CONFIG_MLX4_EN_VXLAN
1696 if (priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_VXLAN_OFFLOADS) 1696 if (priv->mdev->dev->caps.tunnel_offload_mode == MLX4_TUNNEL_OFFLOAD_MODE_VXLAN)
1697 vxlan_get_rx_port(dev); 1697 vxlan_get_rx_port(dev);
1698#endif 1698#endif
1699 priv->port_up = true; 1699 priv->port_up = true;
@@ -2355,6 +2355,11 @@ static void mlx4_en_del_vxlan_port(struct net_device *dev,
2355 2355
2356 queue_work(priv->mdev->workqueue, &priv->vxlan_del_task); 2356 queue_work(priv->mdev->workqueue, &priv->vxlan_del_task);
2357} 2357}
2358
2359static bool mlx4_en_gso_check(struct sk_buff *skb, struct net_device *dev)
2360{
2361 return vxlan_gso_check(skb);
2362}
2358#endif 2363#endif
2359 2364
2360static const struct net_device_ops mlx4_netdev_ops = { 2365static const struct net_device_ops mlx4_netdev_ops = {
@@ -2386,6 +2391,7 @@ static const struct net_device_ops mlx4_netdev_ops = {
2386#ifdef CONFIG_MLX4_EN_VXLAN 2391#ifdef CONFIG_MLX4_EN_VXLAN
2387 .ndo_add_vxlan_port = mlx4_en_add_vxlan_port, 2392 .ndo_add_vxlan_port = mlx4_en_add_vxlan_port,
2388 .ndo_del_vxlan_port = mlx4_en_del_vxlan_port, 2393 .ndo_del_vxlan_port = mlx4_en_del_vxlan_port,
2394 .ndo_gso_check = mlx4_en_gso_check,
2389#endif 2395#endif
2390}; 2396};
2391 2397
@@ -2416,6 +2422,11 @@ static const struct net_device_ops mlx4_netdev_ops_master = {
2416 .ndo_rx_flow_steer = mlx4_en_filter_rfs, 2422 .ndo_rx_flow_steer = mlx4_en_filter_rfs,
2417#endif 2423#endif
2418 .ndo_get_phys_port_id = mlx4_en_get_phys_port_id, 2424 .ndo_get_phys_port_id = mlx4_en_get_phys_port_id,
2425#ifdef CONFIG_MLX4_EN_VXLAN
2426 .ndo_add_vxlan_port = mlx4_en_add_vxlan_port,
2427 .ndo_del_vxlan_port = mlx4_en_del_vxlan_port,
2428 .ndo_gso_check = mlx4_en_gso_check,
2429#endif
2419}; 2430};
2420 2431
2421int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port, 2432int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port,
diff --git a/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c b/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
index 5d2498dcf536..cd5cf6d957c7 100644
--- a/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
+++ b/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
@@ -1546,7 +1546,7 @@ static int qp_alloc_res(struct mlx4_dev *dev, int slave, int op, int cmd,
1546 1546
1547 switch (op) { 1547 switch (op) {
1548 case RES_OP_RESERVE: 1548 case RES_OP_RESERVE:
1549 count = get_param_l(&in_param); 1549 count = get_param_l(&in_param) & 0xffffff;
1550 align = get_param_h(&in_param); 1550 align = get_param_h(&in_param);
1551 err = mlx4_grant_resource(dev, slave, RES_QP, count, 0); 1551 err = mlx4_grant_resource(dev, slave, RES_QP, count, 0);
1552 if (err) 1552 if (err)
diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c
index f5e29f7bdae3..a913b3ad2f89 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c
@@ -503,6 +503,11 @@ static void qlcnic_del_vxlan_port(struct net_device *netdev,
503 503
504 adapter->flags |= QLCNIC_DEL_VXLAN_PORT; 504 adapter->flags |= QLCNIC_DEL_VXLAN_PORT;
505} 505}
506
507static bool qlcnic_gso_check(struct sk_buff *skb, struct net_device *dev)
508{
509 return vxlan_gso_check(skb);
510}
506#endif 511#endif
507 512
508static const struct net_device_ops qlcnic_netdev_ops = { 513static const struct net_device_ops qlcnic_netdev_ops = {
@@ -526,6 +531,7 @@ static const struct net_device_ops qlcnic_netdev_ops = {
526#ifdef CONFIG_QLCNIC_VXLAN 531#ifdef CONFIG_QLCNIC_VXLAN
527 .ndo_add_vxlan_port = qlcnic_add_vxlan_port, 532 .ndo_add_vxlan_port = qlcnic_add_vxlan_port,
528 .ndo_del_vxlan_port = qlcnic_del_vxlan_port, 533 .ndo_del_vxlan_port = qlcnic_del_vxlan_port,
534 .ndo_gso_check = qlcnic_gso_check,
529#endif 535#endif
530#ifdef CONFIG_NET_POLL_CONTROLLER 536#ifdef CONFIG_NET_POLL_CONTROLLER
531 .ndo_poll_controller = qlcnic_poll_controller, 537 .ndo_poll_controller = qlcnic_poll_controller,
diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c
index 60e9c2cd051e..b5db6b3f939f 100644
--- a/drivers/net/ethernet/renesas/sh_eth.c
+++ b/drivers/net/ethernet/renesas/sh_eth.c
@@ -917,21 +917,13 @@ static int sh_eth_reset(struct net_device *ndev)
917 return ret; 917 return ret;
918} 918}
919 919
920#if defined(CONFIG_CPU_SH4) || defined(CONFIG_ARCH_SHMOBILE)
921static void sh_eth_set_receive_align(struct sk_buff *skb) 920static void sh_eth_set_receive_align(struct sk_buff *skb)
922{ 921{
923 int reserve; 922 uintptr_t reserve = (uintptr_t)skb->data & (SH_ETH_RX_ALIGN - 1);
924 923
925 reserve = SH4_SKB_RX_ALIGN - ((u32)skb->data & (SH4_SKB_RX_ALIGN - 1));
926 if (reserve) 924 if (reserve)
927 skb_reserve(skb, reserve); 925 skb_reserve(skb, SH_ETH_RX_ALIGN - reserve);
928} 926}
929#else
930static void sh_eth_set_receive_align(struct sk_buff *skb)
931{
932 skb_reserve(skb, SH2_SH3_SKB_RX_ALIGN);
933}
934#endif
935 927
936 928
937/* CPU <-> EDMAC endian convert */ 929/* CPU <-> EDMAC endian convert */
@@ -1119,6 +1111,7 @@ static void sh_eth_ring_format(struct net_device *ndev)
1119 struct sh_eth_txdesc *txdesc = NULL; 1111 struct sh_eth_txdesc *txdesc = NULL;
1120 int rx_ringsize = sizeof(*rxdesc) * mdp->num_rx_ring; 1112 int rx_ringsize = sizeof(*rxdesc) * mdp->num_rx_ring;
1121 int tx_ringsize = sizeof(*txdesc) * mdp->num_tx_ring; 1113 int tx_ringsize = sizeof(*txdesc) * mdp->num_tx_ring;
1114 int skbuff_size = mdp->rx_buf_sz + SH_ETH_RX_ALIGN - 1;
1122 1115
1123 mdp->cur_rx = 0; 1116 mdp->cur_rx = 0;
1124 mdp->cur_tx = 0; 1117 mdp->cur_tx = 0;
@@ -1131,21 +1124,21 @@ static void sh_eth_ring_format(struct net_device *ndev)
1131 for (i = 0; i < mdp->num_rx_ring; i++) { 1124 for (i = 0; i < mdp->num_rx_ring; i++) {
1132 /* skb */ 1125 /* skb */
1133 mdp->rx_skbuff[i] = NULL; 1126 mdp->rx_skbuff[i] = NULL;
1134 skb = netdev_alloc_skb(ndev, mdp->rx_buf_sz); 1127 skb = netdev_alloc_skb(ndev, skbuff_size);
1135 mdp->rx_skbuff[i] = skb; 1128 mdp->rx_skbuff[i] = skb;
1136 if (skb == NULL) 1129 if (skb == NULL)
1137 break; 1130 break;
1138 dma_map_single(&ndev->dev, skb->data, mdp->rx_buf_sz,
1139 DMA_FROM_DEVICE);
1140 sh_eth_set_receive_align(skb); 1131 sh_eth_set_receive_align(skb);
1141 1132
1142 /* RX descriptor */ 1133 /* RX descriptor */
1143 rxdesc = &mdp->rx_ring[i]; 1134 rxdesc = &mdp->rx_ring[i];
1135 /* The size of the buffer is a multiple of 16 bytes. */
1136 rxdesc->buffer_length = ALIGN(mdp->rx_buf_sz, 16);
1137 dma_map_single(&ndev->dev, skb->data, rxdesc->buffer_length,
1138 DMA_FROM_DEVICE);
1144 rxdesc->addr = virt_to_phys(PTR_ALIGN(skb->data, 4)); 1139 rxdesc->addr = virt_to_phys(PTR_ALIGN(skb->data, 4));
1145 rxdesc->status = cpu_to_edmac(mdp, RD_RACT | RD_RFP); 1140 rxdesc->status = cpu_to_edmac(mdp, RD_RACT | RD_RFP);
1146 1141
1147 /* The size of the buffer is 16 byte boundary. */
1148 rxdesc->buffer_length = ALIGN(mdp->rx_buf_sz, 16);
1149 /* Rx descriptor address set */ 1142 /* Rx descriptor address set */
1150 if (i == 0) { 1143 if (i == 0) {
1151 sh_eth_write(ndev, mdp->rx_desc_dma, RDLAR); 1144 sh_eth_write(ndev, mdp->rx_desc_dma, RDLAR);
@@ -1397,6 +1390,7 @@ static int sh_eth_rx(struct net_device *ndev, u32 intr_status, int *quota)
1397 struct sk_buff *skb; 1390 struct sk_buff *skb;
1398 u16 pkt_len = 0; 1391 u16 pkt_len = 0;
1399 u32 desc_status; 1392 u32 desc_status;
1393 int skbuff_size = mdp->rx_buf_sz + SH_ETH_RX_ALIGN - 1;
1400 1394
1401 rxdesc = &mdp->rx_ring[entry]; 1395 rxdesc = &mdp->rx_ring[entry];
1402 while (!(rxdesc->status & cpu_to_edmac(mdp, RD_RACT))) { 1396 while (!(rxdesc->status & cpu_to_edmac(mdp, RD_RACT))) {
@@ -1448,7 +1442,7 @@ static int sh_eth_rx(struct net_device *ndev, u32 intr_status, int *quota)
1448 if (mdp->cd->rpadir) 1442 if (mdp->cd->rpadir)
1449 skb_reserve(skb, NET_IP_ALIGN); 1443 skb_reserve(skb, NET_IP_ALIGN);
1450 dma_sync_single_for_cpu(&ndev->dev, rxdesc->addr, 1444 dma_sync_single_for_cpu(&ndev->dev, rxdesc->addr,
1451 mdp->rx_buf_sz, 1445 ALIGN(mdp->rx_buf_sz, 16),
1452 DMA_FROM_DEVICE); 1446 DMA_FROM_DEVICE);
1453 skb_put(skb, pkt_len); 1447 skb_put(skb, pkt_len);
1454 skb->protocol = eth_type_trans(skb, ndev); 1448 skb->protocol = eth_type_trans(skb, ndev);
@@ -1468,13 +1462,13 @@ static int sh_eth_rx(struct net_device *ndev, u32 intr_status, int *quota)
1468 rxdesc->buffer_length = ALIGN(mdp->rx_buf_sz, 16); 1462 rxdesc->buffer_length = ALIGN(mdp->rx_buf_sz, 16);
1469 1463
1470 if (mdp->rx_skbuff[entry] == NULL) { 1464 if (mdp->rx_skbuff[entry] == NULL) {
1471 skb = netdev_alloc_skb(ndev, mdp->rx_buf_sz); 1465 skb = netdev_alloc_skb(ndev, skbuff_size);
1472 mdp->rx_skbuff[entry] = skb; 1466 mdp->rx_skbuff[entry] = skb;
1473 if (skb == NULL) 1467 if (skb == NULL)
1474 break; /* Better luck next round. */ 1468 break; /* Better luck next round. */
1475 dma_map_single(&ndev->dev, skb->data, mdp->rx_buf_sz,
1476 DMA_FROM_DEVICE);
1477 sh_eth_set_receive_align(skb); 1469 sh_eth_set_receive_align(skb);
1470 dma_map_single(&ndev->dev, skb->data,
1471 rxdesc->buffer_length, DMA_FROM_DEVICE);
1478 1472
1479 skb_checksum_none_assert(skb); 1473 skb_checksum_none_assert(skb);
1480 rxdesc->addr = virt_to_phys(PTR_ALIGN(skb->data, 4)); 1474 rxdesc->addr = virt_to_phys(PTR_ALIGN(skb->data, 4));
@@ -2042,6 +2036,8 @@ static int sh_eth_open(struct net_device *ndev)
2042 if (ret) 2036 if (ret)
2043 goto out_free_irq; 2037 goto out_free_irq;
2044 2038
2039 mdp->is_opened = 1;
2040
2045 return ret; 2041 return ret;
2046 2042
2047out_free_irq: 2043out_free_irq:
@@ -2131,6 +2127,36 @@ static int sh_eth_start_xmit(struct sk_buff *skb, struct net_device *ndev)
2131 return NETDEV_TX_OK; 2127 return NETDEV_TX_OK;
2132} 2128}
2133 2129
2130static struct net_device_stats *sh_eth_get_stats(struct net_device *ndev)
2131{
2132 struct sh_eth_private *mdp = netdev_priv(ndev);
2133
2134 if (sh_eth_is_rz_fast_ether(mdp))
2135 return &ndev->stats;
2136
2137 if (!mdp->is_opened)
2138 return &ndev->stats;
2139
2140 ndev->stats.tx_dropped += sh_eth_read(ndev, TROCR);
2141 sh_eth_write(ndev, 0, TROCR); /* (write clear) */
2142 ndev->stats.collisions += sh_eth_read(ndev, CDCR);
2143 sh_eth_write(ndev, 0, CDCR); /* (write clear) */
2144 ndev->stats.tx_carrier_errors += sh_eth_read(ndev, LCCR);
2145 sh_eth_write(ndev, 0, LCCR); /* (write clear) */
2146
2147 if (sh_eth_is_gether(mdp)) {
2148 ndev->stats.tx_carrier_errors += sh_eth_read(ndev, CERCR);
2149 sh_eth_write(ndev, 0, CERCR); /* (write clear) */
2150 ndev->stats.tx_carrier_errors += sh_eth_read(ndev, CEECR);
2151 sh_eth_write(ndev, 0, CEECR); /* (write clear) */
2152 } else {
2153 ndev->stats.tx_carrier_errors += sh_eth_read(ndev, CNDCR);
2154 sh_eth_write(ndev, 0, CNDCR); /* (write clear) */
2155 }
2156
2157 return &ndev->stats;
2158}
2159
2134/* device close function */ 2160/* device close function */
2135static int sh_eth_close(struct net_device *ndev) 2161static int sh_eth_close(struct net_device *ndev)
2136{ 2162{
@@ -2145,6 +2171,7 @@ static int sh_eth_close(struct net_device *ndev)
2145 sh_eth_write(ndev, 0, EDTRR); 2171 sh_eth_write(ndev, 0, EDTRR);
2146 sh_eth_write(ndev, 0, EDRRR); 2172 sh_eth_write(ndev, 0, EDRRR);
2147 2173
2174 sh_eth_get_stats(ndev);
2148 /* PHY Disconnect */ 2175 /* PHY Disconnect */
2149 if (mdp->phydev) { 2176 if (mdp->phydev) {
2150 phy_stop(mdp->phydev); 2177 phy_stop(mdp->phydev);
@@ -2163,36 +2190,9 @@ static int sh_eth_close(struct net_device *ndev)
2163 2190
2164 pm_runtime_put_sync(&mdp->pdev->dev); 2191 pm_runtime_put_sync(&mdp->pdev->dev);
2165 2192
2166 return 0; 2193 mdp->is_opened = 0;
2167}
2168
2169static struct net_device_stats *sh_eth_get_stats(struct net_device *ndev)
2170{
2171 struct sh_eth_private *mdp = netdev_priv(ndev);
2172
2173 if (sh_eth_is_rz_fast_ether(mdp))
2174 return &ndev->stats;
2175 2194
2176 pm_runtime_get_sync(&mdp->pdev->dev); 2195 return 0;
2177
2178 ndev->stats.tx_dropped += sh_eth_read(ndev, TROCR);
2179 sh_eth_write(ndev, 0, TROCR); /* (write clear) */
2180 ndev->stats.collisions += sh_eth_read(ndev, CDCR);
2181 sh_eth_write(ndev, 0, CDCR); /* (write clear) */
2182 ndev->stats.tx_carrier_errors += sh_eth_read(ndev, LCCR);
2183 sh_eth_write(ndev, 0, LCCR); /* (write clear) */
2184 if (sh_eth_is_gether(mdp)) {
2185 ndev->stats.tx_carrier_errors += sh_eth_read(ndev, CERCR);
2186 sh_eth_write(ndev, 0, CERCR); /* (write clear) */
2187 ndev->stats.tx_carrier_errors += sh_eth_read(ndev, CEECR);
2188 sh_eth_write(ndev, 0, CEECR); /* (write clear) */
2189 } else {
2190 ndev->stats.tx_carrier_errors += sh_eth_read(ndev, CNDCR);
2191 sh_eth_write(ndev, 0, CNDCR); /* (write clear) */
2192 }
2193 pm_runtime_put_sync(&mdp->pdev->dev);
2194
2195 return &ndev->stats;
2196} 2196}
2197 2197
2198/* ioctl to device function */ 2198/* ioctl to device function */
diff --git a/drivers/net/ethernet/renesas/sh_eth.h b/drivers/net/ethernet/renesas/sh_eth.h
index b37c427144ee..22301bf9c21d 100644
--- a/drivers/net/ethernet/renesas/sh_eth.h
+++ b/drivers/net/ethernet/renesas/sh_eth.h
@@ -162,9 +162,9 @@ enum {
162 162
163/* Driver's parameters */ 163/* Driver's parameters */
164#if defined(CONFIG_CPU_SH4) || defined(CONFIG_ARCH_SHMOBILE) 164#if defined(CONFIG_CPU_SH4) || defined(CONFIG_ARCH_SHMOBILE)
165#define SH4_SKB_RX_ALIGN 32 165#define SH_ETH_RX_ALIGN 32
166#else 166#else
167#define SH2_SH3_SKB_RX_ALIGN 2 167#define SH_ETH_RX_ALIGN 2
168#endif 168#endif
169 169
170/* Register's bits 170/* Register's bits
@@ -522,6 +522,7 @@ struct sh_eth_private {
522 522
523 unsigned no_ether_link:1; 523 unsigned no_ether_link:1;
524 unsigned ether_link_active_low:1; 524 unsigned ether_link_active_low:1;
525 unsigned is_opened:1;
525}; 526};
526 527
527static inline void sh_eth_soft_swap(char *src, int len) 528static inline void sh_eth_soft_swap(char *src, int len)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index db56fa7ce8f9..58a1a0a423d4 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -177,12 +177,6 @@ static int stmmac_probe_config_dt(struct platform_device *pdev,
177 */ 177 */
178 plat->maxmtu = JUMBO_LEN; 178 plat->maxmtu = JUMBO_LEN;
179 179
180 /* Set default value for multicast hash bins */
181 plat->multicast_filter_bins = HASH_TABLE_SIZE;
182
183 /* Set default value for unicast filter entries */
184 plat->unicast_filter_entries = 1;
185
186 /* 180 /*
187 * Currently only the properties needed on SPEAr600 181 * Currently only the properties needed on SPEAr600
188 * are provided. All other properties should be added 182 * are provided. All other properties should be added
@@ -270,16 +264,23 @@ static int stmmac_pltfr_probe(struct platform_device *pdev)
270 return PTR_ERR(addr); 264 return PTR_ERR(addr);
271 265
272 plat_dat = dev_get_platdata(&pdev->dev); 266 plat_dat = dev_get_platdata(&pdev->dev);
273 if (pdev->dev.of_node) { 267
274 if (!plat_dat) 268 if (!plat_dat)
275 plat_dat = devm_kzalloc(&pdev->dev, 269 plat_dat = devm_kzalloc(&pdev->dev,
276 sizeof(struct plat_stmmacenet_data), 270 sizeof(struct plat_stmmacenet_data),
277 GFP_KERNEL); 271 GFP_KERNEL);
278 if (!plat_dat) { 272 if (!plat_dat) {
279 pr_err("%s: ERROR: no memory", __func__); 273 pr_err("%s: ERROR: no memory", __func__);
280 return -ENOMEM; 274 return -ENOMEM;
281 } 275 }
276
277 /* Set default value for multicast hash bins */
278 plat_dat->multicast_filter_bins = HASH_TABLE_SIZE;
282 279
280 /* Set default value for unicast filter entries */
281 plat_dat->unicast_filter_entries = 1;
282
283 if (pdev->dev.of_node) {
283 ret = stmmac_probe_config_dt(pdev, plat_dat, &mac); 284 ret = stmmac_probe_config_dt(pdev, plat_dat, &mac);
284 if (ret) { 285 if (ret) {
285 pr_err("%s: main dt probe failed", __func__); 286 pr_err("%s: main dt probe failed", __func__);
diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
index d8794488f80a..c560f9aeb55d 100644
--- a/drivers/net/ethernet/ti/cpsw.c
+++ b/drivers/net/ethernet/ti/cpsw.c
@@ -129,9 +129,9 @@ do { \
129#define CPSW_VLAN_AWARE BIT(1) 129#define CPSW_VLAN_AWARE BIT(1)
130#define CPSW_ALE_VLAN_AWARE 1 130#define CPSW_ALE_VLAN_AWARE 1
131 131
132#define CPSW_FIFO_NORMAL_MODE (0 << 15) 132#define CPSW_FIFO_NORMAL_MODE (0 << 16)
133#define CPSW_FIFO_DUAL_MAC_MODE (1 << 15) 133#define CPSW_FIFO_DUAL_MAC_MODE (1 << 16)
134#define CPSW_FIFO_RATE_LIMIT_MODE (2 << 15) 134#define CPSW_FIFO_RATE_LIMIT_MODE (2 << 16)
135 135
136#define CPSW_INTPACEEN (0x3f << 16) 136#define CPSW_INTPACEEN (0x3f << 16)
137#define CPSW_INTPRESCALE_MASK (0x7FF << 0) 137#define CPSW_INTPRESCALE_MASK (0x7FF << 0)
diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
index 9ce854f43917..6cbc56ad9ff4 100644
--- a/drivers/net/ieee802154/fakehard.c
+++ b/drivers/net/ieee802154/fakehard.c
@@ -377,17 +377,20 @@ static int ieee802154fake_probe(struct platform_device *pdev)
377 377
378 err = wpan_phy_register(phy); 378 err = wpan_phy_register(phy);
379 if (err) 379 if (err)
380 goto out; 380 goto err_phy_reg;
381 381
382 err = register_netdev(dev); 382 err = register_netdev(dev);
383 if (err < 0) 383 if (err)
384 goto out; 384 goto err_netdev_reg;
385 385
386 dev_info(&pdev->dev, "Added ieee802154 HardMAC hardware\n"); 386 dev_info(&pdev->dev, "Added ieee802154 HardMAC hardware\n");
387 return 0; 387 return 0;
388 388
389out: 389err_netdev_reg:
390 unregister_netdev(dev); 390 wpan_phy_unregister(phy);
391err_phy_reg:
392 free_netdev(dev);
393 wpan_phy_free(phy);
391 return err; 394 return err;
392} 395}
393 396
diff --git a/drivers/net/ppp/pptp.c b/drivers/net/ppp/pptp.c
index 1aff970be33e..1dc628ffce2b 100644
--- a/drivers/net/ppp/pptp.c
+++ b/drivers/net/ppp/pptp.c
@@ -506,7 +506,9 @@ static int pptp_getname(struct socket *sock, struct sockaddr *uaddr,
506 int len = sizeof(struct sockaddr_pppox); 506 int len = sizeof(struct sockaddr_pppox);
507 struct sockaddr_pppox sp; 507 struct sockaddr_pppox sp;
508 508
509 sp.sa_family = AF_PPPOX; 509 memset(&sp.sa_addr, 0, sizeof(sp.sa_addr));
510
511 sp.sa_family = AF_PPPOX;
510 sp.sa_protocol = PX_PROTO_PPTP; 512 sp.sa_protocol = PX_PROTO_PPTP;
511 sp.sa_addr.pptp = pppox_sk(sock->sk)->proto.pptp.src_addr; 513 sp.sa_addr.pptp = pppox_sk(sock->sk)->proto.pptp.src_addr;
512 514
diff --git a/drivers/net/usb/qmi_wwan.c b/drivers/net/usb/qmi_wwan.c
index 22756db53dca..b8a82b86f909 100644
--- a/drivers/net/usb/qmi_wwan.c
+++ b/drivers/net/usb/qmi_wwan.c
@@ -780,6 +780,7 @@ static const struct usb_device_id products[] = {
780 {QMI_FIXED_INTF(0x413c, 0x81a4, 8)}, /* Dell Wireless 5570e HSPA+ (42Mbps) Mobile Broadband Card */ 780 {QMI_FIXED_INTF(0x413c, 0x81a4, 8)}, /* Dell Wireless 5570e HSPA+ (42Mbps) Mobile Broadband Card */
781 {QMI_FIXED_INTF(0x413c, 0x81a8, 8)}, /* Dell Wireless 5808 Gobi(TM) 4G LTE Mobile Broadband Card */ 781 {QMI_FIXED_INTF(0x413c, 0x81a8, 8)}, /* Dell Wireless 5808 Gobi(TM) 4G LTE Mobile Broadband Card */
782 {QMI_FIXED_INTF(0x413c, 0x81a9, 8)}, /* Dell Wireless 5808e Gobi(TM) 4G LTE Mobile Broadband Card */ 782 {QMI_FIXED_INTF(0x413c, 0x81a9, 8)}, /* Dell Wireless 5808e Gobi(TM) 4G LTE Mobile Broadband Card */
783 {QMI_FIXED_INTF(0x03f0, 0x581d, 4)}, /* HP lt4112 LTE/HSPA+ Gobi 4G Module (Huawei me906e) */
783 784
784 /* 4. Gobi 1000 devices */ 785 /* 4. Gobi 1000 devices */
785 {QMI_GOBI1K_DEVICE(0x05c6, 0x9212)}, /* Acer Gobi Modem Device */ 786 {QMI_GOBI1K_DEVICE(0x05c6, 0x9212)}, /* Acer Gobi Modem Device */
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index ec2a8b41ed41..b0bc8ead47de 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -1673,6 +1673,40 @@ static const struct attribute_group virtio_net_mrg_rx_group = {
1673}; 1673};
1674#endif 1674#endif
1675 1675
1676static bool virtnet_fail_on_feature(struct virtio_device *vdev,
1677 unsigned int fbit,
1678 const char *fname, const char *dname)
1679{
1680 if (!virtio_has_feature(vdev, fbit))
1681 return false;
1682
1683 dev_err(&vdev->dev, "device advertises feature %s but not %s",
1684 fname, dname);
1685
1686 return true;
1687}
1688
1689#define VIRTNET_FAIL_ON(vdev, fbit, dbit) \
1690 virtnet_fail_on_feature(vdev, fbit, #fbit, dbit)
1691
1692static bool virtnet_validate_features(struct virtio_device *vdev)
1693{
1694 if (!virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ) &&
1695 (VIRTNET_FAIL_ON(vdev, VIRTIO_NET_F_CTRL_RX,
1696 "VIRTIO_NET_F_CTRL_VQ") ||
1697 VIRTNET_FAIL_ON(vdev, VIRTIO_NET_F_CTRL_VLAN,
1698 "VIRTIO_NET_F_CTRL_VQ") ||
1699 VIRTNET_FAIL_ON(vdev, VIRTIO_NET_F_GUEST_ANNOUNCE,
1700 "VIRTIO_NET_F_CTRL_VQ") ||
1701 VIRTNET_FAIL_ON(vdev, VIRTIO_NET_F_MQ, "VIRTIO_NET_F_CTRL_VQ") ||
1702 VIRTNET_FAIL_ON(vdev, VIRTIO_NET_F_CTRL_MAC_ADDR,
1703 "VIRTIO_NET_F_CTRL_VQ"))) {
1704 return false;
1705 }
1706
1707 return true;
1708}
1709
1676static int virtnet_probe(struct virtio_device *vdev) 1710static int virtnet_probe(struct virtio_device *vdev)
1677{ 1711{
1678 int i, err; 1712 int i, err;
@@ -1680,6 +1714,9 @@ static int virtnet_probe(struct virtio_device *vdev)
1680 struct virtnet_info *vi; 1714 struct virtnet_info *vi;
1681 u16 max_queue_pairs; 1715 u16 max_queue_pairs;
1682 1716
1717 if (!virtnet_validate_features(vdev))
1718 return -EINVAL;
1719
1683 /* Find if host supports multiqueue virtio_net device */ 1720 /* Find if host supports multiqueue virtio_net device */
1684 err = virtio_cread_feature(vdev, VIRTIO_NET_F_MQ, 1721 err = virtio_cread_feature(vdev, VIRTIO_NET_F_MQ,
1685 struct virtio_net_config, 1722 struct virtio_net_config,
diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
index fa9dc45b75a6..be4649a49c5e 100644
--- a/drivers/net/vxlan.c
+++ b/drivers/net/vxlan.c
@@ -67,12 +67,6 @@
67 67
68#define VXLAN_FLAGS 0x08000000 /* struct vxlanhdr.vx_flags required value. */ 68#define VXLAN_FLAGS 0x08000000 /* struct vxlanhdr.vx_flags required value. */
69 69
70/* VXLAN protocol header */
71struct vxlanhdr {
72 __be32 vx_flags;
73 __be32 vx_vni;
74};
75
76/* UDP port for VXLAN traffic. 70/* UDP port for VXLAN traffic.
77 * The IANA assigned port is 4789, but the Linux default is 8472 71 * The IANA assigned port is 4789, but the Linux default is 8472
78 * for compatibility with early adopters. 72 * for compatibility with early adopters.
@@ -2312,9 +2306,9 @@ static struct socket *vxlan_create_sock(struct net *net, bool ipv6,
2312 if (ipv6) { 2306 if (ipv6) {
2313 udp_conf.family = AF_INET6; 2307 udp_conf.family = AF_INET6;
2314 udp_conf.use_udp6_tx_checksums = 2308 udp_conf.use_udp6_tx_checksums =
2315 !!(flags & VXLAN_F_UDP_ZERO_CSUM6_TX); 2309 !(flags & VXLAN_F_UDP_ZERO_CSUM6_TX);
2316 udp_conf.use_udp6_rx_checksums = 2310 udp_conf.use_udp6_rx_checksums =
2317 !!(flags & VXLAN_F_UDP_ZERO_CSUM6_RX); 2311 !(flags & VXLAN_F_UDP_ZERO_CSUM6_RX);
2318 } else { 2312 } else {
2319 udp_conf.family = AF_INET; 2313 udp_conf.family = AF_INET;
2320 udp_conf.local_ip.s_addr = INADDR_ANY; 2314 udp_conf.local_ip.s_addr = INADDR_ANY;
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_phy.c b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
index 697c4ae90af0..1e8ea5e4d4ca 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_phy.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
@@ -664,6 +664,19 @@ static void ar9003_hw_override_ini(struct ath_hw *ah)
664 ah->enabled_cals |= TX_CL_CAL; 664 ah->enabled_cals |= TX_CL_CAL;
665 else 665 else
666 ah->enabled_cals &= ~TX_CL_CAL; 666 ah->enabled_cals &= ~TX_CL_CAL;
667
668 if (AR_SREV_9340(ah) || AR_SREV_9531(ah) || AR_SREV_9550(ah)) {
669 if (ah->is_clk_25mhz) {
670 REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x17c << 1);
671 REG_WRITE(ah, AR_SLP32_MODE, 0x0010f3d7);
672 REG_WRITE(ah, AR_SLP32_INC, 0x0001e7ae);
673 } else {
674 REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x261 << 1);
675 REG_WRITE(ah, AR_SLP32_MODE, 0x0010f400);
676 REG_WRITE(ah, AR_SLP32_INC, 0x0001e800);
677 }
678 udelay(100);
679 }
667} 680}
668 681
669static void ar9003_hw_prog_ini(struct ath_hw *ah, 682static void ar9003_hw_prog_ini(struct ath_hw *ah,
diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c
index 8be4b1453394..2ad605760e21 100644
--- a/drivers/net/wireless/ath/ath9k/hw.c
+++ b/drivers/net/wireless/ath/ath9k/hw.c
@@ -861,19 +861,6 @@ static void ath9k_hw_init_pll(struct ath_hw *ah,
861 udelay(RTC_PLL_SETTLE_DELAY); 861 udelay(RTC_PLL_SETTLE_DELAY);
862 862
863 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK); 863 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
864
865 if (AR_SREV_9340(ah) || AR_SREV_9550(ah)) {
866 if (ah->is_clk_25mhz) {
867 REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x17c << 1);
868 REG_WRITE(ah, AR_SLP32_MODE, 0x0010f3d7);
869 REG_WRITE(ah, AR_SLP32_INC, 0x0001e7ae);
870 } else {
871 REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x261 << 1);
872 REG_WRITE(ah, AR_SLP32_MODE, 0x0010f400);
873 REG_WRITE(ah, AR_SLP32_INC, 0x0001e800);
874 }
875 udelay(100);
876 }
877} 864}
878 865
879static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah, 866static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
index 30c66dfcd7a0..4f18a6be0c7d 100644
--- a/drivers/net/wireless/ath/ath9k/main.c
+++ b/drivers/net/wireless/ath/ath9k/main.c
@@ -974,9 +974,8 @@ void ath9k_calculate_iter_data(struct ath_softc *sc,
974 struct ath_vif *avp; 974 struct ath_vif *avp;
975 975
976 /* 976 /*
977 * Pick the MAC address of the first interface as the new hardware 977 * The hardware will use primary station addr together with the
978 * MAC address. The hardware will use it together with the BSSID mask 978 * BSSID mask when matching addresses.
979 * when matching addresses.
980 */ 979 */
981 memset(iter_data, 0, sizeof(*iter_data)); 980 memset(iter_data, 0, sizeof(*iter_data));
982 memset(&iter_data->mask, 0xff, ETH_ALEN); 981 memset(&iter_data->mask, 0xff, ETH_ALEN);
@@ -1205,6 +1204,8 @@ static int ath9k_add_interface(struct ieee80211_hw *hw,
1205 list_add_tail(&avp->list, &avp->chanctx->vifs); 1204 list_add_tail(&avp->list, &avp->chanctx->vifs);
1206 } 1205 }
1207 1206
1207 ath9k_calculate_summary_state(sc, avp->chanctx);
1208
1208 ath9k_assign_hw_queues(hw, vif); 1209 ath9k_assign_hw_queues(hw, vif);
1209 1210
1210 an->sc = sc; 1211 an->sc = sc;
@@ -1274,6 +1275,8 @@ static void ath9k_remove_interface(struct ieee80211_hw *hw,
1274 1275
1275 ath_tx_node_cleanup(sc, &avp->mcast_node); 1276 ath_tx_node_cleanup(sc, &avp->mcast_node);
1276 1277
1278 ath9k_calculate_summary_state(sc, avp->chanctx);
1279
1277 mutex_unlock(&sc->mutex); 1280 mutex_unlock(&sc->mutex);
1278} 1281}
1279 1282
diff --git a/drivers/net/wireless/b43/phy_common.c b/drivers/net/wireless/b43/phy_common.c
index 1dfc682a8055..ee27b06074e1 100644
--- a/drivers/net/wireless/b43/phy_common.c
+++ b/drivers/net/wireless/b43/phy_common.c
@@ -300,9 +300,7 @@ void b43_phy_write(struct b43_wldev *dev, u16 reg, u16 value)
300 300
301void b43_phy_copy(struct b43_wldev *dev, u16 destreg, u16 srcreg) 301void b43_phy_copy(struct b43_wldev *dev, u16 destreg, u16 srcreg)
302{ 302{
303 assert_mac_suspended(dev); 303 b43_phy_write(dev, destreg, b43_phy_read(dev, srcreg));
304 dev->phy.ops->phy_write(dev, destreg,
305 dev->phy.ops->phy_read(dev, srcreg));
306} 304}
307 305
308void b43_phy_mask(struct b43_wldev *dev, u16 offset, u16 mask) 306void b43_phy_mask(struct b43_wldev *dev, u16 offset, u16 mask)
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/of.c b/drivers/net/wireless/brcm80211/brcmfmac/of.c
index f05f5270fec1..927bffd5be64 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/of.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/of.c
@@ -40,8 +40,8 @@ void brcmf_of_probe(struct brcmf_sdio_dev *sdiodev)
40 return; 40 return;
41 41
42 irq = irq_of_parse_and_map(np, 0); 42 irq = irq_of_parse_and_map(np, 0);
43 if (irq < 0) { 43 if (!irq) {
44 brcmf_err("interrupt could not be mapped: err=%d\n", irq); 44 brcmf_err("interrupt could not be mapped\n");
45 devm_kfree(dev, sdiodev->pdata); 45 devm_kfree(dev, sdiodev->pdata);
46 return; 46 return;
47 } 47 }
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/brcm80211/brcmfmac/pcie.c
index 8c0632ec9f7a..16fef3382019 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/pcie.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/pcie.c
@@ -19,10 +19,10 @@
19#include <linux/pci.h> 19#include <linux/pci.h>
20#include <linux/vmalloc.h> 20#include <linux/vmalloc.h>
21#include <linux/delay.h> 21#include <linux/delay.h>
22#include <linux/unaligned/access_ok.h>
23#include <linux/interrupt.h> 22#include <linux/interrupt.h>
24#include <linux/bcma/bcma.h> 23#include <linux/bcma/bcma.h>
25#include <linux/sched.h> 24#include <linux/sched.h>
25#include <asm/unaligned.h>
26 26
27#include <soc.h> 27#include <soc.h>
28#include <chipcommon.h> 28#include <chipcommon.h>
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/usb.c b/drivers/net/wireless/brcm80211/brcmfmac/usb.c
index dc135915470d..875d1142c8b0 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/usb.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/usb.c
@@ -669,10 +669,12 @@ static int brcmf_usb_dl_cmd(struct brcmf_usbdev_info *devinfo, u8 cmd,
669 goto finalize; 669 goto finalize;
670 } 670 }
671 671
672 if (!brcmf_usb_ioctl_resp_wait(devinfo)) 672 if (!brcmf_usb_ioctl_resp_wait(devinfo)) {
673 usb_kill_urb(devinfo->ctl_urb);
673 ret = -ETIMEDOUT; 674 ret = -ETIMEDOUT;
674 else 675 } else {
675 memcpy(buffer, tmpbuf, buflen); 676 memcpy(buffer, tmpbuf, buflen);
677 }
676 678
677finalize: 679finalize:
678 kfree(tmpbuf); 680 kfree(tmpbuf);
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
index 28fa25b509db..39b45c038a93 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
@@ -299,6 +299,7 @@ static u16 chandef_to_chanspec(struct brcmu_d11inf *d11inf,
299 primary_offset = ch->center_freq1 - ch->chan->center_freq; 299 primary_offset = ch->center_freq1 - ch->chan->center_freq;
300 switch (ch->width) { 300 switch (ch->width) {
301 case NL80211_CHAN_WIDTH_20: 301 case NL80211_CHAN_WIDTH_20:
302 case NL80211_CHAN_WIDTH_20_NOHT:
302 ch_inf.bw = BRCMU_CHAN_BW_20; 303 ch_inf.bw = BRCMU_CHAN_BW_20;
303 WARN_ON(primary_offset != 0); 304 WARN_ON(primary_offset != 0);
304 break; 305 break;
@@ -323,6 +324,10 @@ static u16 chandef_to_chanspec(struct brcmu_d11inf *d11inf,
323 ch_inf.sb = BRCMU_CHAN_SB_LU; 324 ch_inf.sb = BRCMU_CHAN_SB_LU;
324 } 325 }
325 break; 326 break;
327 case NL80211_CHAN_WIDTH_80P80:
328 case NL80211_CHAN_WIDTH_160:
329 case NL80211_CHAN_WIDTH_5:
330 case NL80211_CHAN_WIDTH_10:
326 default: 331 default:
327 WARN_ON_ONCE(1); 332 WARN_ON_ONCE(1);
328 } 333 }
@@ -333,6 +338,7 @@ static u16 chandef_to_chanspec(struct brcmu_d11inf *d11inf,
333 case IEEE80211_BAND_5GHZ: 338 case IEEE80211_BAND_5GHZ:
334 ch_inf.band = BRCMU_CHAN_BAND_5G; 339 ch_inf.band = BRCMU_CHAN_BAND_5G;
335 break; 340 break;
341 case IEEE80211_BAND_60GHZ:
336 default: 342 default:
337 WARN_ON_ONCE(1); 343 WARN_ON_ONCE(1);
338 } 344 }
diff --git a/drivers/net/wireless/iwlwifi/iwl-fw.h b/drivers/net/wireless/iwlwifi/iwl-fw.h
index 4f6e66892acc..b894a84e8393 100644
--- a/drivers/net/wireless/iwlwifi/iwl-fw.h
+++ b/drivers/net/wireless/iwlwifi/iwl-fw.h
@@ -155,6 +155,7 @@ enum iwl_ucode_tlv_api {
155 * @IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT: supports Quiet Period requests 155 * @IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT: supports Quiet Period requests
156 * @IWL_UCODE_TLV_CAPA_DQA_SUPPORT: supports dynamic queue allocation (DQA), 156 * @IWL_UCODE_TLV_CAPA_DQA_SUPPORT: supports dynamic queue allocation (DQA),
157 * which also implies support for the scheduler configuration command 157 * which also implies support for the scheduler configuration command
158 * @IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT: supports Hot Spot Command
158 */ 159 */
159enum iwl_ucode_tlv_capa { 160enum iwl_ucode_tlv_capa {
160 IWL_UCODE_TLV_CAPA_D0I3_SUPPORT = BIT(0), 161 IWL_UCODE_TLV_CAPA_D0I3_SUPPORT = BIT(0),
@@ -163,6 +164,7 @@ enum iwl_ucode_tlv_capa {
163 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT = BIT(10), 164 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT = BIT(10),
164 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT = BIT(11), 165 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT = BIT(11),
165 IWL_UCODE_TLV_CAPA_DQA_SUPPORT = BIT(12), 166 IWL_UCODE_TLV_CAPA_DQA_SUPPORT = BIT(12),
167 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT = BIT(18),
166}; 168};
167 169
168/* The default calibrate table size if not specified by firmware file */ 170/* The default calibrate table size if not specified by firmware file */
diff --git a/drivers/net/wireless/iwlwifi/mvm/mac80211.c b/drivers/net/wireless/iwlwifi/mvm/mac80211.c
index b62405865b25..b6d2683da3a9 100644
--- a/drivers/net/wireless/iwlwifi/mvm/mac80211.c
+++ b/drivers/net/wireless/iwlwifi/mvm/mac80211.c
@@ -2448,9 +2448,15 @@ static int iwl_mvm_roc(struct ieee80211_hw *hw,
2448 2448
2449 switch (vif->type) { 2449 switch (vif->type) {
2450 case NL80211_IFTYPE_STATION: 2450 case NL80211_IFTYPE_STATION:
2451 /* Use aux roc framework (HS20) */ 2451 if (mvm->fw->ucode_capa.capa[0] &
2452 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel, 2452 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT) {
2453 vif, duration); 2453 /* Use aux roc framework (HS20) */
2454 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
2455 vif, duration);
2456 goto out_unlock;
2457 }
2458 IWL_ERR(mvm, "hotspot not supported\n");
2459 ret = -EINVAL;
2454 goto out_unlock; 2460 goto out_unlock;
2455 case NL80211_IFTYPE_P2P_DEVICE: 2461 case NL80211_IFTYPE_P2P_DEVICE:
2456 /* handle below */ 2462 /* handle below */
diff --git a/drivers/net/wireless/iwlwifi/mvm/scan.c b/drivers/net/wireless/iwlwifi/mvm/scan.c
index b280d5d87127..7554f7053830 100644
--- a/drivers/net/wireless/iwlwifi/mvm/scan.c
+++ b/drivers/net/wireless/iwlwifi/mvm/scan.c
@@ -602,16 +602,6 @@ static int iwl_mvm_cancel_regular_scan(struct iwl_mvm *mvm)
602 SCAN_COMPLETE_NOTIFICATION }; 602 SCAN_COMPLETE_NOTIFICATION };
603 int ret; 603 int ret;
604 604
605 if (mvm->scan_status == IWL_MVM_SCAN_NONE)
606 return 0;
607
608 if (iwl_mvm_is_radio_killed(mvm)) {
609 ieee80211_scan_completed(mvm->hw, true);
610 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
611 mvm->scan_status = IWL_MVM_SCAN_NONE;
612 return 0;
613 }
614
615 iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_abort, 605 iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_abort,
616 scan_abort_notif, 606 scan_abort_notif,
617 ARRAY_SIZE(scan_abort_notif), 607 ARRAY_SIZE(scan_abort_notif),
@@ -1400,6 +1390,16 @@ int iwl_mvm_unified_sched_scan_lmac(struct iwl_mvm *mvm,
1400 1390
1401int iwl_mvm_cancel_scan(struct iwl_mvm *mvm) 1391int iwl_mvm_cancel_scan(struct iwl_mvm *mvm)
1402{ 1392{
1393 if (mvm->scan_status == IWL_MVM_SCAN_NONE)
1394 return 0;
1395
1396 if (iwl_mvm_is_radio_killed(mvm)) {
1397 ieee80211_scan_completed(mvm->hw, true);
1398 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
1399 mvm->scan_status = IWL_MVM_SCAN_NONE;
1400 return 0;
1401 }
1402
1403 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN) 1403 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)
1404 return iwl_mvm_scan_offload_stop(mvm, true); 1404 return iwl_mvm_scan_offload_stop(mvm, true);
1405 return iwl_mvm_cancel_regular_scan(mvm); 1405 return iwl_mvm_cancel_regular_scan(mvm);
diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
index 160c3ebc48d0..dd2f3f8baa9d 100644
--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
@@ -1894,8 +1894,7 @@ static u32 iwl_trans_pcie_dump_prph(struct iwl_trans *trans,
1894 int reg; 1894 int reg;
1895 __le32 *val; 1895 __le32 *val;
1896 1896
1897 prph_len += sizeof(*data) + sizeof(*prph) + 1897 prph_len += sizeof(**data) + sizeof(*prph) + num_bytes_in_chunk;
1898 num_bytes_in_chunk;
1899 1898
1900 (*data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_PRPH); 1899 (*data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_PRPH);
1901 (*data)->len = cpu_to_le32(sizeof(*prph) + 1900 (*data)->len = cpu_to_le32(sizeof(*prph) +
diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
index 8e68f87ab13c..66ff36447b94 100644
--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
@@ -158,55 +158,29 @@ void rt2x00queue_align_frame(struct sk_buff *skb)
158 skb_trim(skb, frame_length); 158 skb_trim(skb, frame_length);
159} 159}
160 160
161void rt2x00queue_insert_l2pad(struct sk_buff *skb, unsigned int header_length) 161/*
162 * H/W needs L2 padding between the header and the paylod if header size
163 * is not 4 bytes aligned.
164 */
165void rt2x00queue_insert_l2pad(struct sk_buff *skb, unsigned int hdr_len)
162{ 166{
163 unsigned int payload_length = skb->len - header_length; 167 unsigned int l2pad = (skb->len > hdr_len) ? L2PAD_SIZE(hdr_len) : 0;
164 unsigned int header_align = ALIGN_SIZE(skb, 0);
165 unsigned int payload_align = ALIGN_SIZE(skb, header_length);
166 unsigned int l2pad = payload_length ? L2PAD_SIZE(header_length) : 0;
167 168
168 /* 169 if (!l2pad)
169 * Adjust the header alignment if the payload needs to be moved more
170 * than the header.
171 */
172 if (payload_align > header_align)
173 header_align += 4;
174
175 /* There is nothing to do if no alignment is needed */
176 if (!header_align)
177 return; 170 return;
178 171
179 /* Reserve the amount of space needed in front of the frame */ 172 skb_push(skb, l2pad);
180 skb_push(skb, header_align); 173 memmove(skb->data, skb->data + l2pad, hdr_len);
181
182 /*
183 * Move the header.
184 */
185 memmove(skb->data, skb->data + header_align, header_length);
186
187 /* Move the payload, if present and if required */
188 if (payload_length && payload_align)
189 memmove(skb->data + header_length + l2pad,
190 skb->data + header_length + l2pad + payload_align,
191 payload_length);
192
193 /* Trim the skb to the correct size */
194 skb_trim(skb, header_length + l2pad + payload_length);
195} 174}
196 175
197void rt2x00queue_remove_l2pad(struct sk_buff *skb, unsigned int header_length) 176void rt2x00queue_remove_l2pad(struct sk_buff *skb, unsigned int hdr_len)
198{ 177{
199 /* 178 unsigned int l2pad = (skb->len > hdr_len) ? L2PAD_SIZE(hdr_len) : 0;
200 * L2 padding is only present if the skb contains more than just the
201 * IEEE 802.11 header.
202 */
203 unsigned int l2pad = (skb->len > header_length) ?
204 L2PAD_SIZE(header_length) : 0;
205 179
206 if (!l2pad) 180 if (!l2pad)
207 return; 181 return;
208 182
209 memmove(skb->data + l2pad, skb->data, header_length); 183 memmove(skb->data + l2pad, skb->data, hdr_len);
210 skb_pull(skb, l2pad); 184 skb_pull(skb, l2pad);
211} 185}
212 186
diff --git a/drivers/net/wireless/rtlwifi/pci.c b/drivers/net/wireless/rtlwifi/pci.c
index 25daa8715219..846a2e6e34d8 100644
--- a/drivers/net/wireless/rtlwifi/pci.c
+++ b/drivers/net/wireless/rtlwifi/pci.c
@@ -842,7 +842,8 @@ static void _rtl_pci_rx_interrupt(struct ieee80211_hw *hw)
842 break; 842 break;
843 } 843 }
844 /* handle command packet here */ 844 /* handle command packet here */
845 if (rtlpriv->cfg->ops->rx_command_packet(hw, stats, skb)) { 845 if (rtlpriv->cfg->ops->rx_command_packet &&
846 rtlpriv->cfg->ops->rx_command_packet(hw, stats, skb)) {
846 dev_kfree_skb_any(skb); 847 dev_kfree_skb_any(skb);
847 goto end; 848 goto end;
848 } 849 }
@@ -1127,9 +1128,14 @@ static void _rtl_pci_prepare_bcn_tasklet(struct ieee80211_hw *hw)
1127 1128
1128 __skb_queue_tail(&ring->queue, pskb); 1129 __skb_queue_tail(&ring->queue, pskb);
1129 1130
1130 rtlpriv->cfg->ops->set_desc(hw, (u8 *)pdesc, true, HW_DESC_OWN, 1131 if (rtlpriv->use_new_trx_flow) {
1131 &temp_one); 1132 temp_one = 4;
1132 1133 rtlpriv->cfg->ops->set_desc(hw, (u8 *)pbuffer_desc, true,
1134 HW_DESC_OWN, (u8 *)&temp_one);
1135 } else {
1136 rtlpriv->cfg->ops->set_desc(hw, (u8 *)pdesc, true, HW_DESC_OWN,
1137 &temp_one);
1138 }
1133 return; 1139 return;
1134} 1140}
1135 1141
@@ -1370,9 +1376,9 @@ static void _rtl_pci_free_tx_ring(struct ieee80211_hw *hw,
1370 ring->desc = NULL; 1376 ring->desc = NULL;
1371 if (rtlpriv->use_new_trx_flow) { 1377 if (rtlpriv->use_new_trx_flow) {
1372 pci_free_consistent(rtlpci->pdev, 1378 pci_free_consistent(rtlpci->pdev,
1373 sizeof(*ring->desc) * ring->entries, 1379 sizeof(*ring->buffer_desc) * ring->entries,
1374 ring->buffer_desc, ring->buffer_desc_dma); 1380 ring->buffer_desc, ring->buffer_desc_dma);
1375 ring->desc = NULL; 1381 ring->buffer_desc = NULL;
1376 } 1382 }
1377} 1383}
1378 1384
@@ -1543,7 +1549,6 @@ int rtl_pci_reset_trx_ring(struct ieee80211_hw *hw)
1543 true, 1549 true,
1544 HW_DESC_TXBUFF_ADDR), 1550 HW_DESC_TXBUFF_ADDR),
1545 skb->len, PCI_DMA_TODEVICE); 1551 skb->len, PCI_DMA_TODEVICE);
1546 ring->idx = (ring->idx + 1) % ring->entries;
1547 kfree_skb(skb); 1552 kfree_skb(skb);
1548 ring->idx = (ring->idx + 1) % ring->entries; 1553 ring->idx = (ring->idx + 1) % ring->entries;
1549 } 1554 }
@@ -2244,6 +2249,16 @@ int rtl_pci_probe(struct pci_dev *pdev,
2244 /*like read eeprom and so on */ 2249 /*like read eeprom and so on */
2245 rtlpriv->cfg->ops->read_eeprom_info(hw); 2250 rtlpriv->cfg->ops->read_eeprom_info(hw);
2246 2251
2252 if (rtlpriv->cfg->ops->init_sw_vars(hw)) {
2253 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "Can't init_sw_vars\n");
2254 err = -ENODEV;
2255 goto fail3;
2256 }
2257 rtlpriv->cfg->ops->init_sw_leds(hw);
2258
2259 /*aspm */
2260 rtl_pci_init_aspm(hw);
2261
2247 /* Init mac80211 sw */ 2262 /* Init mac80211 sw */
2248 err = rtl_init_core(hw); 2263 err = rtl_init_core(hw);
2249 if (err) { 2264 if (err) {
@@ -2259,16 +2274,6 @@ int rtl_pci_probe(struct pci_dev *pdev,
2259 goto fail3; 2274 goto fail3;
2260 } 2275 }
2261 2276
2262 if (rtlpriv->cfg->ops->init_sw_vars(hw)) {
2263 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "Can't init_sw_vars\n");
2264 err = -ENODEV;
2265 goto fail3;
2266 }
2267 rtlpriv->cfg->ops->init_sw_leds(hw);
2268
2269 /*aspm */
2270 rtl_pci_init_aspm(hw);
2271
2272 err = ieee80211_register_hw(hw); 2277 err = ieee80211_register_hw(hw);
2273 if (err) { 2278 if (err) {
2274 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, 2279 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
diff --git a/drivers/net/wireless/rtlwifi/rtl8192se/hw.c b/drivers/net/wireless/rtlwifi/rtl8192se/hw.c
index 00e067044c08..5761d5b49e39 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192se/hw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192se/hw.c
@@ -1201,6 +1201,9 @@ static int _rtl92se_set_media_status(struct ieee80211_hw *hw,
1201 1201
1202 } 1202 }
1203 1203
1204 if (type != NL80211_IFTYPE_AP &&
1205 rtlpriv->mac80211.link_state < MAC80211_LINKED)
1206 bt_msr = rtl_read_byte(rtlpriv, MSR) & ~MSR_LINK_MASK;
1204 rtl_write_byte(rtlpriv, (MSR), bt_msr); 1207 rtl_write_byte(rtlpriv, (MSR), bt_msr);
1205 1208
1206 temp = rtl_read_dword(rtlpriv, TCR); 1209 temp = rtl_read_dword(rtlpriv, TCR);
@@ -1262,6 +1265,7 @@ void rtl92se_enable_interrupt(struct ieee80211_hw *hw)
1262 rtl_write_dword(rtlpriv, INTA_MASK, rtlpci->irq_mask[0]); 1265 rtl_write_dword(rtlpriv, INTA_MASK, rtlpci->irq_mask[0]);
1263 /* Support Bit 32-37(Assign as Bit 0-5) interrupt setting now */ 1266 /* Support Bit 32-37(Assign as Bit 0-5) interrupt setting now */
1264 rtl_write_dword(rtlpriv, INTA_MASK + 4, rtlpci->irq_mask[1] & 0x3F); 1267 rtl_write_dword(rtlpriv, INTA_MASK + 4, rtlpci->irq_mask[1] & 0x3F);
1268 rtlpci->irq_enabled = true;
1265} 1269}
1266 1270
1267void rtl92se_disable_interrupt(struct ieee80211_hw *hw) 1271void rtl92se_disable_interrupt(struct ieee80211_hw *hw)
@@ -1276,8 +1280,7 @@ void rtl92se_disable_interrupt(struct ieee80211_hw *hw)
1276 rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 1280 rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1277 rtl_write_dword(rtlpriv, INTA_MASK, 0); 1281 rtl_write_dword(rtlpriv, INTA_MASK, 0);
1278 rtl_write_dword(rtlpriv, INTA_MASK + 4, 0); 1282 rtl_write_dword(rtlpriv, INTA_MASK + 4, 0);
1279 1283 rtlpci->irq_enabled = false;
1280 synchronize_irq(rtlpci->pdev->irq);
1281} 1284}
1282 1285
1283static u8 _rtl92s_set_sysclk(struct ieee80211_hw *hw, u8 data) 1286static u8 _rtl92s_set_sysclk(struct ieee80211_hw *hw, u8 data)
diff --git a/drivers/net/wireless/rtlwifi/rtl8192se/phy.c b/drivers/net/wireless/rtlwifi/rtl8192se/phy.c
index 77c5b5f35244..4b4612fe2fdb 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192se/phy.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192se/phy.c
@@ -399,6 +399,8 @@ static bool _rtl92s_phy_sw_chnl_step_by_step(struct ieee80211_hw *hw,
399 case 2: 399 case 2:
400 currentcmd = &postcommoncmd[*step]; 400 currentcmd = &postcommoncmd[*step];
401 break; 401 break;
402 default:
403 return true;
402 } 404 }
403 405
404 if (currentcmd->cmdid == CMDID_END) { 406 if (currentcmd->cmdid == CMDID_END) {
diff --git a/drivers/net/wireless/rtlwifi/rtl8192se/sw.c b/drivers/net/wireless/rtlwifi/rtl8192se/sw.c
index aadba29c167a..fb003868bdef 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192se/sw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192se/sw.c
@@ -236,6 +236,19 @@ static void rtl92s_deinit_sw_vars(struct ieee80211_hw *hw)
236 } 236 }
237} 237}
238 238
239static bool rtl92se_is_tx_desc_closed(struct ieee80211_hw *hw, u8 hw_queue,
240 u16 index)
241{
242 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
243 struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[hw_queue];
244 u8 *entry = (u8 *)(&ring->desc[ring->idx]);
245 u8 own = (u8)rtl92se_get_desc(entry, true, HW_DESC_OWN);
246
247 if (own)
248 return false;
249 return true;
250}
251
239static struct rtl_hal_ops rtl8192se_hal_ops = { 252static struct rtl_hal_ops rtl8192se_hal_ops = {
240 .init_sw_vars = rtl92s_init_sw_vars, 253 .init_sw_vars = rtl92s_init_sw_vars,
241 .deinit_sw_vars = rtl92s_deinit_sw_vars, 254 .deinit_sw_vars = rtl92s_deinit_sw_vars,
@@ -269,6 +282,7 @@ static struct rtl_hal_ops rtl8192se_hal_ops = {
269 .led_control = rtl92se_led_control, 282 .led_control = rtl92se_led_control,
270 .set_desc = rtl92se_set_desc, 283 .set_desc = rtl92se_set_desc,
271 .get_desc = rtl92se_get_desc, 284 .get_desc = rtl92se_get_desc,
285 .is_tx_desc_closed = rtl92se_is_tx_desc_closed,
272 .tx_polling = rtl92se_tx_polling, 286 .tx_polling = rtl92se_tx_polling,
273 .enable_hw_sec = rtl92se_enable_hw_security_config, 287 .enable_hw_sec = rtl92se_enable_hw_security_config,
274 .set_key = rtl92se_set_key, 288 .set_key = rtl92se_set_key,
@@ -306,6 +320,8 @@ static struct rtl_hal_cfg rtl92se_hal_cfg = {
306 .maps[MAC_RCR_ACRC32] = RCR_ACRC32, 320 .maps[MAC_RCR_ACRC32] = RCR_ACRC32,
307 .maps[MAC_RCR_ACF] = RCR_ACF, 321 .maps[MAC_RCR_ACF] = RCR_ACF,
308 .maps[MAC_RCR_AAP] = RCR_AAP, 322 .maps[MAC_RCR_AAP] = RCR_AAP,
323 .maps[MAC_HIMR] = INTA_MASK,
324 .maps[MAC_HIMRE] = INTA_MASK + 4,
309 325
310 .maps[EFUSE_TEST] = REG_EFUSE_TEST, 326 .maps[EFUSE_TEST] = REG_EFUSE_TEST,
311 .maps[EFUSE_CTRL] = REG_EFUSE_CTRL, 327 .maps[EFUSE_CTRL] = REG_EFUSE_CTRL,
diff --git a/drivers/net/wireless/rtlwifi/rtl8821ae/hw.c b/drivers/net/wireless/rtlwifi/rtl8821ae/hw.c
index 310d3163dc5b..8ec8200002c7 100644
--- a/drivers/net/wireless/rtlwifi/rtl8821ae/hw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8821ae/hw.c
@@ -3672,8 +3672,9 @@ static void rtl8821ae_update_hal_rate_mask(struct ieee80211_hw *hw,
3672 mac->opmode == NL80211_IFTYPE_ADHOC) 3672 mac->opmode == NL80211_IFTYPE_ADHOC)
3673 macid = sta->aid + 1; 3673 macid = sta->aid + 1;
3674 if (wirelessmode == WIRELESS_MODE_N_5G || 3674 if (wirelessmode == WIRELESS_MODE_N_5G ||
3675 wirelessmode == WIRELESS_MODE_AC_5G) 3675 wirelessmode == WIRELESS_MODE_AC_5G ||
3676 ratr_bitmap = sta->supp_rates[NL80211_BAND_5GHZ]; 3676 wirelessmode == WIRELESS_MODE_A)
3677 ratr_bitmap = sta->supp_rates[NL80211_BAND_5GHZ] << 4;
3677 else 3678 else
3678 ratr_bitmap = sta->supp_rates[NL80211_BAND_2GHZ]; 3679 ratr_bitmap = sta->supp_rates[NL80211_BAND_2GHZ];
3679 3680
diff --git a/drivers/net/xen-netback/xenbus.c b/drivers/net/xen-netback/xenbus.c
index 4e56a27f9689..fab0d4b42f58 100644
--- a/drivers/net/xen-netback/xenbus.c
+++ b/drivers/net/xen-netback/xenbus.c
@@ -39,7 +39,7 @@ struct backend_info {
39static int connect_rings(struct backend_info *be, struct xenvif_queue *queue); 39static int connect_rings(struct backend_info *be, struct xenvif_queue *queue);
40static void connect(struct backend_info *be); 40static void connect(struct backend_info *be);
41static int read_xenbus_vif_flags(struct backend_info *be); 41static int read_xenbus_vif_flags(struct backend_info *be);
42static void backend_create_xenvif(struct backend_info *be); 42static int backend_create_xenvif(struct backend_info *be);
43static void unregister_hotplug_status_watch(struct backend_info *be); 43static void unregister_hotplug_status_watch(struct backend_info *be);
44static void set_backend_state(struct backend_info *be, 44static void set_backend_state(struct backend_info *be,
45 enum xenbus_state state); 45 enum xenbus_state state);
@@ -352,7 +352,9 @@ static int netback_probe(struct xenbus_device *dev,
352 be->state = XenbusStateInitWait; 352 be->state = XenbusStateInitWait;
353 353
354 /* This kicks hotplug scripts, so do it immediately. */ 354 /* This kicks hotplug scripts, so do it immediately. */
355 backend_create_xenvif(be); 355 err = backend_create_xenvif(be);
356 if (err)
357 goto fail;
356 358
357 return 0; 359 return 0;
358 360
@@ -397,19 +399,19 @@ static int netback_uevent(struct xenbus_device *xdev,
397} 399}
398 400
399 401
400static void backend_create_xenvif(struct backend_info *be) 402static int backend_create_xenvif(struct backend_info *be)
401{ 403{
402 int err; 404 int err;
403 long handle; 405 long handle;
404 struct xenbus_device *dev = be->dev; 406 struct xenbus_device *dev = be->dev;
405 407
406 if (be->vif != NULL) 408 if (be->vif != NULL)
407 return; 409 return 0;
408 410
409 err = xenbus_scanf(XBT_NIL, dev->nodename, "handle", "%li", &handle); 411 err = xenbus_scanf(XBT_NIL, dev->nodename, "handle", "%li", &handle);
410 if (err != 1) { 412 if (err != 1) {
411 xenbus_dev_fatal(dev, err, "reading handle"); 413 xenbus_dev_fatal(dev, err, "reading handle");
412 return; 414 return (err < 0) ? err : -EINVAL;
413 } 415 }
414 416
415 be->vif = xenvif_alloc(&dev->dev, dev->otherend_id, handle); 417 be->vif = xenvif_alloc(&dev->dev, dev->otherend_id, handle);
@@ -417,10 +419,11 @@ static void backend_create_xenvif(struct backend_info *be)
417 err = PTR_ERR(be->vif); 419 err = PTR_ERR(be->vif);
418 be->vif = NULL; 420 be->vif = NULL;
419 xenbus_dev_fatal(dev, err, "creating interface"); 421 xenbus_dev_fatal(dev, err, "creating interface");
420 return; 422 return err;
421 } 423 }
422 424
423 kobject_uevent(&dev->dev.kobj, KOBJ_ONLINE); 425 kobject_uevent(&dev->dev.kobj, KOBJ_ONLINE);
426 return 0;
424} 427}
425 428
426static void backend_disconnect(struct backend_info *be) 429static void backend_disconnect(struct backend_info *be)
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index cca871346a0f..ece8d1804d13 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -496,9 +496,6 @@ static void xennet_make_frags(struct sk_buff *skb, struct netfront_queue *queue,
496 len = skb_frag_size(frag); 496 len = skb_frag_size(frag);
497 offset = frag->page_offset; 497 offset = frag->page_offset;
498 498
499 /* Data must not cross a page boundary. */
500 BUG_ON(len + offset > PAGE_SIZE<<compound_order(page));
501
502 /* Skip unused frames from start of page */ 499 /* Skip unused frames from start of page */
503 page += offset >> PAGE_SHIFT; 500 page += offset >> PAGE_SHIFT;
504 offset &= ~PAGE_MASK; 501 offset &= ~PAGE_MASK;
@@ -506,8 +503,6 @@ static void xennet_make_frags(struct sk_buff *skb, struct netfront_queue *queue,
506 while (len > 0) { 503 while (len > 0) {
507 unsigned long bytes; 504 unsigned long bytes;
508 505
509 BUG_ON(offset >= PAGE_SIZE);
510
511 bytes = PAGE_SIZE - offset; 506 bytes = PAGE_SIZE - offset;
512 if (bytes > len) 507 if (bytes > len)
513 bytes = len; 508 bytes = len;
diff --git a/drivers/of/address.c b/drivers/of/address.c
index afdb78299f61..06af494184d6 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -450,6 +450,21 @@ static struct of_bus *of_match_bus(struct device_node *np)
450 return NULL; 450 return NULL;
451} 451}
452 452
453static int of_empty_ranges_quirk(void)
454{
455 if (IS_ENABLED(CONFIG_PPC)) {
456 /* To save cycles, we cache the result */
457 static int quirk_state = -1;
458
459 if (quirk_state < 0)
460 quirk_state =
461 of_machine_is_compatible("Power Macintosh") ||
462 of_machine_is_compatible("MacRISC");
463 return quirk_state;
464 }
465 return false;
466}
467
453static int of_translate_one(struct device_node *parent, struct of_bus *bus, 468static int of_translate_one(struct device_node *parent, struct of_bus *bus,
454 struct of_bus *pbus, __be32 *addr, 469 struct of_bus *pbus, __be32 *addr,
455 int na, int ns, int pna, const char *rprop) 470 int na, int ns, int pna, const char *rprop)
@@ -475,12 +490,10 @@ static int of_translate_one(struct device_node *parent, struct of_bus *bus,
475 * This code is only enabled on powerpc. --gcl 490 * This code is only enabled on powerpc. --gcl
476 */ 491 */
477 ranges = of_get_property(parent, rprop, &rlen); 492 ranges = of_get_property(parent, rprop, &rlen);
478#if !defined(CONFIG_PPC) 493 if (ranges == NULL && !of_empty_ranges_quirk()) {
479 if (ranges == NULL) {
480 pr_err("OF: no ranges; cannot translate\n"); 494 pr_err("OF: no ranges; cannot translate\n");
481 return 1; 495 return 1;
482 } 496 }
483#endif /* !defined(CONFIG_PPC) */
484 if (ranges == NULL || rlen == 0) { 497 if (ranges == NULL || rlen == 0) {
485 offset = of_read_number(addr, na); 498 offset = of_read_number(addr, na);
486 memset(addr, 0, pna * 4); 499 memset(addr, 0, pna * 4);
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 3823edf2d012..4c2ccde42427 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1250,6 +1250,39 @@ int of_property_read_u64(const struct device_node *np, const char *propname,
1250EXPORT_SYMBOL_GPL(of_property_read_u64); 1250EXPORT_SYMBOL_GPL(of_property_read_u64);
1251 1251
1252/** 1252/**
1253 * of_property_read_u64_array - Find and read an array of 64 bit integers
1254 * from a property.
1255 *
1256 * @np: device node from which the property value is to be read.
1257 * @propname: name of the property to be searched.
1258 * @out_values: pointer to return value, modified only if return value is 0.
1259 * @sz: number of array elements to read
1260 *
1261 * Search for a property in a device node and read 64-bit value(s) from
1262 * it. Returns 0 on success, -EINVAL if the property does not exist,
1263 * -ENODATA if property does not have a value, and -EOVERFLOW if the
1264 * property data isn't large enough.
1265 *
1266 * The out_values is modified only if a valid u64 value can be decoded.
1267 */
1268int of_property_read_u64_array(const struct device_node *np,
1269 const char *propname, u64 *out_values,
1270 size_t sz)
1271{
1272 const __be32 *val = of_find_property_value_of_size(np, propname,
1273 (sz * sizeof(*out_values)));
1274
1275 if (IS_ERR(val))
1276 return PTR_ERR(val);
1277
1278 while (sz--) {
1279 *out_values++ = of_read_number(val, 2);
1280 val += 2;
1281 }
1282 return 0;
1283}
1284
1285/**
1253 * of_property_read_string - Find and read a string from a property 1286 * of_property_read_string - Find and read a string from a property
1254 * @np: device node from which the property value is to be read. 1287 * @np: device node from which the property value is to be read.
1255 * @propname: name of the property to be searched. 1288 * @propname: name of the property to be searched.
diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c
index f297891d8529..d4994177dec2 100644
--- a/drivers/of/dynamic.c
+++ b/drivers/of/dynamic.c
@@ -247,7 +247,7 @@ void of_node_release(struct kobject *kobj)
247 * @allocflags: Allocation flags (typically pass GFP_KERNEL) 247 * @allocflags: Allocation flags (typically pass GFP_KERNEL)
248 * 248 *
249 * Copy a property by dynamically allocating the memory of both the 249 * Copy a property by dynamically allocating the memory of both the
250 * property stucture and the property name & contents. The property's 250 * property structure and the property name & contents. The property's
251 * flags have the OF_DYNAMIC bit set so that we can differentiate between 251 * flags have the OF_DYNAMIC bit set so that we can differentiate between
252 * dynamically allocated properties and not. 252 * dynamically allocated properties and not.
253 * Returns the newly allocated property or NULL on out of memory error. 253 * Returns the newly allocated property or NULL on out of memory error.
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index d1ffca8b34ea..d134710de96d 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -773,7 +773,7 @@ int __init early_init_dt_scan_chosen_serial(void)
773 if (offset < 0) 773 if (offset < 0)
774 return -ENODEV; 774 return -ENODEV;
775 775
776 while (match->compatible) { 776 while (match->compatible[0]) {
777 unsigned long addr; 777 unsigned long addr;
778 if (fdt_node_check_compatible(fdt, offset, match->compatible)) { 778 if (fdt_node_check_compatible(fdt, offset, match->compatible)) {
779 match++; 779 match++;
@@ -964,8 +964,6 @@ void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
964int __init __weak early_init_dt_reserve_memory_arch(phys_addr_t base, 964int __init __weak early_init_dt_reserve_memory_arch(phys_addr_t base,
965 phys_addr_t size, bool nomap) 965 phys_addr_t size, bool nomap)
966{ 966{
967 if (memblock_is_region_reserved(base, size))
968 return -EBUSY;
969 if (nomap) 967 if (nomap)
970 return memblock_remove(base, size); 968 return memblock_remove(base, size);
971 return memblock_reserve(base, size); 969 return memblock_reserve(base, size);
diff --git a/drivers/of/selftest.c b/drivers/of/selftest.c
index 11b873c54a77..e2d79afa9dc6 100644
--- a/drivers/of/selftest.c
+++ b/drivers/of/selftest.c
@@ -896,10 +896,14 @@ static void selftest_data_remove(void)
896 return; 896 return;
897 } 897 }
898 898
899 while (last_node_index >= 0) { 899 while (last_node_index-- > 0) {
900 if (nodes[last_node_index]) { 900 if (nodes[last_node_index]) {
901 np = of_find_node_by_path(nodes[last_node_index]->full_name); 901 np = of_find_node_by_path(nodes[last_node_index]->full_name);
902 if (strcmp(np->full_name, "/aliases") != 0) { 902 if (np == nodes[last_node_index]) {
903 if (of_aliases == np) {
904 of_node_put(of_aliases);
905 of_aliases = NULL;
906 }
903 detach_node_and_children(np); 907 detach_node_and_children(np);
904 } else { 908 } else {
905 for_each_property_of_node(np, prop) { 909 for_each_property_of_node(np, prop) {
@@ -908,7 +912,6 @@ static void selftest_data_remove(void)
908 } 912 }
909 } 913 }
910 } 914 }
911 last_node_index--;
912 } 915 }
913} 916}
914 917
@@ -921,6 +924,8 @@ static int __init of_selftest(void)
921 res = selftest_data_add(); 924 res = selftest_data_add();
922 if (res) 925 if (res)
923 return res; 926 return res;
927 if (!of_aliases)
928 of_aliases = of_find_node_by_path("/aliases");
924 929
925 np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a"); 930 np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
926 if (!np) { 931 if (!np) {
diff --git a/drivers/pci/access.c b/drivers/pci/access.c
index d292d7cb3417..49dd766852ba 100644
--- a/drivers/pci/access.c
+++ b/drivers/pci/access.c
@@ -444,7 +444,7 @@ static inline int pcie_cap_version(const struct pci_dev *dev)
444 return pcie_caps_reg(dev) & PCI_EXP_FLAGS_VERS; 444 return pcie_caps_reg(dev) & PCI_EXP_FLAGS_VERS;
445} 445}
446 446
447static inline bool pcie_cap_has_lnkctl(const struct pci_dev *dev) 447bool pcie_cap_has_lnkctl(const struct pci_dev *dev)
448{ 448{
449 int type = pci_pcie_type(dev); 449 int type = pci_pcie_type(dev);
450 450
diff --git a/drivers/pci/host/pci-tegra.c b/drivers/pci/host/pci-tegra.c
index 3d43874319be..19bb19c7db4a 100644
--- a/drivers/pci/host/pci-tegra.c
+++ b/drivers/pci/host/pci-tegra.c
@@ -276,6 +276,7 @@ struct tegra_pcie {
276 276
277 struct resource all; 277 struct resource all;
278 struct resource io; 278 struct resource io;
279 struct resource pio;
279 struct resource mem; 280 struct resource mem;
280 struct resource prefetch; 281 struct resource prefetch;
281 struct resource busn; 282 struct resource busn;
@@ -658,7 +659,6 @@ static int tegra_pcie_setup(int nr, struct pci_sys_data *sys)
658{ 659{
659 struct tegra_pcie *pcie = sys_to_pcie(sys); 660 struct tegra_pcie *pcie = sys_to_pcie(sys);
660 int err; 661 int err;
661 phys_addr_t io_start;
662 662
663 err = devm_request_resource(pcie->dev, &pcie->all, &pcie->mem); 663 err = devm_request_resource(pcie->dev, &pcie->all, &pcie->mem);
664 if (err < 0) 664 if (err < 0)
@@ -668,14 +668,12 @@ static int tegra_pcie_setup(int nr, struct pci_sys_data *sys)
668 if (err) 668 if (err)
669 return err; 669 return err;
670 670
671 io_start = pci_pio_to_address(pcie->io.start);
672
673 pci_add_resource_offset(&sys->resources, &pcie->mem, sys->mem_offset); 671 pci_add_resource_offset(&sys->resources, &pcie->mem, sys->mem_offset);
674 pci_add_resource_offset(&sys->resources, &pcie->prefetch, 672 pci_add_resource_offset(&sys->resources, &pcie->prefetch,
675 sys->mem_offset); 673 sys->mem_offset);
676 pci_add_resource(&sys->resources, &pcie->busn); 674 pci_add_resource(&sys->resources, &pcie->busn);
677 675
678 pci_ioremap_io(nr * SZ_64K, io_start); 676 pci_ioremap_io(pcie->pio.start, pcie->io.start);
679 677
680 return 1; 678 return 1;
681} 679}
@@ -786,7 +784,6 @@ static irqreturn_t tegra_pcie_isr(int irq, void *arg)
786static void tegra_pcie_setup_translations(struct tegra_pcie *pcie) 784static void tegra_pcie_setup_translations(struct tegra_pcie *pcie)
787{ 785{
788 u32 fpci_bar, size, axi_address; 786 u32 fpci_bar, size, axi_address;
789 phys_addr_t io_start = pci_pio_to_address(pcie->io.start);
790 787
791 /* Bar 0: type 1 extended configuration space */ 788 /* Bar 0: type 1 extended configuration space */
792 fpci_bar = 0xfe100000; 789 fpci_bar = 0xfe100000;
@@ -799,7 +796,7 @@ static void tegra_pcie_setup_translations(struct tegra_pcie *pcie)
799 /* Bar 1: downstream IO bar */ 796 /* Bar 1: downstream IO bar */
800 fpci_bar = 0xfdfc0000; 797 fpci_bar = 0xfdfc0000;
801 size = resource_size(&pcie->io); 798 size = resource_size(&pcie->io);
802 axi_address = io_start; 799 axi_address = pcie->io.start;
803 afi_writel(pcie, axi_address, AFI_AXI_BAR1_START); 800 afi_writel(pcie, axi_address, AFI_AXI_BAR1_START);
804 afi_writel(pcie, size >> 12, AFI_AXI_BAR1_SZ); 801 afi_writel(pcie, size >> 12, AFI_AXI_BAR1_SZ);
805 afi_writel(pcie, fpci_bar, AFI_FPCI_BAR1); 802 afi_writel(pcie, fpci_bar, AFI_FPCI_BAR1);
@@ -1690,8 +1687,23 @@ static int tegra_pcie_parse_dt(struct tegra_pcie *pcie)
1690 1687
1691 switch (res.flags & IORESOURCE_TYPE_BITS) { 1688 switch (res.flags & IORESOURCE_TYPE_BITS) {
1692 case IORESOURCE_IO: 1689 case IORESOURCE_IO:
1693 memcpy(&pcie->io, &res, sizeof(res)); 1690 memcpy(&pcie->pio, &res, sizeof(res));
1694 pcie->io.name = np->full_name; 1691 pcie->pio.name = np->full_name;
1692
1693 /*
1694 * The Tegra PCIe host bridge uses this to program the
1695 * mapping of the I/O space to the physical address,
1696 * so we override the .start and .end fields here that
1697 * of_pci_range_to_resource() converted to I/O space.
1698 * We also set the IORESOURCE_MEM type to clarify that
1699 * the resource is in the physical memory space.
1700 */
1701 pcie->io.start = range.cpu_addr;
1702 pcie->io.end = range.cpu_addr + range.size - 1;
1703 pcie->io.flags = IORESOURCE_MEM;
1704 pcie->io.name = "I/O";
1705
1706 memcpy(&res, &pcie->io, sizeof(res));
1695 break; 1707 break;
1696 1708
1697 case IORESOURCE_MEM: 1709 case IORESOURCE_MEM:
diff --git a/drivers/pci/host/pci-xgene.c b/drivers/pci/host/pci-xgene.c
index 9ecabfa8c634..2988fe136c1e 100644
--- a/drivers/pci/host/pci-xgene.c
+++ b/drivers/pci/host/pci-xgene.c
@@ -631,10 +631,15 @@ static int xgene_pcie_probe_bridge(struct platform_device *pdev)
631 if (ret) 631 if (ret)
632 return ret; 632 return ret;
633 633
634 bus = pci_scan_root_bus(&pdev->dev, 0, &xgene_pcie_ops, port, &res); 634 bus = pci_create_root_bus(&pdev->dev, 0,
635 &xgene_pcie_ops, port, &res);
635 if (!bus) 636 if (!bus)
636 return -ENOMEM; 637 return -ENOMEM;
637 638
639 pci_scan_child_bus(bus);
640 pci_assign_unassigned_bus_resources(bus);
641 pci_bus_add_devices(bus);
642
638 platform_set_drvdata(pdev, port); 643 platform_set_drvdata(pdev, port);
639 return 0; 644 return 0;
640} 645}
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 9fab30af0e75..084587d7cd13 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -590,6 +590,20 @@ static struct msi_desc *msi_setup_entry(struct pci_dev *dev)
590 return entry; 590 return entry;
591} 591}
592 592
593static int msi_verify_entries(struct pci_dev *dev)
594{
595 struct msi_desc *entry;
596
597 list_for_each_entry(entry, &dev->msi_list, list) {
598 if (!dev->no_64bit_msi || !entry->msg.address_hi)
599 continue;
600 dev_err(&dev->dev, "Device has broken 64-bit MSI but arch"
601 " tried to assign one above 4G\n");
602 return -EIO;
603 }
604 return 0;
605}
606
593/** 607/**
594 * msi_capability_init - configure device's MSI capability structure 608 * msi_capability_init - configure device's MSI capability structure
595 * @dev: pointer to the pci_dev data structure of MSI device function 609 * @dev: pointer to the pci_dev data structure of MSI device function
@@ -627,6 +641,13 @@ static int msi_capability_init(struct pci_dev *dev, int nvec)
627 return ret; 641 return ret;
628 } 642 }
629 643
644 ret = msi_verify_entries(dev);
645 if (ret) {
646 msi_mask_irq(entry, mask, ~mask);
647 free_msi_irqs(dev);
648 return ret;
649 }
650
630 ret = populate_msi_sysfs(dev); 651 ret = populate_msi_sysfs(dev);
631 if (ret) { 652 if (ret) {
632 msi_mask_irq(entry, mask, ~mask); 653 msi_mask_irq(entry, mask, ~mask);
@@ -739,6 +760,11 @@ static int msix_capability_init(struct pci_dev *dev,
739 if (ret) 760 if (ret)
740 goto out_avail; 761 goto out_avail;
741 762
763 /* Check if all MSI entries honor device restrictions */
764 ret = msi_verify_entries(dev);
765 if (ret)
766 goto out_free;
767
742 /* 768 /*
743 * Some devices require MSI-X to be enabled before we can touch the 769 * Some devices require MSI-X to be enabled before we can touch the
744 * MSI-X registers. We need to mask all the vectors to prevent 770 * MSI-X registers. We need to mask all the vectors to prevent
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 0601890db22d..4a3902d8e6fe 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -6,6 +6,8 @@
6 6
7extern const unsigned char pcie_link_speed[]; 7extern const unsigned char pcie_link_speed[];
8 8
9bool pcie_cap_has_lnkctl(const struct pci_dev *dev);
10
9/* Functions internal to the PCI core code */ 11/* Functions internal to the PCI core code */
10 12
11int pci_create_sysfs_dev_files(struct pci_dev *pdev); 13int pci_create_sysfs_dev_files(struct pci_dev *pdev);
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 5ed99309c758..c8ca98c2b480 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -407,15 +407,16 @@ static void pci_read_bridge_mmio_pref(struct pci_bus *child)
407{ 407{
408 struct pci_dev *dev = child->self; 408 struct pci_dev *dev = child->self;
409 u16 mem_base_lo, mem_limit_lo; 409 u16 mem_base_lo, mem_limit_lo;
410 unsigned long base, limit; 410 u64 base64, limit64;
411 dma_addr_t base, limit;
411 struct pci_bus_region region; 412 struct pci_bus_region region;
412 struct resource *res; 413 struct resource *res;
413 414
414 res = child->resource[2]; 415 res = child->resource[2];
415 pci_read_config_word(dev, PCI_PREF_MEMORY_BASE, &mem_base_lo); 416 pci_read_config_word(dev, PCI_PREF_MEMORY_BASE, &mem_base_lo);
416 pci_read_config_word(dev, PCI_PREF_MEMORY_LIMIT, &mem_limit_lo); 417 pci_read_config_word(dev, PCI_PREF_MEMORY_LIMIT, &mem_limit_lo);
417 base = ((unsigned long) mem_base_lo & PCI_PREF_RANGE_MASK) << 16; 418 base64 = (mem_base_lo & PCI_PREF_RANGE_MASK) << 16;
418 limit = ((unsigned long) mem_limit_lo & PCI_PREF_RANGE_MASK) << 16; 419 limit64 = (mem_limit_lo & PCI_PREF_RANGE_MASK) << 16;
419 420
420 if ((mem_base_lo & PCI_PREF_RANGE_TYPE_MASK) == PCI_PREF_RANGE_TYPE_64) { 421 if ((mem_base_lo & PCI_PREF_RANGE_TYPE_MASK) == PCI_PREF_RANGE_TYPE_64) {
421 u32 mem_base_hi, mem_limit_hi; 422 u32 mem_base_hi, mem_limit_hi;
@@ -429,17 +430,20 @@ static void pci_read_bridge_mmio_pref(struct pci_bus *child)
429 * this, just assume they are not being used. 430 * this, just assume they are not being used.
430 */ 431 */
431 if (mem_base_hi <= mem_limit_hi) { 432 if (mem_base_hi <= mem_limit_hi) {
432#if BITS_PER_LONG == 64 433 base64 |= (u64) mem_base_hi << 32;
433 base |= ((unsigned long) mem_base_hi) << 32; 434 limit64 |= (u64) mem_limit_hi << 32;
434 limit |= ((unsigned long) mem_limit_hi) << 32;
435#else
436 if (mem_base_hi || mem_limit_hi) {
437 dev_err(&dev->dev, "can't handle 64-bit address space for bridge\n");
438 return;
439 }
440#endif
441 } 435 }
442 } 436 }
437
438 base = (dma_addr_t) base64;
439 limit = (dma_addr_t) limit64;
440
441 if (base != base64) {
442 dev_err(&dev->dev, "can't handle bridge window above 4GB (bus address %#010llx)\n",
443 (unsigned long long) base64);
444 return;
445 }
446
443 if (base <= limit) { 447 if (base <= limit) {
444 res->flags = (mem_base_lo & PCI_PREF_RANGE_TYPE_MASK) | 448 res->flags = (mem_base_lo & PCI_PREF_RANGE_TYPE_MASK) |
445 IORESOURCE_MEM | IORESOURCE_PREFETCH; 449 IORESOURCE_MEM | IORESOURCE_PREFETCH;
@@ -1323,7 +1327,7 @@ static void program_hpp_type2(struct pci_dev *dev, struct hpp_type2 *hpp)
1323 ~hpp->pci_exp_devctl_and, hpp->pci_exp_devctl_or); 1327 ~hpp->pci_exp_devctl_and, hpp->pci_exp_devctl_or);
1324 1328
1325 /* Initialize Link Control Register */ 1329 /* Initialize Link Control Register */
1326 if (dev->subordinate) 1330 if (pcie_cap_has_lnkctl(dev))
1327 pcie_capability_clear_and_set_word(dev, PCI_EXP_LNKCTL, 1331 pcie_capability_clear_and_set_word(dev, PCI_EXP_LNKCTL,
1328 ~hpp->pci_exp_lnkctl_and, hpp->pci_exp_lnkctl_or); 1332 ~hpp->pci_exp_lnkctl_and, hpp->pci_exp_lnkctl_or);
1329 1333
diff --git a/drivers/powercap/Kconfig b/drivers/powercap/Kconfig
index a7c81b53d88a..85727ef6ce8e 100644
--- a/drivers/powercap/Kconfig
+++ b/drivers/powercap/Kconfig
@@ -17,7 +17,7 @@ if POWERCAP
17# Client driver configurations go here. 17# Client driver configurations go here.
18config INTEL_RAPL 18config INTEL_RAPL
19 tristate "Intel RAPL Support" 19 tristate "Intel RAPL Support"
20 depends on X86 20 depends on X86 && IOSF_MBI
21 default n 21 default n
22 ---help--- 22 ---help---
23 This enables support for the Intel Running Average Power Limit (RAPL) 23 This enables support for the Intel Running Average Power Limit (RAPL)
diff --git a/drivers/powercap/intel_rapl.c b/drivers/powercap/intel_rapl.c
index 45e05b32f9b6..c71443c4f265 100644
--- a/drivers/powercap/intel_rapl.c
+++ b/drivers/powercap/intel_rapl.c
@@ -29,6 +29,7 @@
29#include <linux/sysfs.h> 29#include <linux/sysfs.h>
30#include <linux/cpu.h> 30#include <linux/cpu.h>
31#include <linux/powercap.h> 31#include <linux/powercap.h>
32#include <asm/iosf_mbi.h>
32 33
33#include <asm/processor.h> 34#include <asm/processor.h>
34#include <asm/cpu_device_id.h> 35#include <asm/cpu_device_id.h>
@@ -70,11 +71,6 @@
70#define RAPL_PRIMITIVE_DERIVED BIT(1) /* not from raw data */ 71#define RAPL_PRIMITIVE_DERIVED BIT(1) /* not from raw data */
71#define RAPL_PRIMITIVE_DUMMY BIT(2) 72#define RAPL_PRIMITIVE_DUMMY BIT(2)
72 73
73/* scale RAPL units to avoid floating point math inside kernel */
74#define POWER_UNIT_SCALE (1000000)
75#define ENERGY_UNIT_SCALE (1000000)
76#define TIME_UNIT_SCALE (1000000)
77
78#define TIME_WINDOW_MAX_MSEC 40000 74#define TIME_WINDOW_MAX_MSEC 40000
79#define TIME_WINDOW_MIN_MSEC 250 75#define TIME_WINDOW_MIN_MSEC 250
80 76
@@ -175,9 +171,9 @@ struct rapl_package {
175 unsigned int id; /* physical package/socket id */ 171 unsigned int id; /* physical package/socket id */
176 unsigned int nr_domains; 172 unsigned int nr_domains;
177 unsigned long domain_map; /* bit map of active domains */ 173 unsigned long domain_map; /* bit map of active domains */
178 unsigned int power_unit_divisor; 174 unsigned int power_unit;
179 unsigned int energy_unit_divisor; 175 unsigned int energy_unit;
180 unsigned int time_unit_divisor; 176 unsigned int time_unit;
181 struct rapl_domain *domains; /* array of domains, sized at runtime */ 177 struct rapl_domain *domains; /* array of domains, sized at runtime */
182 struct powercap_zone *power_zone; /* keep track of parent zone */ 178 struct powercap_zone *power_zone; /* keep track of parent zone */
183 int nr_cpus; /* active cpus on the package, topology info is lost during 179 int nr_cpus; /* active cpus on the package, topology info is lost during
@@ -188,6 +184,18 @@ struct rapl_package {
188 */ 184 */
189 struct list_head plist; 185 struct list_head plist;
190}; 186};
187
188struct rapl_defaults {
189 int (*check_unit)(struct rapl_package *rp, int cpu);
190 void (*set_floor_freq)(struct rapl_domain *rd, bool mode);
191 u64 (*compute_time_window)(struct rapl_package *rp, u64 val,
192 bool to_raw);
193};
194static struct rapl_defaults *rapl_defaults;
195
196/* Sideband MBI registers */
197#define IOSF_CPU_POWER_BUDGET_CTL (0x2)
198
191#define PACKAGE_PLN_INT_SAVED BIT(0) 199#define PACKAGE_PLN_INT_SAVED BIT(0)
192#define MAX_PRIM_NAME (32) 200#define MAX_PRIM_NAME (32)
193 201
@@ -339,23 +347,13 @@ static int find_nr_power_limit(struct rapl_domain *rd)
339static int set_domain_enable(struct powercap_zone *power_zone, bool mode) 347static int set_domain_enable(struct powercap_zone *power_zone, bool mode)
340{ 348{
341 struct rapl_domain *rd = power_zone_to_rapl_domain(power_zone); 349 struct rapl_domain *rd = power_zone_to_rapl_domain(power_zone);
342 int nr_powerlimit;
343 350
344 if (rd->state & DOMAIN_STATE_BIOS_LOCKED) 351 if (rd->state & DOMAIN_STATE_BIOS_LOCKED)
345 return -EACCES; 352 return -EACCES;
353
346 get_online_cpus(); 354 get_online_cpus();
347 nr_powerlimit = find_nr_power_limit(rd);
348 /* here we activate/deactivate the hardware for power limiting */
349 rapl_write_data_raw(rd, PL1_ENABLE, mode); 355 rapl_write_data_raw(rd, PL1_ENABLE, mode);
350 /* always enable clamp such that p-state can go below OS requested 356 rapl_defaults->set_floor_freq(rd, mode);
351 * range. power capping priority over guranteed frequency.
352 */
353 rapl_write_data_raw(rd, PL1_CLAMP, mode);
354 /* some domains have pl2 */
355 if (nr_powerlimit > 1) {
356 rapl_write_data_raw(rd, PL2_ENABLE, mode);
357 rapl_write_data_raw(rd, PL2_CLAMP, mode);
358 }
359 put_online_cpus(); 357 put_online_cpus();
360 358
361 return 0; 359 return 0;
@@ -653,9 +651,7 @@ static void rapl_init_domains(struct rapl_package *rp)
653static u64 rapl_unit_xlate(int package, enum unit_type type, u64 value, 651static u64 rapl_unit_xlate(int package, enum unit_type type, u64 value,
654 int to_raw) 652 int to_raw)
655{ 653{
656 u64 divisor = 1; 654 u64 units = 1;
657 int scale = 1; /* scale to user friendly data without floating point */
658 u64 f, y; /* fraction and exp. used for time unit */
659 struct rapl_package *rp; 655 struct rapl_package *rp;
660 656
661 rp = find_package_by_id(package); 657 rp = find_package_by_id(package);
@@ -664,42 +660,24 @@ static u64 rapl_unit_xlate(int package, enum unit_type type, u64 value,
664 660
665 switch (type) { 661 switch (type) {
666 case POWER_UNIT: 662 case POWER_UNIT:
667 divisor = rp->power_unit_divisor; 663 units = rp->power_unit;
668 scale = POWER_UNIT_SCALE;
669 break; 664 break;
670 case ENERGY_UNIT: 665 case ENERGY_UNIT:
671 scale = ENERGY_UNIT_SCALE; 666 units = rp->energy_unit;
672 divisor = rp->energy_unit_divisor;
673 break; 667 break;
674 case TIME_UNIT: 668 case TIME_UNIT:
675 divisor = rp->time_unit_divisor; 669 return rapl_defaults->compute_time_window(rp, value, to_raw);
676 scale = TIME_UNIT_SCALE;
677 /* special processing based on 2^Y*(1+F)/4 = val/divisor, refer
678 * to Intel Software Developer's manual Vol. 3a, CH 14.7.4.
679 */
680 if (!to_raw) {
681 f = (value & 0x60) >> 5;
682 y = value & 0x1f;
683 value = (1 << y) * (4 + f) * scale / 4;
684 return div64_u64(value, divisor);
685 } else {
686 do_div(value, scale);
687 value *= divisor;
688 y = ilog2(value);
689 f = div64_u64(4 * (value - (1 << y)), 1 << y);
690 value = (y & 0x1f) | ((f & 0x3) << 5);
691 return value;
692 }
693 break;
694 case ARBITRARY_UNIT: 670 case ARBITRARY_UNIT:
695 default: 671 default:
696 return value; 672 return value;
697 }; 673 };
698 674
699 if (to_raw) 675 if (to_raw)
700 return div64_u64(value * divisor, scale); 676 return div64_u64(value, units);
701 else 677
702 return div64_u64(value * scale, divisor); 678 value *= units;
679
680 return value;
703} 681}
704 682
705/* in the order of enum rapl_primitives */ 683/* in the order of enum rapl_primitives */
@@ -833,12 +811,18 @@ static int rapl_write_data_raw(struct rapl_domain *rd,
833 return 0; 811 return 0;
834} 812}
835 813
836static const struct x86_cpu_id energy_unit_quirk_ids[] = { 814/*
837 { X86_VENDOR_INTEL, 6, 0x37},/* Valleyview */ 815 * Raw RAPL data stored in MSRs are in certain scales. We need to
838 {} 816 * convert them into standard units based on the units reported in
839}; 817 * the RAPL unit MSRs. This is specific to CPUs as the method to
840 818 * calculate units differ on different CPUs.
841static int rapl_check_unit(struct rapl_package *rp, int cpu) 819 * We convert the units to below format based on CPUs.
820 * i.e.
821 * energy unit: microJoules : Represented in microJoules by default
822 * power unit : microWatts : Represented in milliWatts by default
823 * time unit : microseconds: Represented in seconds by default
824 */
825static int rapl_check_unit_core(struct rapl_package *rp, int cpu)
842{ 826{
843 u64 msr_val; 827 u64 msr_val;
844 u32 value; 828 u32 value;
@@ -849,36 +833,47 @@ static int rapl_check_unit(struct rapl_package *rp, int cpu)
849 return -ENODEV; 833 return -ENODEV;
850 } 834 }
851 835
852 /* Raw RAPL data stored in MSRs are in certain scales. We need to
853 * convert them into standard units based on the divisors reported in
854 * the RAPL unit MSRs.
855 * i.e.
856 * energy unit: 1/enery_unit_divisor Joules
857 * power unit: 1/power_unit_divisor Watts
858 * time unit: 1/time_unit_divisor Seconds
859 */
860 value = (msr_val & ENERGY_UNIT_MASK) >> ENERGY_UNIT_OFFSET; 836 value = (msr_val & ENERGY_UNIT_MASK) >> ENERGY_UNIT_OFFSET;
861 /* some CPUs have different way to calculate energy unit */ 837 rp->energy_unit = 1000000 / (1 << value);
862 if (x86_match_cpu(energy_unit_quirk_ids))
863 rp->energy_unit_divisor = 1000000 / (1 << value);
864 else
865 rp->energy_unit_divisor = 1 << value;
866 838
867 value = (msr_val & POWER_UNIT_MASK) >> POWER_UNIT_OFFSET; 839 value = (msr_val & POWER_UNIT_MASK) >> POWER_UNIT_OFFSET;
868 rp->power_unit_divisor = 1 << value; 840 rp->power_unit = 1000000 / (1 << value);
869 841
870 value = (msr_val & TIME_UNIT_MASK) >> TIME_UNIT_OFFSET; 842 value = (msr_val & TIME_UNIT_MASK) >> TIME_UNIT_OFFSET;
871 rp->time_unit_divisor = 1 << value; 843 rp->time_unit = 1000000 / (1 << value);
872 844
873 pr_debug("Physical package %d units: energy=%d, time=%d, power=%d\n", 845 pr_debug("Core CPU package %d energy=%duJ, time=%dus, power=%duW\n",
874 rp->id, 846 rp->id, rp->energy_unit, rp->time_unit, rp->power_unit);
875 rp->energy_unit_divisor,
876 rp->time_unit_divisor,
877 rp->power_unit_divisor);
878 847
879 return 0; 848 return 0;
880} 849}
881 850
851static int rapl_check_unit_atom(struct rapl_package *rp, int cpu)
852{
853 u64 msr_val;
854 u32 value;
855
856 if (rdmsrl_safe_on_cpu(cpu, MSR_RAPL_POWER_UNIT, &msr_val)) {
857 pr_err("Failed to read power unit MSR 0x%x on CPU %d, exit.\n",
858 MSR_RAPL_POWER_UNIT, cpu);
859 return -ENODEV;
860 }
861 value = (msr_val & ENERGY_UNIT_MASK) >> ENERGY_UNIT_OFFSET;
862 rp->energy_unit = 1 << value;
863
864 value = (msr_val & POWER_UNIT_MASK) >> POWER_UNIT_OFFSET;
865 rp->power_unit = (1 << value) * 1000;
866
867 value = (msr_val & TIME_UNIT_MASK) >> TIME_UNIT_OFFSET;
868 rp->time_unit = 1000000 / (1 << value);
869
870 pr_debug("Atom package %d energy=%duJ, time=%dus, power=%duW\n",
871 rp->id, rp->energy_unit, rp->time_unit, rp->power_unit);
872
873 return 0;
874}
875
876
882/* REVISIT: 877/* REVISIT:
883 * When package power limit is set artificially low by RAPL, LVT 878 * When package power limit is set artificially low by RAPL, LVT
884 * thermal interrupt for package power limit should be ignored 879 * thermal interrupt for package power limit should be ignored
@@ -946,16 +941,107 @@ static void package_power_limit_irq_restore(int package_id)
946 wrmsr_on_cpu(cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h); 941 wrmsr_on_cpu(cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
947} 942}
948 943
944static void set_floor_freq_default(struct rapl_domain *rd, bool mode)
945{
946 int nr_powerlimit = find_nr_power_limit(rd);
947
948 /* always enable clamp such that p-state can go below OS requested
949 * range. power capping priority over guranteed frequency.
950 */
951 rapl_write_data_raw(rd, PL1_CLAMP, mode);
952
953 /* some domains have pl2 */
954 if (nr_powerlimit > 1) {
955 rapl_write_data_raw(rd, PL2_ENABLE, mode);
956 rapl_write_data_raw(rd, PL2_CLAMP, mode);
957 }
958}
959
960static void set_floor_freq_atom(struct rapl_domain *rd, bool enable)
961{
962 static u32 power_ctrl_orig_val;
963 u32 mdata;
964
965 if (!power_ctrl_orig_val)
966 iosf_mbi_read(BT_MBI_UNIT_PMC, BT_MBI_PMC_READ,
967 IOSF_CPU_POWER_BUDGET_CTL, &power_ctrl_orig_val);
968 mdata = power_ctrl_orig_val;
969 if (enable) {
970 mdata &= ~(0x7f << 8);
971 mdata |= 1 << 8;
972 }
973 iosf_mbi_write(BT_MBI_UNIT_PMC, BT_MBI_PMC_WRITE,
974 IOSF_CPU_POWER_BUDGET_CTL, mdata);
975}
976
977static u64 rapl_compute_time_window_core(struct rapl_package *rp, u64 value,
978 bool to_raw)
979{
980 u64 f, y; /* fraction and exp. used for time unit */
981
982 /*
983 * Special processing based on 2^Y*(1+F/4), refer
984 * to Intel Software Developer's manual Vol.3B: CH 14.9.3.
985 */
986 if (!to_raw) {
987 f = (value & 0x60) >> 5;
988 y = value & 0x1f;
989 value = (1 << y) * (4 + f) * rp->time_unit / 4;
990 } else {
991 do_div(value, rp->time_unit);
992 y = ilog2(value);
993 f = div64_u64(4 * (value - (1 << y)), 1 << y);
994 value = (y & 0x1f) | ((f & 0x3) << 5);
995 }
996 return value;
997}
998
999static u64 rapl_compute_time_window_atom(struct rapl_package *rp, u64 value,
1000 bool to_raw)
1001{
1002 /*
1003 * Atom time unit encoding is straight forward val * time_unit,
1004 * where time_unit is default to 1 sec. Never 0.
1005 */
1006 if (!to_raw)
1007 return (value) ? value *= rp->time_unit : rp->time_unit;
1008 else
1009 value = div64_u64(value, rp->time_unit);
1010
1011 return value;
1012}
1013
1014static const struct rapl_defaults rapl_defaults_core = {
1015 .check_unit = rapl_check_unit_core,
1016 .set_floor_freq = set_floor_freq_default,
1017 .compute_time_window = rapl_compute_time_window_core,
1018};
1019
1020static const struct rapl_defaults rapl_defaults_atom = {
1021 .check_unit = rapl_check_unit_atom,
1022 .set_floor_freq = set_floor_freq_atom,
1023 .compute_time_window = rapl_compute_time_window_atom,
1024};
1025
1026#define RAPL_CPU(_model, _ops) { \
1027 .vendor = X86_VENDOR_INTEL, \
1028 .family = 6, \
1029 .model = _model, \
1030 .driver_data = (kernel_ulong_t)&_ops, \
1031 }
1032
949static const struct x86_cpu_id rapl_ids[] = { 1033static const struct x86_cpu_id rapl_ids[] = {
950 { X86_VENDOR_INTEL, 6, 0x2a},/* Sandy Bridge */ 1034 RAPL_CPU(0x2a, rapl_defaults_core),/* Sandy Bridge */
951 { X86_VENDOR_INTEL, 6, 0x2d},/* Sandy Bridge EP */ 1035 RAPL_CPU(0x2d, rapl_defaults_core),/* Sandy Bridge EP */
952 { X86_VENDOR_INTEL, 6, 0x37},/* Valleyview */ 1036 RAPL_CPU(0x37, rapl_defaults_atom),/* Valleyview */
953 { X86_VENDOR_INTEL, 6, 0x3a},/* Ivy Bridge */ 1037 RAPL_CPU(0x3a, rapl_defaults_core),/* Ivy Bridge */
954 { X86_VENDOR_INTEL, 6, 0x3c},/* Haswell */ 1038 RAPL_CPU(0x3c, rapl_defaults_core),/* Haswell */
955 { X86_VENDOR_INTEL, 6, 0x3d},/* Broadwell */ 1039 RAPL_CPU(0x3d, rapl_defaults_core),/* Broadwell */
956 { X86_VENDOR_INTEL, 6, 0x3f},/* Haswell */ 1040 RAPL_CPU(0x3f, rapl_defaults_core),/* Haswell */
957 { X86_VENDOR_INTEL, 6, 0x45},/* Haswell ULT */ 1041 RAPL_CPU(0x45, rapl_defaults_core),/* Haswell ULT */
958 /* TODO: Add more CPU IDs after testing */ 1042 RAPL_CPU(0x4C, rapl_defaults_atom),/* Braswell */
1043 RAPL_CPU(0x4A, rapl_defaults_atom),/* Tangier */
1044 RAPL_CPU(0x5A, rapl_defaults_atom),/* Annidale */
959 {} 1045 {}
960}; 1046};
961MODULE_DEVICE_TABLE(x86cpu, rapl_ids); 1047MODULE_DEVICE_TABLE(x86cpu, rapl_ids);
@@ -1241,7 +1327,7 @@ static int rapl_detect_topology(void)
1241 1327
1242 /* check if the package contains valid domains */ 1328 /* check if the package contains valid domains */
1243 if (rapl_detect_domains(new_package, i) || 1329 if (rapl_detect_domains(new_package, i) ||
1244 rapl_check_unit(new_package, i)) { 1330 rapl_defaults->check_unit(new_package, i)) {
1245 kfree(new_package->domains); 1331 kfree(new_package->domains);
1246 kfree(new_package); 1332 kfree(new_package);
1247 /* free up the packages already initialized */ 1333 /* free up the packages already initialized */
@@ -1296,7 +1382,7 @@ static int rapl_add_package(int cpu)
1296 rp->nr_cpus = 1; 1382 rp->nr_cpus = 1;
1297 /* check if the package contains valid domains */ 1383 /* check if the package contains valid domains */
1298 if (rapl_detect_domains(rp, cpu) || 1384 if (rapl_detect_domains(rp, cpu) ||
1299 rapl_check_unit(rp, cpu)) { 1385 rapl_defaults->check_unit(rp, cpu)) {
1300 ret = -ENODEV; 1386 ret = -ENODEV;
1301 goto err_free_package; 1387 goto err_free_package;
1302 } 1388 }
@@ -1358,14 +1444,18 @@ static struct notifier_block rapl_cpu_notifier = {
1358static int __init rapl_init(void) 1444static int __init rapl_init(void)
1359{ 1445{
1360 int ret = 0; 1446 int ret = 0;
1447 const struct x86_cpu_id *id;
1361 1448
1362 if (!x86_match_cpu(rapl_ids)) { 1449 id = x86_match_cpu(rapl_ids);
1450 if (!id) {
1363 pr_err("driver does not support CPU family %d model %d\n", 1451 pr_err("driver does not support CPU family %d model %d\n",
1364 boot_cpu_data.x86, boot_cpu_data.x86_model); 1452 boot_cpu_data.x86, boot_cpu_data.x86_model);
1365 1453
1366 return -ENODEV; 1454 return -ENODEV;
1367 } 1455 }
1368 1456
1457 rapl_defaults = (struct rapl_defaults *)id->driver_data;
1458
1369 cpu_notifier_register_begin(); 1459 cpu_notifier_register_begin();
1370 1460
1371 /* prevent CPU hotplug during detection */ 1461 /* prevent CPU hotplug during detection */
diff --git a/drivers/scsi/bnx2fc/bnx2fc_fcoe.c b/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
index 79e5c94107a9..72533c58c1f3 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
@@ -412,6 +412,7 @@ static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
412 struct fc_frame_header *fh; 412 struct fc_frame_header *fh;
413 struct fcoe_rcv_info *fr; 413 struct fcoe_rcv_info *fr;
414 struct fcoe_percpu_s *bg; 414 struct fcoe_percpu_s *bg;
415 struct sk_buff *tmp_skb;
415 unsigned short oxid; 416 unsigned short oxid;
416 417
417 interface = container_of(ptype, struct bnx2fc_interface, 418 interface = container_of(ptype, struct bnx2fc_interface,
@@ -424,6 +425,12 @@ static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
424 goto err; 425 goto err;
425 } 426 }
426 427
428 tmp_skb = skb_share_check(skb, GFP_ATOMIC);
429 if (!tmp_skb)
430 goto err;
431
432 skb = tmp_skb;
433
427 if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) { 434 if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
428 printk(KERN_ERR PFX "bnx2fc_rcv: Wrong FC type frame\n"); 435 printk(KERN_ERR PFX "bnx2fc_rcv: Wrong FC type frame\n");
429 goto err; 436 goto err;
diff --git a/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c b/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c
index 81bb3bd7909d..15081257cfc8 100644
--- a/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c
+++ b/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c
@@ -828,6 +828,8 @@ static void do_act_open_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
828 if (status == CPL_ERR_RTX_NEG_ADVICE) 828 if (status == CPL_ERR_RTX_NEG_ADVICE)
829 goto rel_skb; 829 goto rel_skb;
830 830
831 module_put(THIS_MODULE);
832
831 if (status && status != CPL_ERR_TCAM_FULL && 833 if (status && status != CPL_ERR_TCAM_FULL &&
832 status != CPL_ERR_CONN_EXIST && 834 status != CPL_ERR_CONN_EXIST &&
833 status != CPL_ERR_ARP_MISS) 835 status != CPL_ERR_ARP_MISS)
diff --git a/drivers/scsi/cxgbi/libcxgbi.c b/drivers/scsi/cxgbi/libcxgbi.c
index 13d869a92248..7da59c38a69e 100644
--- a/drivers/scsi/cxgbi/libcxgbi.c
+++ b/drivers/scsi/cxgbi/libcxgbi.c
@@ -816,7 +816,7 @@ static void cxgbi_inform_iscsi_conn_closing(struct cxgbi_sock *csk)
816 read_lock_bh(&csk->callback_lock); 816 read_lock_bh(&csk->callback_lock);
817 if (csk->user_data) 817 if (csk->user_data)
818 iscsi_conn_failure(csk->user_data, 818 iscsi_conn_failure(csk->user_data,
819 ISCSI_ERR_CONN_FAILED); 819 ISCSI_ERR_TCP_CONN_CLOSE);
820 read_unlock_bh(&csk->callback_lock); 820 read_unlock_bh(&csk->callback_lock);
821 } 821 }
822} 822}
diff --git a/drivers/scsi/scsi_devinfo.c b/drivers/scsi/scsi_devinfo.c
index 49014a143c6a..c1d04d4d3c6c 100644
--- a/drivers/scsi/scsi_devinfo.c
+++ b/drivers/scsi/scsi_devinfo.c
@@ -202,6 +202,7 @@ static struct {
202 {"IOMEGA", "Io20S *F", NULL, BLIST_KEY}, 202 {"IOMEGA", "Io20S *F", NULL, BLIST_KEY},
203 {"INSITE", "Floptical F*8I", NULL, BLIST_KEY}, 203 {"INSITE", "Floptical F*8I", NULL, BLIST_KEY},
204 {"INSITE", "I325VM", NULL, BLIST_KEY}, 204 {"INSITE", "I325VM", NULL, BLIST_KEY},
205 {"Intel", "Multi-Flex", NULL, BLIST_NO_RSOC},
205 {"iRiver", "iFP Mass Driver", NULL, BLIST_NOT_LOCKABLE | BLIST_INQUIRY_36}, 206 {"iRiver", "iFP Mass Driver", NULL, BLIST_NOT_LOCKABLE | BLIST_INQUIRY_36},
206 {"LASOUND", "CDX7405", "3.10", BLIST_MAX5LUN | BLIST_SINGLELUN}, 207 {"LASOUND", "CDX7405", "3.10", BLIST_MAX5LUN | BLIST_SINGLELUN},
207 {"MATSHITA", "PD-1", NULL, BLIST_FORCELUN | BLIST_SINGLELUN}, 208 {"MATSHITA", "PD-1", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
diff --git a/drivers/scsi/ufs/ufshcd-pltfrm.c b/drivers/scsi/ufs/ufshcd-pltfrm.c
index 8adf067ff019..1c3467b82566 100644
--- a/drivers/scsi/ufs/ufshcd-pltfrm.c
+++ b/drivers/scsi/ufs/ufshcd-pltfrm.c
@@ -102,7 +102,6 @@ static int ufshcd_parse_clock_info(struct ufs_hba *hba)
102 clkfreq = devm_kzalloc(dev, sz * sizeof(*clkfreq), 102 clkfreq = devm_kzalloc(dev, sz * sizeof(*clkfreq),
103 GFP_KERNEL); 103 GFP_KERNEL);
104 if (!clkfreq) { 104 if (!clkfreq) {
105 dev_err(dev, "%s: no memory\n", "freq-table-hz");
106 ret = -ENOMEM; 105 ret = -ENOMEM;
107 goto out; 106 goto out;
108 } 107 }
@@ -112,19 +111,19 @@ static int ufshcd_parse_clock_info(struct ufs_hba *hba)
112 if (ret && (ret != -EINVAL)) { 111 if (ret && (ret != -EINVAL)) {
113 dev_err(dev, "%s: error reading array %d\n", 112 dev_err(dev, "%s: error reading array %d\n",
114 "freq-table-hz", ret); 113 "freq-table-hz", ret);
115 goto free_clkfreq; 114 return ret;
116 } 115 }
117 116
118 for (i = 0; i < sz; i += 2) { 117 for (i = 0; i < sz; i += 2) {
119 ret = of_property_read_string_index(np, 118 ret = of_property_read_string_index(np,
120 "clock-names", i/2, (const char **)&name); 119 "clock-names", i/2, (const char **)&name);
121 if (ret) 120 if (ret)
122 goto free_clkfreq; 121 goto out;
123 122
124 clki = devm_kzalloc(dev, sizeof(*clki), GFP_KERNEL); 123 clki = devm_kzalloc(dev, sizeof(*clki), GFP_KERNEL);
125 if (!clki) { 124 if (!clki) {
126 ret = -ENOMEM; 125 ret = -ENOMEM;
127 goto free_clkfreq; 126 goto out;
128 } 127 }
129 128
130 clki->min_freq = clkfreq[i]; 129 clki->min_freq = clkfreq[i];
@@ -134,8 +133,6 @@ static int ufshcd_parse_clock_info(struct ufs_hba *hba)
134 clki->min_freq, clki->max_freq, clki->name); 133 clki->min_freq, clki->max_freq, clki->name);
135 list_add_tail(&clki->list, &hba->clk_list_head); 134 list_add_tail(&clki->list, &hba->clk_list_head);
136 } 135 }
137free_clkfreq:
138 kfree(clkfreq);
139out: 136out:
140 return ret; 137 return ret;
141} 138}
@@ -162,10 +159,8 @@ static int ufshcd_populate_vreg(struct device *dev, const char *name,
162 } 159 }
163 160
164 vreg = devm_kzalloc(dev, sizeof(*vreg), GFP_KERNEL); 161 vreg = devm_kzalloc(dev, sizeof(*vreg), GFP_KERNEL);
165 if (!vreg) { 162 if (!vreg)
166 dev_err(dev, "No memory for %s regulator\n", name); 163 return -ENOMEM;
167 goto out;
168 }
169 164
170 vreg->name = kstrdup(name, GFP_KERNEL); 165 vreg->name = kstrdup(name, GFP_KERNEL);
171 166
diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 497c38a4a866..605ca60e8a10 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -744,6 +744,8 @@ static void ufshcd_exit_clk_gating(struct ufs_hba *hba)
744 if (!ufshcd_is_clkgating_allowed(hba)) 744 if (!ufshcd_is_clkgating_allowed(hba))
745 return; 745 return;
746 device_remove_file(hba->dev, &hba->clk_gating.delay_attr); 746 device_remove_file(hba->dev, &hba->clk_gating.delay_attr);
747 cancel_work_sync(&hba->clk_gating.ungate_work);
748 cancel_delayed_work_sync(&hba->clk_gating.gate_work);
747} 749}
748 750
749/* Must be called with host lock acquired */ 751/* Must be called with host lock acquired */
@@ -2246,6 +2248,22 @@ static int ufshcd_uic_hibern8_exit(struct ufs_hba *hba)
2246 return ret; 2248 return ret;
2247} 2249}
2248 2250
2251 /**
2252 * ufshcd_init_pwr_info - setting the POR (power on reset)
2253 * values in hba power info
2254 * @hba: per-adapter instance
2255 */
2256static void ufshcd_init_pwr_info(struct ufs_hba *hba)
2257{
2258 hba->pwr_info.gear_rx = UFS_PWM_G1;
2259 hba->pwr_info.gear_tx = UFS_PWM_G1;
2260 hba->pwr_info.lane_rx = 1;
2261 hba->pwr_info.lane_tx = 1;
2262 hba->pwr_info.pwr_rx = SLOWAUTO_MODE;
2263 hba->pwr_info.pwr_tx = SLOWAUTO_MODE;
2264 hba->pwr_info.hs_rate = 0;
2265}
2266
2249/** 2267/**
2250 * ufshcd_get_max_pwr_mode - reads the max power mode negotiated with device 2268 * ufshcd_get_max_pwr_mode - reads the max power mode negotiated with device
2251 * @hba: per-adapter instance 2269 * @hba: per-adapter instance
@@ -2844,8 +2862,13 @@ static void ufshcd_slave_destroy(struct scsi_device *sdev)
2844 hba = shost_priv(sdev->host); 2862 hba = shost_priv(sdev->host);
2845 scsi_deactivate_tcq(sdev, hba->nutrs); 2863 scsi_deactivate_tcq(sdev, hba->nutrs);
2846 /* Drop the reference as it won't be needed anymore */ 2864 /* Drop the reference as it won't be needed anymore */
2847 if (ufshcd_scsi_to_upiu_lun(sdev->lun) == UFS_UPIU_UFS_DEVICE_WLUN) 2865 if (ufshcd_scsi_to_upiu_lun(sdev->lun) == UFS_UPIU_UFS_DEVICE_WLUN) {
2866 unsigned long flags;
2867
2868 spin_lock_irqsave(hba->host->host_lock, flags);
2848 hba->sdev_ufs_device = NULL; 2869 hba->sdev_ufs_device = NULL;
2870 spin_unlock_irqrestore(hba->host->host_lock, flags);
2871 }
2849} 2872}
2850 2873
2851/** 2874/**
@@ -4062,6 +4085,8 @@ static void ufshcd_init_icc_levels(struct ufs_hba *hba)
4062static int ufshcd_scsi_add_wlus(struct ufs_hba *hba) 4085static int ufshcd_scsi_add_wlus(struct ufs_hba *hba)
4063{ 4086{
4064 int ret = 0; 4087 int ret = 0;
4088 struct scsi_device *sdev_rpmb;
4089 struct scsi_device *sdev_boot;
4065 4090
4066 hba->sdev_ufs_device = __scsi_add_device(hba->host, 0, 0, 4091 hba->sdev_ufs_device = __scsi_add_device(hba->host, 0, 0,
4067 ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_UFS_DEVICE_WLUN), NULL); 4092 ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_UFS_DEVICE_WLUN), NULL);
@@ -4070,26 +4095,27 @@ static int ufshcd_scsi_add_wlus(struct ufs_hba *hba)
4070 hba->sdev_ufs_device = NULL; 4095 hba->sdev_ufs_device = NULL;
4071 goto out; 4096 goto out;
4072 } 4097 }
4098 scsi_device_put(hba->sdev_ufs_device);
4073 4099
4074 hba->sdev_boot = __scsi_add_device(hba->host, 0, 0, 4100 sdev_boot = __scsi_add_device(hba->host, 0, 0,
4075 ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_BOOT_WLUN), NULL); 4101 ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_BOOT_WLUN), NULL);
4076 if (IS_ERR(hba->sdev_boot)) { 4102 if (IS_ERR(sdev_boot)) {
4077 ret = PTR_ERR(hba->sdev_boot); 4103 ret = PTR_ERR(sdev_boot);
4078 hba->sdev_boot = NULL;
4079 goto remove_sdev_ufs_device; 4104 goto remove_sdev_ufs_device;
4080 } 4105 }
4106 scsi_device_put(sdev_boot);
4081 4107
4082 hba->sdev_rpmb = __scsi_add_device(hba->host, 0, 0, 4108 sdev_rpmb = __scsi_add_device(hba->host, 0, 0,
4083 ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_RPMB_WLUN), NULL); 4109 ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_RPMB_WLUN), NULL);
4084 if (IS_ERR(hba->sdev_rpmb)) { 4110 if (IS_ERR(sdev_rpmb)) {
4085 ret = PTR_ERR(hba->sdev_rpmb); 4111 ret = PTR_ERR(sdev_rpmb);
4086 hba->sdev_rpmb = NULL;
4087 goto remove_sdev_boot; 4112 goto remove_sdev_boot;
4088 } 4113 }
4114 scsi_device_put(sdev_rpmb);
4089 goto out; 4115 goto out;
4090 4116
4091remove_sdev_boot: 4117remove_sdev_boot:
4092 scsi_remove_device(hba->sdev_boot); 4118 scsi_remove_device(sdev_boot);
4093remove_sdev_ufs_device: 4119remove_sdev_ufs_device:
4094 scsi_remove_device(hba->sdev_ufs_device); 4120 scsi_remove_device(hba->sdev_ufs_device);
4095out: 4121out:
@@ -4097,30 +4123,6 @@ out:
4097} 4123}
4098 4124
4099/** 4125/**
4100 * ufshcd_scsi_remove_wlus - Removes the W-LUs which were added by
4101 * ufshcd_scsi_add_wlus()
4102 * @hba: per-adapter instance
4103 *
4104 */
4105static void ufshcd_scsi_remove_wlus(struct ufs_hba *hba)
4106{
4107 if (hba->sdev_ufs_device) {
4108 scsi_remove_device(hba->sdev_ufs_device);
4109 hba->sdev_ufs_device = NULL;
4110 }
4111
4112 if (hba->sdev_boot) {
4113 scsi_remove_device(hba->sdev_boot);
4114 hba->sdev_boot = NULL;
4115 }
4116
4117 if (hba->sdev_rpmb) {
4118 scsi_remove_device(hba->sdev_rpmb);
4119 hba->sdev_rpmb = NULL;
4120 }
4121}
4122
4123/**
4124 * ufshcd_probe_hba - probe hba to detect device and initialize 4126 * ufshcd_probe_hba - probe hba to detect device and initialize
4125 * @hba: per-adapter instance 4127 * @hba: per-adapter instance
4126 * 4128 *
@@ -4134,6 +4136,8 @@ static int ufshcd_probe_hba(struct ufs_hba *hba)
4134 if (ret) 4136 if (ret)
4135 goto out; 4137 goto out;
4136 4138
4139 ufshcd_init_pwr_info(hba);
4140
4137 /* UniPro link is active now */ 4141 /* UniPro link is active now */
4138 ufshcd_set_link_active(hba); 4142 ufshcd_set_link_active(hba);
4139 4143
@@ -4264,12 +4268,18 @@ static int ufshcd_config_vreg_load(struct device *dev, struct ufs_vreg *vreg,
4264static inline int ufshcd_config_vreg_lpm(struct ufs_hba *hba, 4268static inline int ufshcd_config_vreg_lpm(struct ufs_hba *hba,
4265 struct ufs_vreg *vreg) 4269 struct ufs_vreg *vreg)
4266{ 4270{
4271 if (!vreg)
4272 return 0;
4273
4267 return ufshcd_config_vreg_load(hba->dev, vreg, UFS_VREG_LPM_LOAD_UA); 4274 return ufshcd_config_vreg_load(hba->dev, vreg, UFS_VREG_LPM_LOAD_UA);
4268} 4275}
4269 4276
4270static inline int ufshcd_config_vreg_hpm(struct ufs_hba *hba, 4277static inline int ufshcd_config_vreg_hpm(struct ufs_hba *hba,
4271 struct ufs_vreg *vreg) 4278 struct ufs_vreg *vreg)
4272{ 4279{
4280 if (!vreg)
4281 return 0;
4282
4273 return ufshcd_config_vreg_load(hba->dev, vreg, vreg->max_uA); 4283 return ufshcd_config_vreg_load(hba->dev, vreg, vreg->max_uA);
4274} 4284}
4275 4285
@@ -4471,7 +4481,7 @@ out:
4471 if (!IS_ERR_OR_NULL(clki->clk) && clki->enabled) 4481 if (!IS_ERR_OR_NULL(clki->clk) && clki->enabled)
4472 clk_disable_unprepare(clki->clk); 4482 clk_disable_unprepare(clki->clk);
4473 } 4483 }
4474 } else if (!ret && on) { 4484 } else if (on) {
4475 spin_lock_irqsave(hba->host->host_lock, flags); 4485 spin_lock_irqsave(hba->host->host_lock, flags);
4476 hba->clk_gating.state = CLKS_ON; 4486 hba->clk_gating.state = CLKS_ON;
4477 spin_unlock_irqrestore(hba->host->host_lock, flags); 4487 spin_unlock_irqrestore(hba->host->host_lock, flags);
@@ -4675,11 +4685,25 @@ static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba,
4675{ 4685{
4676 unsigned char cmd[6] = { START_STOP }; 4686 unsigned char cmd[6] = { START_STOP };
4677 struct scsi_sense_hdr sshdr; 4687 struct scsi_sense_hdr sshdr;
4678 struct scsi_device *sdp = hba->sdev_ufs_device; 4688 struct scsi_device *sdp;
4689 unsigned long flags;
4679 int ret; 4690 int ret;
4680 4691
4681 if (!sdp || !scsi_device_online(sdp)) 4692 spin_lock_irqsave(hba->host->host_lock, flags);
4682 return -ENODEV; 4693 sdp = hba->sdev_ufs_device;
4694 if (sdp) {
4695 ret = scsi_device_get(sdp);
4696 if (!ret && !scsi_device_online(sdp)) {
4697 ret = -ENODEV;
4698 scsi_device_put(sdp);
4699 }
4700 } else {
4701 ret = -ENODEV;
4702 }
4703 spin_unlock_irqrestore(hba->host->host_lock, flags);
4704
4705 if (ret)
4706 return ret;
4683 4707
4684 /* 4708 /*
4685 * If scsi commands fail, the scsi mid-layer schedules scsi error- 4709 * If scsi commands fail, the scsi mid-layer schedules scsi error-
@@ -4718,6 +4742,7 @@ static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba,
4718 if (!ret) 4742 if (!ret)
4719 hba->curr_dev_pwr_mode = pwr_mode; 4743 hba->curr_dev_pwr_mode = pwr_mode;
4720out: 4744out:
4745 scsi_device_put(sdp);
4721 hba->host->eh_noresume = 0; 4746 hba->host->eh_noresume = 0;
4722 return ret; 4747 return ret;
4723} 4748}
@@ -5087,7 +5112,7 @@ int ufshcd_system_suspend(struct ufs_hba *hba)
5087 int ret = 0; 5112 int ret = 0;
5088 5113
5089 if (!hba || !hba->is_powered) 5114 if (!hba || !hba->is_powered)
5090 goto out; 5115 return 0;
5091 5116
5092 if (pm_runtime_suspended(hba->dev)) { 5117 if (pm_runtime_suspended(hba->dev)) {
5093 if (hba->rpm_lvl == hba->spm_lvl) 5118 if (hba->rpm_lvl == hba->spm_lvl)
@@ -5231,7 +5256,6 @@ EXPORT_SYMBOL(ufshcd_shutdown);
5231void ufshcd_remove(struct ufs_hba *hba) 5256void ufshcd_remove(struct ufs_hba *hba)
5232{ 5257{
5233 scsi_remove_host(hba->host); 5258 scsi_remove_host(hba->host);
5234 ufshcd_scsi_remove_wlus(hba);
5235 /* disable interrupts */ 5259 /* disable interrupts */
5236 ufshcd_disable_intr(hba, hba->intr_mask); 5260 ufshcd_disable_intr(hba, hba->intr_mask);
5237 ufshcd_hba_stop(hba); 5261 ufshcd_hba_stop(hba);
diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
index 58ecdff5065c..4a574aa45855 100644
--- a/drivers/scsi/ufs/ufshcd.h
+++ b/drivers/scsi/ufs/ufshcd.h
@@ -392,8 +392,6 @@ struct ufs_hba {
392 * "UFS device" W-LU. 392 * "UFS device" W-LU.
393 */ 393 */
394 struct scsi_device *sdev_ufs_device; 394 struct scsi_device *sdev_ufs_device;
395 struct scsi_device *sdev_rpmb;
396 struct scsi_device *sdev_boot;
397 395
398 enum ufs_dev_pwr_mode curr_dev_pwr_mode; 396 enum ufs_dev_pwr_mode curr_dev_pwr_mode;
399 enum uic_link_state uic_link_state; 397 enum uic_link_state uic_link_state;
diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c
index 72e12bad14b9..d0d5542efc06 100644
--- a/drivers/spi/spi-dw.c
+++ b/drivers/spi/spi-dw.c
@@ -376,9 +376,6 @@ static void pump_transfers(unsigned long data)
376 chip = dws->cur_chip; 376 chip = dws->cur_chip;
377 spi = message->spi; 377 spi = message->spi;
378 378
379 if (unlikely(!chip->clk_div))
380 chip->clk_div = dws->max_freq / chip->speed_hz;
381
382 if (message->state == ERROR_STATE) { 379 if (message->state == ERROR_STATE) {
383 message->status = -EIO; 380 message->status = -EIO;
384 goto early_exit; 381 goto early_exit;
@@ -419,7 +416,7 @@ static void pump_transfers(unsigned long data)
419 if (transfer->speed_hz) { 416 if (transfer->speed_hz) {
420 speed = chip->speed_hz; 417 speed = chip->speed_hz;
421 418
422 if (transfer->speed_hz != speed) { 419 if ((transfer->speed_hz != speed) || (!chip->clk_div)) {
423 speed = transfer->speed_hz; 420 speed = transfer->speed_hz;
424 421
425 /* clk_div doesn't support odd number */ 422 /* clk_div doesn't support odd number */
@@ -581,7 +578,6 @@ static int dw_spi_setup(struct spi_device *spi)
581 dev_err(&spi->dev, "No max speed HZ parameter\n"); 578 dev_err(&spi->dev, "No max speed HZ parameter\n");
582 return -EINVAL; 579 return -EINVAL;
583 } 580 }
584 chip->speed_hz = spi->max_speed_hz;
585 581
586 chip->tmode = 0; /* Tx & Rx */ 582 chip->tmode = 0; /* Tx & Rx */
587 /* Default SPI mode is SCPOL = 0, SCPH = 0 */ 583 /* Default SPI mode is SCPOL = 0, SCPH = 0 */
diff --git a/drivers/spi/spi-sirf.c b/drivers/spi/spi-sirf.c
index 39e2c0a55a28..f63de781c729 100644
--- a/drivers/spi/spi-sirf.c
+++ b/drivers/spi/spi-sirf.c
@@ -562,9 +562,9 @@ spi_sirfsoc_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
562 562
563 sspi->word_width = DIV_ROUND_UP(bits_per_word, 8); 563 sspi->word_width = DIV_ROUND_UP(bits_per_word, 8);
564 txfifo_ctrl = SIRFSOC_SPI_FIFO_THD(SIRFSOC_SPI_FIFO_SIZE / 2) | 564 txfifo_ctrl = SIRFSOC_SPI_FIFO_THD(SIRFSOC_SPI_FIFO_SIZE / 2) |
565 sspi->word_width; 565 (sspi->word_width >> 1);
566 rxfifo_ctrl = SIRFSOC_SPI_FIFO_THD(SIRFSOC_SPI_FIFO_SIZE / 2) | 566 rxfifo_ctrl = SIRFSOC_SPI_FIFO_THD(SIRFSOC_SPI_FIFO_SIZE / 2) |
567 sspi->word_width; 567 (sspi->word_width >> 1);
568 568
569 if (!(spi->mode & SPI_CS_HIGH)) 569 if (!(spi->mode & SPI_CS_HIGH))
570 regval |= SIRFSOC_SPI_CS_IDLE_STAT; 570 regval |= SIRFSOC_SPI_CS_IDLE_STAT;
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index ebcb33df2eb2..50f20f243981 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -615,13 +615,13 @@ static int spi_map_buf(struct spi_master *master, struct device *dev,
615 sg_free_table(sgt); 615 sg_free_table(sgt);
616 return -ENOMEM; 616 return -ENOMEM;
617 } 617 }
618 sg_buf = page_address(vm_page) + 618 sg_set_page(&sgt->sgl[i], vm_page,
619 ((size_t)buf & ~PAGE_MASK); 619 min, offset_in_page(buf));
620 } else { 620 } else {
621 sg_buf = buf; 621 sg_buf = buf;
622 sg_set_buf(&sgt->sgl[i], sg_buf, min);
622 } 623 }
623 624
624 sg_set_buf(&sgt->sgl[i], sg_buf, min);
625 625
626 buf += min; 626 buf += min;
627 len -= min; 627 len -= min;
diff --git a/drivers/staging/rtl8188eu/core/rtw_cmd.c b/drivers/staging/rtl8188eu/core/rtw_cmd.c
index 9935e66935af..eddef9cd2e16 100644
--- a/drivers/staging/rtl8188eu/core/rtw_cmd.c
+++ b/drivers/staging/rtl8188eu/core/rtw_cmd.c
@@ -275,11 +275,11 @@ u8 rtw_sitesurvey_cmd(struct adapter *padapter, struct ndis_802_11_ssid *ssid,
275 if (check_fwstate(pmlmepriv, _FW_LINKED) == true) 275 if (check_fwstate(pmlmepriv, _FW_LINKED) == true)
276 rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_SCAN, 1); 276 rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_SCAN, 1);
277 277
278 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); 278 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
279 if (ph2c == NULL) 279 if (ph2c == NULL)
280 return _FAIL; 280 return _FAIL;
281 281
282 psurveyPara = kzalloc(sizeof(struct sitesurvey_parm), GFP_KERNEL); 282 psurveyPara = kzalloc(sizeof(struct sitesurvey_parm), GFP_ATOMIC);
283 if (psurveyPara == NULL) { 283 if (psurveyPara == NULL) {
284 kfree(ph2c); 284 kfree(ph2c);
285 return _FAIL; 285 return _FAIL;
@@ -405,7 +405,7 @@ u8 rtw_joinbss_cmd(struct adapter *padapter, struct wlan_network *pnetwork)
405 else 405 else
406 RT_TRACE(_module_rtl871x_cmd_c_, _drv_notice_, ("+Join cmd: SSid =[%s]\n", pmlmepriv->assoc_ssid.Ssid)); 406 RT_TRACE(_module_rtl871x_cmd_c_, _drv_notice_, ("+Join cmd: SSid =[%s]\n", pmlmepriv->assoc_ssid.Ssid));
407 407
408 pcmd = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); 408 pcmd = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
409 if (pcmd == NULL) { 409 if (pcmd == NULL) {
410 res = _FAIL; 410 res = _FAIL;
411 RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_, ("rtw_joinbss_cmd: memory allocate for cmd_obj fail!!!\n")); 411 RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_, ("rtw_joinbss_cmd: memory allocate for cmd_obj fail!!!\n"));
@@ -755,13 +755,13 @@ u8 rtw_dynamic_chk_wk_cmd(struct adapter *padapter)
755 u8 res = _SUCCESS; 755 u8 res = _SUCCESS;
756 756
757 757
758 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); 758 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
759 if (ph2c == NULL) { 759 if (ph2c == NULL) {
760 res = _FAIL; 760 res = _FAIL;
761 goto exit; 761 goto exit;
762 } 762 }
763 763
764 pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_KERNEL); 764 pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_ATOMIC);
765 if (pdrvextra_cmd_parm == NULL) { 765 if (pdrvextra_cmd_parm == NULL) {
766 kfree(ph2c); 766 kfree(ph2c);
767 res = _FAIL; 767 res = _FAIL;
@@ -967,13 +967,13 @@ u8 rtw_lps_ctrl_wk_cmd(struct adapter *padapter, u8 lps_ctrl_type, u8 enqueue)
967 u8 res = _SUCCESS; 967 u8 res = _SUCCESS;
968 968
969 if (enqueue) { 969 if (enqueue) {
970 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); 970 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
971 if (ph2c == NULL) { 971 if (ph2c == NULL) {
972 res = _FAIL; 972 res = _FAIL;
973 goto exit; 973 goto exit;
974 } 974 }
975 975
976 pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_KERNEL); 976 pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_ATOMIC);
977 if (pdrvextra_cmd_parm == NULL) { 977 if (pdrvextra_cmd_parm == NULL) {
978 kfree(ph2c); 978 kfree(ph2c);
979 res = _FAIL; 979 res = _FAIL;
@@ -1010,13 +1010,13 @@ u8 rtw_rpt_timer_cfg_cmd(struct adapter *padapter, u16 min_time)
1010 1010
1011 u8 res = _SUCCESS; 1011 u8 res = _SUCCESS;
1012 1012
1013 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); 1013 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
1014 if (ph2c == NULL) { 1014 if (ph2c == NULL) {
1015 res = _FAIL; 1015 res = _FAIL;
1016 goto exit; 1016 goto exit;
1017 } 1017 }
1018 1018
1019 pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_KERNEL); 1019 pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_ATOMIC);
1020 if (pdrvextra_cmd_parm == NULL) { 1020 if (pdrvextra_cmd_parm == NULL) {
1021 kfree(ph2c); 1021 kfree(ph2c);
1022 res = _FAIL; 1022 res = _FAIL;
@@ -1088,13 +1088,13 @@ u8 rtw_ps_cmd(struct adapter *padapter)
1088 1088
1089 u8 res = _SUCCESS; 1089 u8 res = _SUCCESS;
1090 1090
1091 ppscmd = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); 1091 ppscmd = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
1092 if (ppscmd == NULL) { 1092 if (ppscmd == NULL) {
1093 res = _FAIL; 1093 res = _FAIL;
1094 goto exit; 1094 goto exit;
1095 } 1095 }
1096 1096
1097 pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_KERNEL); 1097 pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_ATOMIC);
1098 if (pdrvextra_cmd_parm == NULL) { 1098 if (pdrvextra_cmd_parm == NULL) {
1099 kfree(ppscmd); 1099 kfree(ppscmd);
1100 res = _FAIL; 1100 res = _FAIL;
diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
index 5ba5099ec20d..70b1bc3e0e63 100644
--- a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
@@ -4241,12 +4241,12 @@ void report_survey_event(struct adapter *padapter,
4241 pcmdpriv = &padapter->cmdpriv; 4241 pcmdpriv = &padapter->cmdpriv;
4242 4242
4243 4243
4244 pcmd_obj = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); 4244 pcmd_obj = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
4245 if (pcmd_obj == NULL) 4245 if (pcmd_obj == NULL)
4246 return; 4246 return;
4247 4247
4248 cmdsz = (sizeof(struct survey_event) + sizeof(struct C2HEvent_Header)); 4248 cmdsz = (sizeof(struct survey_event) + sizeof(struct C2HEvent_Header));
4249 pevtcmd = kzalloc(cmdsz, GFP_KERNEL); 4249 pevtcmd = kzalloc(cmdsz, GFP_ATOMIC);
4250 if (pevtcmd == NULL) { 4250 if (pevtcmd == NULL) {
4251 kfree(pcmd_obj); 4251 kfree(pcmd_obj);
4252 return; 4252 return;
@@ -4339,12 +4339,12 @@ void report_join_res(struct adapter *padapter, int res)
4339 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 4339 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
4340 struct cmd_priv *pcmdpriv = &padapter->cmdpriv; 4340 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
4341 4341
4342 pcmd_obj = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); 4342 pcmd_obj = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
4343 if (pcmd_obj == NULL) 4343 if (pcmd_obj == NULL)
4344 return; 4344 return;
4345 4345
4346 cmdsz = (sizeof(struct joinbss_event) + sizeof(struct C2HEvent_Header)); 4346 cmdsz = (sizeof(struct joinbss_event) + sizeof(struct C2HEvent_Header));
4347 pevtcmd = kzalloc(cmdsz, GFP_KERNEL); 4347 pevtcmd = kzalloc(cmdsz, GFP_ATOMIC);
4348 if (pevtcmd == NULL) { 4348 if (pevtcmd == NULL) {
4349 kfree(pcmd_obj); 4349 kfree(pcmd_obj);
4350 return; 4350 return;
@@ -4854,11 +4854,11 @@ void survey_timer_hdl(void *function_context)
4854 pmlmeext->scan_abort = false;/* reset */ 4854 pmlmeext->scan_abort = false;/* reset */
4855 } 4855 }
4856 4856
4857 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); 4857 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
4858 if (ph2c == NULL) 4858 if (ph2c == NULL)
4859 goto exit_survey_timer_hdl; 4859 goto exit_survey_timer_hdl;
4860 4860
4861 psurveyPara = kzalloc(sizeof(struct sitesurvey_parm), GFP_KERNEL); 4861 psurveyPara = kzalloc(sizeof(struct sitesurvey_parm), GFP_ATOMIC);
4862 if (psurveyPara == NULL) { 4862 if (psurveyPara == NULL) {
4863 kfree(ph2c); 4863 kfree(ph2c);
4864 goto exit_survey_timer_hdl; 4864 goto exit_survey_timer_hdl;
diff --git a/drivers/staging/rtl8188eu/core/rtw_wlan_util.c b/drivers/staging/rtl8188eu/core/rtw_wlan_util.c
index 33ccbbbd8ed6..d300369977fa 100644
--- a/drivers/staging/rtl8188eu/core/rtw_wlan_util.c
+++ b/drivers/staging/rtl8188eu/core/rtw_wlan_util.c
@@ -935,7 +935,7 @@ int rtw_check_bcn_info(struct adapter *Adapter, u8 *pframe, u32 packet_len)
935 return true; 935 return true;
936 } 936 }
937 937
938 bssid = kzalloc(sizeof(struct wlan_bssid_ex), GFP_KERNEL); 938 bssid = kzalloc(sizeof(struct wlan_bssid_ex), GFP_ATOMIC);
939 939
940 subtype = GetFrameSubType(pframe) >> 4; 940 subtype = GetFrameSubType(pframe) >> 4;
941 941
diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
index 407a318b09db..2f87150a21b7 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
@@ -47,6 +47,7 @@ static struct usb_device_id rtw_usb_id_tbl[] = {
47 {USB_DEVICE(0x07b8, 0x8179)}, /* Abocom - Abocom */ 47 {USB_DEVICE(0x07b8, 0x8179)}, /* Abocom - Abocom */
48 {USB_DEVICE(0x2001, 0x330F)}, /* DLink DWA-125 REV D1 */ 48 {USB_DEVICE(0x2001, 0x330F)}, /* DLink DWA-125 REV D1 */
49 {USB_DEVICE(0x2001, 0x3310)}, /* Dlink DWA-123 REV D1 */ 49 {USB_DEVICE(0x2001, 0x3310)}, /* Dlink DWA-123 REV D1 */
50 {USB_DEVICE(0x2001, 0x3311)}, /* DLink GO-USB-N150 REV B1 */
50 {USB_DEVICE(0x0df6, 0x0076)}, /* Sitecom N150 v2 */ 51 {USB_DEVICE(0x0df6, 0x0076)}, /* Sitecom N150 v2 */
51 {} /* Terminating entry */ 52 {} /* Terminating entry */
52}; 53};
diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
index b19e4329ba00..73e58d22e325 100644
--- a/drivers/target/iscsi/iscsi_target.c
+++ b/drivers/target/iscsi/iscsi_target.c
@@ -3491,7 +3491,7 @@ iscsit_build_sendtargets_response(struct iscsi_cmd *cmd,
3491 len = sprintf(buf, "TargetAddress=" 3491 len = sprintf(buf, "TargetAddress="
3492 "%s:%hu,%hu", 3492 "%s:%hu,%hu",
3493 inaddr_any ? conn->local_ip : np->np_ip, 3493 inaddr_any ? conn->local_ip : np->np_ip,
3494 inaddr_any ? conn->local_port : np->np_port, 3494 np->np_port,
3495 tpg->tpgt); 3495 tpg->tpgt);
3496 len += 1; 3496 len += 1;
3497 3497
diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
index 8c60a1a1ae8d..9f93b8234095 100644
--- a/drivers/target/target_core_pr.c
+++ b/drivers/target/target_core_pr.c
@@ -2738,7 +2738,8 @@ core_scsi3_pro_preempt(struct se_cmd *cmd, int type, int scope, u64 res_key,
2738 struct t10_pr_registration *pr_reg, *pr_reg_tmp, *pr_reg_n, *pr_res_holder; 2738 struct t10_pr_registration *pr_reg, *pr_reg_tmp, *pr_reg_n, *pr_res_holder;
2739 struct t10_reservation *pr_tmpl = &dev->t10_pr; 2739 struct t10_reservation *pr_tmpl = &dev->t10_pr;
2740 u32 pr_res_mapped_lun = 0; 2740 u32 pr_res_mapped_lun = 0;
2741 int all_reg = 0, calling_it_nexus = 0, released_regs = 0; 2741 int all_reg = 0, calling_it_nexus = 0;
2742 bool sa_res_key_unmatched = sa_res_key != 0;
2742 int prh_type = 0, prh_scope = 0; 2743 int prh_type = 0, prh_scope = 0;
2743 2744
2744 if (!se_sess) 2745 if (!se_sess)
@@ -2813,6 +2814,7 @@ core_scsi3_pro_preempt(struct se_cmd *cmd, int type, int scope, u64 res_key,
2813 if (!all_reg) { 2814 if (!all_reg) {
2814 if (pr_reg->pr_res_key != sa_res_key) 2815 if (pr_reg->pr_res_key != sa_res_key)
2815 continue; 2816 continue;
2817 sa_res_key_unmatched = false;
2816 2818
2817 calling_it_nexus = (pr_reg_n == pr_reg) ? 1 : 0; 2819 calling_it_nexus = (pr_reg_n == pr_reg) ? 1 : 0;
2818 pr_reg_nacl = pr_reg->pr_reg_nacl; 2820 pr_reg_nacl = pr_reg->pr_reg_nacl;
@@ -2820,7 +2822,6 @@ core_scsi3_pro_preempt(struct se_cmd *cmd, int type, int scope, u64 res_key,
2820 __core_scsi3_free_registration(dev, pr_reg, 2822 __core_scsi3_free_registration(dev, pr_reg,
2821 (preempt_type == PREEMPT_AND_ABORT) ? &preempt_and_abort_list : 2823 (preempt_type == PREEMPT_AND_ABORT) ? &preempt_and_abort_list :
2822 NULL, calling_it_nexus); 2824 NULL, calling_it_nexus);
2823 released_regs++;
2824 } else { 2825 } else {
2825 /* 2826 /*
2826 * Case for any existing all registrants type 2827 * Case for any existing all registrants type
@@ -2838,6 +2839,7 @@ core_scsi3_pro_preempt(struct se_cmd *cmd, int type, int scope, u64 res_key,
2838 if ((sa_res_key) && 2839 if ((sa_res_key) &&
2839 (pr_reg->pr_res_key != sa_res_key)) 2840 (pr_reg->pr_res_key != sa_res_key))
2840 continue; 2841 continue;
2842 sa_res_key_unmatched = false;
2841 2843
2842 calling_it_nexus = (pr_reg_n == pr_reg) ? 1 : 0; 2844 calling_it_nexus = (pr_reg_n == pr_reg) ? 1 : 0;
2843 if (calling_it_nexus) 2845 if (calling_it_nexus)
@@ -2848,7 +2850,6 @@ core_scsi3_pro_preempt(struct se_cmd *cmd, int type, int scope, u64 res_key,
2848 __core_scsi3_free_registration(dev, pr_reg, 2850 __core_scsi3_free_registration(dev, pr_reg,
2849 (preempt_type == PREEMPT_AND_ABORT) ? &preempt_and_abort_list : 2851 (preempt_type == PREEMPT_AND_ABORT) ? &preempt_and_abort_list :
2850 NULL, 0); 2852 NULL, 0);
2851 released_regs++;
2852 } 2853 }
2853 if (!calling_it_nexus) 2854 if (!calling_it_nexus)
2854 core_scsi3_ua_allocate(pr_reg_nacl, 2855 core_scsi3_ua_allocate(pr_reg_nacl,
@@ -2863,7 +2864,7 @@ core_scsi3_pro_preempt(struct se_cmd *cmd, int type, int scope, u64 res_key,
2863 * registered reservation key, then the device server shall 2864 * registered reservation key, then the device server shall
2864 * complete the command with RESERVATION CONFLICT status. 2865 * complete the command with RESERVATION CONFLICT status.
2865 */ 2866 */
2866 if (!released_regs) { 2867 if (sa_res_key_unmatched) {
2867 spin_unlock(&dev->dev_reservation_lock); 2868 spin_unlock(&dev->dev_reservation_lock);
2868 core_scsi3_put_pr_reg(pr_reg_n); 2869 core_scsi3_put_pr_reg(pr_reg_n);
2869 return TCM_RESERVATION_CONFLICT; 2870 return TCM_RESERVATION_CONFLICT;
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 9ea0d5f03f7a..be877bf6f730 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -2292,7 +2292,7 @@ transport_generic_new_cmd(struct se_cmd *cmd)
2292 * and let it call back once the write buffers are ready. 2292 * and let it call back once the write buffers are ready.
2293 */ 2293 */
2294 target_add_to_state_list(cmd); 2294 target_add_to_state_list(cmd);
2295 if (cmd->data_direction != DMA_TO_DEVICE) { 2295 if (cmd->data_direction != DMA_TO_DEVICE || cmd->data_length == 0) {
2296 target_execute_cmd(cmd); 2296 target_execute_cmd(cmd);
2297 return 0; 2297 return 0;
2298 } 2298 }
diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 1ab0018271c5..ad09e51ffae4 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -50,15 +50,14 @@ struct cpufreq_cooling_device {
50 unsigned int cpufreq_state; 50 unsigned int cpufreq_state;
51 unsigned int cpufreq_val; 51 unsigned int cpufreq_val;
52 struct cpumask allowed_cpus; 52 struct cpumask allowed_cpus;
53 struct list_head node;
53}; 54};
54static DEFINE_IDR(cpufreq_idr); 55static DEFINE_IDR(cpufreq_idr);
55static DEFINE_MUTEX(cooling_cpufreq_lock); 56static DEFINE_MUTEX(cooling_cpufreq_lock);
56 57
57static unsigned int cpufreq_dev_count; 58static unsigned int cpufreq_dev_count;
58 59
59/* notify_table passes value to the CPUFREQ_ADJUST callback function. */ 60static LIST_HEAD(cpufreq_dev_list);
60#define NOTIFY_INVALID NULL
61static struct cpufreq_cooling_device *notify_device;
62 61
63/** 62/**
64 * get_idr - function to get a unique id. 63 * get_idr - function to get a unique id.
@@ -287,15 +286,12 @@ static int cpufreq_apply_cooling(struct cpufreq_cooling_device *cpufreq_device,
287 286
288 cpufreq_device->cpufreq_state = cooling_state; 287 cpufreq_device->cpufreq_state = cooling_state;
289 cpufreq_device->cpufreq_val = clip_freq; 288 cpufreq_device->cpufreq_val = clip_freq;
290 notify_device = cpufreq_device;
291 289
292 for_each_cpu(cpuid, mask) { 290 for_each_cpu(cpuid, mask) {
293 if (is_cpufreq_valid(cpuid)) 291 if (is_cpufreq_valid(cpuid))
294 cpufreq_update_policy(cpuid); 292 cpufreq_update_policy(cpuid);
295 } 293 }
296 294
297 notify_device = NOTIFY_INVALID;
298
299 return 0; 295 return 0;
300} 296}
301 297
@@ -316,21 +312,28 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb,
316{ 312{
317 struct cpufreq_policy *policy = data; 313 struct cpufreq_policy *policy = data;
318 unsigned long max_freq = 0; 314 unsigned long max_freq = 0;
315 struct cpufreq_cooling_device *cpufreq_dev;
319 316
320 if (event != CPUFREQ_ADJUST || notify_device == NOTIFY_INVALID) 317 if (event != CPUFREQ_ADJUST)
321 return 0; 318 return 0;
322 319
323 if (cpumask_test_cpu(policy->cpu, &notify_device->allowed_cpus)) 320 mutex_lock(&cooling_cpufreq_lock);
324 max_freq = notify_device->cpufreq_val; 321 list_for_each_entry(cpufreq_dev, &cpufreq_dev_list, node) {
325 else 322 if (!cpumask_test_cpu(policy->cpu,
326 return 0; 323 &cpufreq_dev->allowed_cpus))
324 continue;
325
326 if (!cpufreq_dev->cpufreq_val)
327 cpufreq_dev->cpufreq_val = get_cpu_frequency(
328 cpumask_any(&cpufreq_dev->allowed_cpus),
329 cpufreq_dev->cpufreq_state);
327 330
328 /* Never exceed user_policy.max */ 331 max_freq = cpufreq_dev->cpufreq_val;
329 if (max_freq > policy->user_policy.max)
330 max_freq = policy->user_policy.max;
331 332
332 if (policy->max != max_freq) 333 if (policy->max != max_freq)
333 cpufreq_verify_within_limits(policy, 0, max_freq); 334 cpufreq_verify_within_limits(policy, 0, max_freq);
335 }
336 mutex_unlock(&cooling_cpufreq_lock);
334 337
335 return 0; 338 return 0;
336} 339}
@@ -486,6 +489,7 @@ __cpufreq_cooling_register(struct device_node *np,
486 cpufreq_register_notifier(&thermal_cpufreq_notifier_block, 489 cpufreq_register_notifier(&thermal_cpufreq_notifier_block,
487 CPUFREQ_POLICY_NOTIFIER); 490 CPUFREQ_POLICY_NOTIFIER);
488 cpufreq_dev_count++; 491 cpufreq_dev_count++;
492 list_add(&cpufreq_dev->node, &cpufreq_dev_list);
489 493
490 mutex_unlock(&cooling_cpufreq_lock); 494 mutex_unlock(&cooling_cpufreq_lock);
491 495
@@ -549,6 +553,7 @@ void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
549 553
550 cpufreq_dev = cdev->devdata; 554 cpufreq_dev = cdev->devdata;
551 mutex_lock(&cooling_cpufreq_lock); 555 mutex_lock(&cooling_cpufreq_lock);
556 list_del(&cpufreq_dev->node);
552 cpufreq_dev_count--; 557 cpufreq_dev_count--;
553 558
554 /* Unregister the notifier for the last cpufreq cooling device */ 559 /* Unregister the notifier for the last cpufreq cooling device */
diff --git a/drivers/thermal/samsung/exynos_thermal_common.c b/drivers/thermal/samsung/exynos_thermal_common.c
index 3f5ad25ddca8..b6be572704a4 100644
--- a/drivers/thermal/samsung/exynos_thermal_common.c
+++ b/drivers/thermal/samsung/exynos_thermal_common.c
@@ -417,13 +417,10 @@ void exynos_unregister_thermal(struct thermal_sensor_conf *sensor_conf)
417 417
418 th_zone = sensor_conf->pzone_data; 418 th_zone = sensor_conf->pzone_data;
419 419
420 if (th_zone->therm_dev) 420 thermal_zone_device_unregister(th_zone->therm_dev);
421 thermal_zone_device_unregister(th_zone->therm_dev);
422 421
423 for (i = 0; i < th_zone->cool_dev_size; i++) { 422 for (i = 0; i < th_zone->cool_dev_size; ++i)
424 if (th_zone->cool_dev[i]) 423 cpufreq_cooling_unregister(th_zone->cool_dev[i]);
425 cpufreq_cooling_unregister(th_zone->cool_dev[i]);
426 }
427 424
428 dev_info(sensor_conf->dev, 425 dev_info(sensor_conf->dev,
429 "Exynos: Kernel Thermal management unregistered\n"); 426 "Exynos: Kernel Thermal management unregistered\n");
diff --git a/drivers/thermal/st/st_thermal.c b/drivers/thermal/st/st_thermal.c
index 90163b384660..d1ec5804c0bb 100644
--- a/drivers/thermal/st/st_thermal.c
+++ b/drivers/thermal/st/st_thermal.c
@@ -275,6 +275,7 @@ int st_thermal_unregister(struct platform_device *pdev)
275} 275}
276EXPORT_SYMBOL_GPL(st_thermal_unregister); 276EXPORT_SYMBOL_GPL(st_thermal_unregister);
277 277
278#ifdef CONFIG_PM_SLEEP
278static int st_thermal_suspend(struct device *dev) 279static int st_thermal_suspend(struct device *dev)
279{ 280{
280 struct platform_device *pdev = to_platform_device(dev); 281 struct platform_device *pdev = to_platform_device(dev);
@@ -305,6 +306,8 @@ static int st_thermal_resume(struct device *dev)
305 306
306 return 0; 307 return 0;
307} 308}
309#endif
310
308SIMPLE_DEV_PM_OPS(st_thermal_pm_ops, st_thermal_suspend, st_thermal_resume); 311SIMPLE_DEV_PM_OPS(st_thermal_pm_ops, st_thermal_suspend, st_thermal_resume);
309EXPORT_SYMBOL_GPL(st_thermal_pm_ops); 312EXPORT_SYMBOL_GPL(st_thermal_pm_ops);
310 313
diff --git a/drivers/tty/serial/of_serial.c b/drivers/tty/serial/of_serial.c
index 56982da4a9e9..bf355050eab6 100644
--- a/drivers/tty/serial/of_serial.c
+++ b/drivers/tty/serial/of_serial.c
@@ -240,32 +240,6 @@ static int of_platform_serial_remove(struct platform_device *ofdev)
240 return 0; 240 return 0;
241} 241}
242 242
243#ifdef CONFIG_PM_SLEEP
244static int of_serial_suspend(struct device *dev)
245{
246 struct of_serial_info *info = dev_get_drvdata(dev);
247
248 serial8250_suspend_port(info->line);
249 if (info->clk)
250 clk_disable_unprepare(info->clk);
251
252 return 0;
253}
254
255static int of_serial_resume(struct device *dev)
256{
257 struct of_serial_info *info = dev_get_drvdata(dev);
258
259 if (info->clk)
260 clk_prepare_enable(info->clk);
261
262 serial8250_resume_port(info->line);
263
264 return 0;
265}
266#endif
267static SIMPLE_DEV_PM_OPS(of_serial_pm_ops, of_serial_suspend, of_serial_resume);
268
269/* 243/*
270 * A few common types, add more as needed. 244 * A few common types, add more as needed.
271 */ 245 */
@@ -297,7 +271,6 @@ static struct platform_driver of_platform_serial_driver = {
297 .name = "of_serial", 271 .name = "of_serial",
298 .owner = THIS_MODULE, 272 .owner = THIS_MODULE,
299 .of_match_table = of_platform_serial_table, 273 .of_match_table = of_platform_serial_table,
300 .pm = &of_serial_pm_ops,
301 }, 274 },
302 .probe = of_platform_serial_probe, 275 .probe = of_platform_serial_probe,
303 .remove = of_platform_serial_remove, 276 .remove = of_platform_serial_remove,
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
index 39b4081b632d..96fafed92b76 100644
--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -44,6 +44,9 @@ static const struct usb_device_id usb_quirk_list[] = {
44 /* Creative SB Audigy 2 NX */ 44 /* Creative SB Audigy 2 NX */
45 { USB_DEVICE(0x041e, 0x3020), .driver_info = USB_QUIRK_RESET_RESUME }, 45 { USB_DEVICE(0x041e, 0x3020), .driver_info = USB_QUIRK_RESET_RESUME },
46 46
47 /* Microsoft Wireless Laser Mouse 6000 Receiver */
48 { USB_DEVICE(0x045e, 0x00e1), .driver_info = USB_QUIRK_RESET_RESUME },
49
47 /* Microsoft LifeCam-VX700 v2.0 */ 50 /* Microsoft LifeCam-VX700 v2.0 */
48 { USB_DEVICE(0x045e, 0x0770), .driver_info = USB_QUIRK_RESET_RESUME }, 51 { USB_DEVICE(0x045e, 0x0770), .driver_info = USB_QUIRK_RESET_RESUME },
49 52
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 711b23019d54..df38e7ef4976 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -791,6 +791,10 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
791 791
792 trb = dwc->ep0_trb; 792 trb = dwc->ep0_trb;
793 793
794 r = next_request(&ep0->request_list);
795 if (!r)
796 return;
797
794 status = DWC3_TRB_SIZE_TRBSTS(trb->size); 798 status = DWC3_TRB_SIZE_TRBSTS(trb->size);
795 if (status == DWC3_TRBSTS_SETUP_PENDING) { 799 if (status == DWC3_TRBSTS_SETUP_PENDING) {
796 dwc3_trace(trace_dwc3_ep0, "Setup Pending received"); 800 dwc3_trace(trace_dwc3_ep0, "Setup Pending received");
@@ -801,10 +805,6 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
801 return; 805 return;
802 } 806 }
803 807
804 r = next_request(&ep0->request_list);
805 if (!r)
806 return;
807
808 ur = &r->request; 808 ur = &r->request;
809 809
810 length = trb->size & DWC3_TRB_SIZE_MASK; 810 length = trb->size & DWC3_TRB_SIZE_MASK;
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 696160d48ae8..388cfd83b6b6 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -22,7 +22,6 @@
22 22
23 23
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/device.h>
26#include <asm/unaligned.h> 25#include <asm/unaligned.h>
27 26
28#include "xhci.h" 27#include "xhci.h"
@@ -1149,9 +1148,7 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
1149 * including the USB 3.0 roothub, but only if CONFIG_PM_RUNTIME 1148 * including the USB 3.0 roothub, but only if CONFIG_PM_RUNTIME
1150 * is enabled, so also enable remote wake here. 1149 * is enabled, so also enable remote wake here.
1151 */ 1150 */
1152 if (hcd->self.root_hub->do_remote_wakeup 1151 if (hcd->self.root_hub->do_remote_wakeup) {
1153 && device_may_wakeup(hcd->self.controller)) {
1154
1155 if (t1 & PORT_CONNECT) { 1152 if (t1 & PORT_CONNECT) {
1156 t2 |= PORT_WKOC_E | PORT_WKDISC_E; 1153 t2 |= PORT_WKOC_E | PORT_WKDISC_E;
1157 t2 &= ~PORT_WKCONN_E; 1154 t2 &= ~PORT_WKCONN_E;
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 9a69b1f1b300..142b601f9563 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -281,7 +281,7 @@ static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
281 if (xhci->quirks & XHCI_COMP_MODE_QUIRK) 281 if (xhci->quirks & XHCI_COMP_MODE_QUIRK)
282 pdev->no_d3cold = true; 282 pdev->no_d3cold = true;
283 283
284 return xhci_suspend(xhci); 284 return xhci_suspend(xhci, do_wakeup);
285} 285}
286 286
287static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated) 287static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated)
diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index 3d78b0cd674b..646300cbe5f7 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -204,7 +204,15 @@ static int xhci_plat_suspend(struct device *dev)
204 struct usb_hcd *hcd = dev_get_drvdata(dev); 204 struct usb_hcd *hcd = dev_get_drvdata(dev);
205 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 205 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
206 206
207 return xhci_suspend(xhci); 207 /*
208 * xhci_suspend() needs `do_wakeup` to know whether host is allowed
209 * to do wakeup during suspend. Since xhci_plat_suspend is currently
210 * only designed for system suspend, device_may_wakeup() is enough
211 * to dertermine whether host is allowed to do wakeup. Need to
212 * reconsider this when xhci_plat_suspend enlarges its scope, e.g.,
213 * also applies to runtime suspend.
214 */
215 return xhci_suspend(xhci, device_may_wakeup(dev));
208} 216}
209 217
210static int xhci_plat_resume(struct device *dev) 218static int xhci_plat_resume(struct device *dev)
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index bc6fcbc16f61..06433aec81d7 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1067,9 +1067,8 @@ static void xhci_handle_cmd_reset_ep(struct xhci_hcd *xhci, int slot_id,
1067 false); 1067 false);
1068 xhci_ring_cmd_db(xhci); 1068 xhci_ring_cmd_db(xhci);
1069 } else { 1069 } else {
1070 /* Clear our internal halted state and restart the ring(s) */ 1070 /* Clear our internal halted state */
1071 xhci->devs[slot_id]->eps[ep_index].ep_state &= ~EP_HALTED; 1071 xhci->devs[slot_id]->eps[ep_index].ep_state &= ~EP_HALTED;
1072 ring_doorbell_for_active_rings(xhci, slot_id, ep_index);
1073 } 1072 }
1074} 1073}
1075 1074
@@ -1823,22 +1822,13 @@ static int finish_td(struct xhci_hcd *xhci, struct xhci_td *td,
1823 ep->stopped_td = td; 1822 ep->stopped_td = td;
1824 return 0; 1823 return 0;
1825 } else { 1824 } else {
1826 if (trb_comp_code == COMP_STALL) { 1825 if (trb_comp_code == COMP_STALL ||
1827 /* The transfer is completed from the driver's 1826 xhci_requires_manual_halt_cleanup(xhci, ep_ctx,
1828 * perspective, but we need to issue a set dequeue 1827 trb_comp_code)) {
1829 * command for this stalled endpoint to move the dequeue 1828 /* Issue a reset endpoint command to clear the host side
1830 * pointer past the TD. We can't do that here because 1829 * halt, followed by a set dequeue command to move the
1831 * the halt condition must be cleared first. Let the 1830 * dequeue pointer past the TD.
1832 * USB class driver clear the stall later. 1831 * The class driver clears the device side halt later.
1833 */
1834 ep->stopped_td = td;
1835 ep->stopped_stream = ep_ring->stream_id;
1836 } else if (xhci_requires_manual_halt_cleanup(xhci,
1837 ep_ctx, trb_comp_code)) {
1838 /* Other types of errors halt the endpoint, but the
1839 * class driver doesn't call usb_reset_endpoint() unless
1840 * the error is -EPIPE. Clear the halted status in the
1841 * xHCI hardware manually.
1842 */ 1832 */
1843 xhci_cleanup_halted_endpoint(xhci, 1833 xhci_cleanup_halted_endpoint(xhci,
1844 slot_id, ep_index, ep_ring->stream_id, 1834 slot_id, ep_index, ep_ring->stream_id,
@@ -1958,9 +1948,7 @@ static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_td *td,
1958 else 1948 else
1959 td->urb->actual_length = 0; 1949 td->urb->actual_length = 0;
1960 1950
1961 xhci_cleanup_halted_endpoint(xhci, 1951 return finish_td(xhci, td, event_trb, event, ep, status, false);
1962 slot_id, ep_index, 0, td, event_trb);
1963 return finish_td(xhci, td, event_trb, event, ep, status, true);
1964 } 1952 }
1965 /* 1953 /*
1966 * Did we transfer any data, despite the errors that might have 1954 * Did we transfer any data, despite the errors that might have
@@ -2519,17 +2507,8 @@ cleanup:
2519 if (ret) { 2507 if (ret) {
2520 urb = td->urb; 2508 urb = td->urb;
2521 urb_priv = urb->hcpriv; 2509 urb_priv = urb->hcpriv;
2522 /* Leave the TD around for the reset endpoint function 2510
2523 * to use(but only if it's not a control endpoint, 2511 xhci_urb_free_priv(xhci, urb_priv);
2524 * since we already queued the Set TR dequeue pointer
2525 * command for stalled control endpoints).
2526 */
2527 if (usb_endpoint_xfer_control(&urb->ep->desc) ||
2528 (trb_comp_code != COMP_STALL &&
2529 trb_comp_code != COMP_BABBLE))
2530 xhci_urb_free_priv(xhci, urb_priv);
2531 else
2532 kfree(urb_priv);
2533 2512
2534 usb_hcd_unlink_urb_from_ep(bus_to_hcd(urb->dev->bus), urb); 2513 usb_hcd_unlink_urb_from_ep(bus_to_hcd(urb->dev->bus), urb);
2535 if ((urb->actual_length != urb->transfer_buffer_length && 2514 if ((urb->actual_length != urb->transfer_buffer_length &&
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 2a5d45b4cb15..033b46c470bd 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -35,6 +35,8 @@
35#define DRIVER_AUTHOR "Sarah Sharp" 35#define DRIVER_AUTHOR "Sarah Sharp"
36#define DRIVER_DESC "'eXtensible' Host Controller (xHC) Driver" 36#define DRIVER_DESC "'eXtensible' Host Controller (xHC) Driver"
37 37
38#define PORT_WAKE_BITS (PORT_WKOC_E | PORT_WKDISC_E | PORT_WKCONN_E)
39
38/* Some 0.95 hardware can't handle the chain bit on a Link TRB being cleared */ 40/* Some 0.95 hardware can't handle the chain bit on a Link TRB being cleared */
39static int link_quirk; 41static int link_quirk;
40module_param(link_quirk, int, S_IRUGO | S_IWUSR); 42module_param(link_quirk, int, S_IRUGO | S_IWUSR);
@@ -851,13 +853,47 @@ static void xhci_clear_command_ring(struct xhci_hcd *xhci)
851 xhci_set_cmd_ring_deq(xhci); 853 xhci_set_cmd_ring_deq(xhci);
852} 854}
853 855
856static void xhci_disable_port_wake_on_bits(struct xhci_hcd *xhci)
857{
858 int port_index;
859 __le32 __iomem **port_array;
860 unsigned long flags;
861 u32 t1, t2;
862
863 spin_lock_irqsave(&xhci->lock, flags);
864
865 /* disble usb3 ports Wake bits*/
866 port_index = xhci->num_usb3_ports;
867 port_array = xhci->usb3_ports;
868 while (port_index--) {
869 t1 = readl(port_array[port_index]);
870 t1 = xhci_port_state_to_neutral(t1);
871 t2 = t1 & ~PORT_WAKE_BITS;
872 if (t1 != t2)
873 writel(t2, port_array[port_index]);
874 }
875
876 /* disble usb2 ports Wake bits*/
877 port_index = xhci->num_usb2_ports;
878 port_array = xhci->usb2_ports;
879 while (port_index--) {
880 t1 = readl(port_array[port_index]);
881 t1 = xhci_port_state_to_neutral(t1);
882 t2 = t1 & ~PORT_WAKE_BITS;
883 if (t1 != t2)
884 writel(t2, port_array[port_index]);
885 }
886
887 spin_unlock_irqrestore(&xhci->lock, flags);
888}
889
854/* 890/*
855 * Stop HC (not bus-specific) 891 * Stop HC (not bus-specific)
856 * 892 *
857 * This is called when the machine transition into S3/S4 mode. 893 * This is called when the machine transition into S3/S4 mode.
858 * 894 *
859 */ 895 */
860int xhci_suspend(struct xhci_hcd *xhci) 896int xhci_suspend(struct xhci_hcd *xhci, bool do_wakeup)
861{ 897{
862 int rc = 0; 898 int rc = 0;
863 unsigned int delay = XHCI_MAX_HALT_USEC; 899 unsigned int delay = XHCI_MAX_HALT_USEC;
@@ -868,6 +904,10 @@ int xhci_suspend(struct xhci_hcd *xhci)
868 xhci->shared_hcd->state != HC_STATE_SUSPENDED) 904 xhci->shared_hcd->state != HC_STATE_SUSPENDED)
869 return -EINVAL; 905 return -EINVAL;
870 906
907 /* Clear root port wake on bits if wakeup not allowed. */
908 if (!do_wakeup)
909 xhci_disable_port_wake_on_bits(xhci);
910
871 /* Don't poll the roothubs on bus suspend. */ 911 /* Don't poll the roothubs on bus suspend. */
872 xhci_dbg(xhci, "%s: stopping port polling.\n", __func__); 912 xhci_dbg(xhci, "%s: stopping port polling.\n", __func__);
873 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); 913 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
@@ -2912,68 +2952,33 @@ void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci,
2912 } 2952 }
2913} 2953}
2914 2954
2915/* Deal with stalled endpoints. The core should have sent the control message 2955/* Called when clearing halted device. The core should have sent the control
2916 * to clear the halt condition. However, we need to make the xHCI hardware 2956 * message to clear the device halt condition. The host side of the halt should
2917 * reset its sequence number, since a device will expect a sequence number of 2957 * already be cleared with a reset endpoint command issued when the STALL tx
2918 * zero after the halt condition is cleared. 2958 * event was received.
2959 *
2919 * Context: in_interrupt 2960 * Context: in_interrupt
2920 */ 2961 */
2962
2921void xhci_endpoint_reset(struct usb_hcd *hcd, 2963void xhci_endpoint_reset(struct usb_hcd *hcd,
2922 struct usb_host_endpoint *ep) 2964 struct usb_host_endpoint *ep)
2923{ 2965{
2924 struct xhci_hcd *xhci; 2966 struct xhci_hcd *xhci;
2925 struct usb_device *udev;
2926 unsigned int ep_index;
2927 unsigned long flags;
2928 int ret;
2929 struct xhci_virt_ep *virt_ep;
2930 struct xhci_command *command;
2931 2967
2932 xhci = hcd_to_xhci(hcd); 2968 xhci = hcd_to_xhci(hcd);
2933 udev = (struct usb_device *) ep->hcpriv;
2934 /* Called with a root hub endpoint (or an endpoint that wasn't added
2935 * with xhci_add_endpoint()
2936 */
2937 if (!ep->hcpriv)
2938 return;
2939 ep_index = xhci_get_endpoint_index(&ep->desc);
2940 virt_ep = &xhci->devs[udev->slot_id]->eps[ep_index];
2941 if (!virt_ep->stopped_td) {
2942 xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep,
2943 "Endpoint 0x%x not halted, refusing to reset.",
2944 ep->desc.bEndpointAddress);
2945 return;
2946 }
2947 if (usb_endpoint_xfer_control(&ep->desc)) {
2948 xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep,
2949 "Control endpoint stall already handled.");
2950 return;
2951 }
2952 2969
2953 command = xhci_alloc_command(xhci, false, false, GFP_ATOMIC);
2954 if (!command)
2955 return;
2956
2957 xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep,
2958 "Queueing reset endpoint command");
2959 spin_lock_irqsave(&xhci->lock, flags);
2960 ret = xhci_queue_reset_ep(xhci, command, udev->slot_id, ep_index);
2961 /* 2970 /*
2962 * Can't change the ring dequeue pointer until it's transitioned to the 2971 * We might need to implement the config ep cmd in xhci 4.8.1 note:
2963 * stopped state, which is only upon a successful reset endpoint 2972 * The Reset Endpoint Command may only be issued to endpoints in the
2964 * command. Better hope that last command worked! 2973 * Halted state. If software wishes reset the Data Toggle or Sequence
2974 * Number of an endpoint that isn't in the Halted state, then software
2975 * may issue a Configure Endpoint Command with the Drop and Add bits set
2976 * for the target endpoint. that is in the Stopped state.
2965 */ 2977 */
2966 if (!ret) {
2967 xhci_cleanup_stalled_ring(xhci, udev, ep_index);
2968 kfree(virt_ep->stopped_td);
2969 xhci_ring_cmd_db(xhci);
2970 }
2971 virt_ep->stopped_td = NULL;
2972 virt_ep->stopped_stream = 0;
2973 spin_unlock_irqrestore(&xhci->lock, flags);
2974 2978
2975 if (ret) 2979 /* For now just print debug to follow the situation */
2976 xhci_warn(xhci, "FIXME allocate a new ring segment\n"); 2980 xhci_dbg(xhci, "Endpoint 0x%x ep reset callback called\n",
2981 ep->desc.bEndpointAddress);
2977} 2982}
2978 2983
2979static int xhci_check_streams_endpoint(struct xhci_hcd *xhci, 2984static int xhci_check_streams_endpoint(struct xhci_hcd *xhci,
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index df76d642e719..d745715a1e2f 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1746,7 +1746,7 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks);
1746void xhci_init_driver(struct hc_driver *drv, int (*setup_fn)(struct usb_hcd *)); 1746void xhci_init_driver(struct hc_driver *drv, int (*setup_fn)(struct usb_hcd *));
1747 1747
1748#ifdef CONFIG_PM 1748#ifdef CONFIG_PM
1749int xhci_suspend(struct xhci_hcd *xhci); 1749int xhci_suspend(struct xhci_hcd *xhci, bool do_wakeup);
1750int xhci_resume(struct xhci_hcd *xhci, bool hibernated); 1750int xhci_resume(struct xhci_hcd *xhci, bool hibernated);
1751#else 1751#else
1752#define xhci_suspend NULL 1752#define xhci_suspend NULL
diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index cfd009dc4018..6c4eb3cf5efd 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -120,6 +120,7 @@ static const struct usb_device_id id_table[] = {
120 { USB_DEVICE(0x10C4, 0x85F8) }, /* Virtenio Preon32 */ 120 { USB_DEVICE(0x10C4, 0x85F8) }, /* Virtenio Preon32 */
121 { USB_DEVICE(0x10C4, 0x8664) }, /* AC-Services CAN-IF */ 121 { USB_DEVICE(0x10C4, 0x8664) }, /* AC-Services CAN-IF */
122 { USB_DEVICE(0x10C4, 0x8665) }, /* AC-Services OBD-IF */ 122 { USB_DEVICE(0x10C4, 0x8665) }, /* AC-Services OBD-IF */
123 { USB_DEVICE(0x10C4, 0x8875) }, /* CEL MeshConnect USB Stick */
123 { USB_DEVICE(0x10C4, 0x88A4) }, /* MMB Networks ZigBee USB Device */ 124 { USB_DEVICE(0x10C4, 0x88A4) }, /* MMB Networks ZigBee USB Device */
124 { USB_DEVICE(0x10C4, 0x88A5) }, /* Planet Innovation Ingeni ZigBee USB Device */ 125 { USB_DEVICE(0x10C4, 0x88A5) }, /* Planet Innovation Ingeni ZigBee USB Device */
125 { USB_DEVICE(0x10C4, 0x8946) }, /* Ketra N1 Wireless Interface */ 126 { USB_DEVICE(0x10C4, 0x8946) }, /* Ketra N1 Wireless Interface */
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 0dad8ce5a609..1ebb351b9e9a 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -470,6 +470,39 @@ static const struct usb_device_id id_table_combined[] = {
470 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FD_PID) }, 470 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FD_PID) },
471 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FE_PID) }, 471 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FE_PID) },
472 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FF_PID) }, 472 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FF_PID) },
473 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_4701_PID) },
474 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9300_PID) },
475 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9301_PID) },
476 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9302_PID) },
477 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9303_PID) },
478 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9304_PID) },
479 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9305_PID) },
480 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9306_PID) },
481 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9307_PID) },
482 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9308_PID) },
483 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9309_PID) },
484 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_930A_PID) },
485 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_930B_PID) },
486 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_930C_PID) },
487 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_930D_PID) },
488 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_930E_PID) },
489 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_930F_PID) },
490 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9310_PID) },
491 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9311_PID) },
492 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9312_PID) },
493 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9313_PID) },
494 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9314_PID) },
495 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9315_PID) },
496 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9316_PID) },
497 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9317_PID) },
498 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9318_PID) },
499 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9319_PID) },
500 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_931A_PID) },
501 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_931B_PID) },
502 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_931C_PID) },
503 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_931D_PID) },
504 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_931E_PID) },
505 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_931F_PID) },
473 { USB_DEVICE(FTDI_VID, FTDI_PERLE_ULTRAPORT_PID) }, 506 { USB_DEVICE(FTDI_VID, FTDI_PERLE_ULTRAPORT_PID) },
474 { USB_DEVICE(FTDI_VID, FTDI_PIEGROUP_PID) }, 507 { USB_DEVICE(FTDI_VID, FTDI_PIEGROUP_PID) },
475 { USB_DEVICE(FTDI_VID, FTDI_TNC_X_PID) }, 508 { USB_DEVICE(FTDI_VID, FTDI_TNC_X_PID) },
diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h
index 6786b705ccf6..e52409c9be99 100644
--- a/drivers/usb/serial/ftdi_sio_ids.h
+++ b/drivers/usb/serial/ftdi_sio_ids.h
@@ -926,8 +926,8 @@
926#define BAYER_CONTOUR_CABLE_PID 0x6001 926#define BAYER_CONTOUR_CABLE_PID 0x6001
927 927
928/* 928/*
929 * The following are the values for the Matrix Orbital FTDI Range 929 * Matrix Orbital Intelligent USB displays.
930 * Anything in this range will use an FT232RL. 930 * http://www.matrixorbital.com
931 */ 931 */
932#define MTXORB_VID 0x1B3D 932#define MTXORB_VID 0x1B3D
933#define MTXORB_FTDI_RANGE_0100_PID 0x0100 933#define MTXORB_FTDI_RANGE_0100_PID 0x0100
@@ -1186,8 +1186,39 @@
1186#define MTXORB_FTDI_RANGE_01FD_PID 0x01FD 1186#define MTXORB_FTDI_RANGE_01FD_PID 0x01FD
1187#define MTXORB_FTDI_RANGE_01FE_PID 0x01FE 1187#define MTXORB_FTDI_RANGE_01FE_PID 0x01FE
1188#define MTXORB_FTDI_RANGE_01FF_PID 0x01FF 1188#define MTXORB_FTDI_RANGE_01FF_PID 0x01FF
1189 1189#define MTXORB_FTDI_RANGE_4701_PID 0x4701
1190 1190#define MTXORB_FTDI_RANGE_9300_PID 0x9300
1191#define MTXORB_FTDI_RANGE_9301_PID 0x9301
1192#define MTXORB_FTDI_RANGE_9302_PID 0x9302
1193#define MTXORB_FTDI_RANGE_9303_PID 0x9303
1194#define MTXORB_FTDI_RANGE_9304_PID 0x9304
1195#define MTXORB_FTDI_RANGE_9305_PID 0x9305
1196#define MTXORB_FTDI_RANGE_9306_PID 0x9306
1197#define MTXORB_FTDI_RANGE_9307_PID 0x9307
1198#define MTXORB_FTDI_RANGE_9308_PID 0x9308
1199#define MTXORB_FTDI_RANGE_9309_PID 0x9309
1200#define MTXORB_FTDI_RANGE_930A_PID 0x930A
1201#define MTXORB_FTDI_RANGE_930B_PID 0x930B
1202#define MTXORB_FTDI_RANGE_930C_PID 0x930C
1203#define MTXORB_FTDI_RANGE_930D_PID 0x930D
1204#define MTXORB_FTDI_RANGE_930E_PID 0x930E
1205#define MTXORB_FTDI_RANGE_930F_PID 0x930F
1206#define MTXORB_FTDI_RANGE_9310_PID 0x9310
1207#define MTXORB_FTDI_RANGE_9311_PID 0x9311
1208#define MTXORB_FTDI_RANGE_9312_PID 0x9312
1209#define MTXORB_FTDI_RANGE_9313_PID 0x9313
1210#define MTXORB_FTDI_RANGE_9314_PID 0x9314
1211#define MTXORB_FTDI_RANGE_9315_PID 0x9315
1212#define MTXORB_FTDI_RANGE_9316_PID 0x9316
1213#define MTXORB_FTDI_RANGE_9317_PID 0x9317
1214#define MTXORB_FTDI_RANGE_9318_PID 0x9318
1215#define MTXORB_FTDI_RANGE_9319_PID 0x9319
1216#define MTXORB_FTDI_RANGE_931A_PID 0x931A
1217#define MTXORB_FTDI_RANGE_931B_PID 0x931B
1218#define MTXORB_FTDI_RANGE_931C_PID 0x931C
1219#define MTXORB_FTDI_RANGE_931D_PID 0x931D
1220#define MTXORB_FTDI_RANGE_931E_PID 0x931E
1221#define MTXORB_FTDI_RANGE_931F_PID 0x931F
1191 1222
1192/* 1223/*
1193 * The Mobility Lab (TML) 1224 * The Mobility Lab (TML)
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
index 93cb7cebda62..077c714f1285 100644
--- a/drivers/usb/serial/keyspan.c
+++ b/drivers/usb/serial/keyspan.c
@@ -311,24 +311,30 @@ static void usa26_indat_callback(struct urb *urb)
311 if ((data[0] & 0x80) == 0) { 311 if ((data[0] & 0x80) == 0) {
312 /* no errors on individual bytes, only 312 /* no errors on individual bytes, only
313 possible overrun err */ 313 possible overrun err */
314 if (data[0] & RXERROR_OVERRUN) 314 if (data[0] & RXERROR_OVERRUN) {
315 err = TTY_OVERRUN; 315 tty_insert_flip_char(&port->port, 0,
316 else 316 TTY_OVERRUN);
317 err = 0; 317 }
318 for (i = 1; i < urb->actual_length ; ++i) 318 for (i = 1; i < urb->actual_length ; ++i)
319 tty_insert_flip_char(&port->port, data[i], err); 319 tty_insert_flip_char(&port->port, data[i],
320 TTY_NORMAL);
320 } else { 321 } else {
321 /* some bytes had errors, every byte has status */ 322 /* some bytes had errors, every byte has status */
322 dev_dbg(&port->dev, "%s - RX error!!!!\n", __func__); 323 dev_dbg(&port->dev, "%s - RX error!!!!\n", __func__);
323 for (i = 0; i + 1 < urb->actual_length; i += 2) { 324 for (i = 0; i + 1 < urb->actual_length; i += 2) {
324 int stat = data[i], flag = 0; 325 int stat = data[i];
325 if (stat & RXERROR_OVERRUN) 326 int flag = TTY_NORMAL;
326 flag |= TTY_OVERRUN; 327
327 if (stat & RXERROR_FRAMING) 328 if (stat & RXERROR_OVERRUN) {
328 flag |= TTY_FRAME; 329 tty_insert_flip_char(&port->port, 0,
329 if (stat & RXERROR_PARITY) 330 TTY_OVERRUN);
330 flag |= TTY_PARITY; 331 }
331 /* XXX should handle break (0x10) */ 332 /* XXX should handle break (0x10) */
333 if (stat & RXERROR_PARITY)
334 flag = TTY_PARITY;
335 else if (stat & RXERROR_FRAMING)
336 flag = TTY_FRAME;
337
332 tty_insert_flip_char(&port->port, data[i+1], 338 tty_insert_flip_char(&port->port, data[i+1],
333 flag); 339 flag);
334 } 340 }
@@ -649,14 +655,19 @@ static void usa49_indat_callback(struct urb *urb)
649 } else { 655 } else {
650 /* some bytes had errors, every byte has status */ 656 /* some bytes had errors, every byte has status */
651 for (i = 0; i + 1 < urb->actual_length; i += 2) { 657 for (i = 0; i + 1 < urb->actual_length; i += 2) {
652 int stat = data[i], flag = 0; 658 int stat = data[i];
653 if (stat & RXERROR_OVERRUN) 659 int flag = TTY_NORMAL;
654 flag |= TTY_OVERRUN; 660
655 if (stat & RXERROR_FRAMING) 661 if (stat & RXERROR_OVERRUN) {
656 flag |= TTY_FRAME; 662 tty_insert_flip_char(&port->port, 0,
657 if (stat & RXERROR_PARITY) 663 TTY_OVERRUN);
658 flag |= TTY_PARITY; 664 }
659 /* XXX should handle break (0x10) */ 665 /* XXX should handle break (0x10) */
666 if (stat & RXERROR_PARITY)
667 flag = TTY_PARITY;
668 else if (stat & RXERROR_FRAMING)
669 flag = TTY_FRAME;
670
660 tty_insert_flip_char(&port->port, data[i+1], 671 tty_insert_flip_char(&port->port, data[i+1],
661 flag); 672 flag);
662 } 673 }
@@ -713,15 +724,19 @@ static void usa49wg_indat_callback(struct urb *urb)
713 */ 724 */
714 for (x = 0; x + 1 < len && 725 for (x = 0; x + 1 < len &&
715 i + 1 < urb->actual_length; x += 2) { 726 i + 1 < urb->actual_length; x += 2) {
716 int stat = data[i], flag = 0; 727 int stat = data[i];
728 int flag = TTY_NORMAL;
717 729
718 if (stat & RXERROR_OVERRUN) 730 if (stat & RXERROR_OVERRUN) {
719 flag |= TTY_OVERRUN; 731 tty_insert_flip_char(&port->port, 0,
720 if (stat & RXERROR_FRAMING) 732 TTY_OVERRUN);
721 flag |= TTY_FRAME; 733 }
722 if (stat & RXERROR_PARITY)
723 flag |= TTY_PARITY;
724 /* XXX should handle break (0x10) */ 734 /* XXX should handle break (0x10) */
735 if (stat & RXERROR_PARITY)
736 flag = TTY_PARITY;
737 else if (stat & RXERROR_FRAMING)
738 flag = TTY_FRAME;
739
725 tty_insert_flip_char(&port->port, data[i+1], 740 tty_insert_flip_char(&port->port, data[i+1],
726 flag); 741 flag);
727 i += 2; 742 i += 2;
@@ -773,25 +788,31 @@ static void usa90_indat_callback(struct urb *urb)
773 if ((data[0] & 0x80) == 0) { 788 if ((data[0] & 0x80) == 0) {
774 /* no errors on individual bytes, only 789 /* no errors on individual bytes, only
775 possible overrun err*/ 790 possible overrun err*/
776 if (data[0] & RXERROR_OVERRUN) 791 if (data[0] & RXERROR_OVERRUN) {
777 err = TTY_OVERRUN; 792 tty_insert_flip_char(&port->port, 0,
778 else 793 TTY_OVERRUN);
779 err = 0; 794 }
780 for (i = 1; i < urb->actual_length ; ++i) 795 for (i = 1; i < urb->actual_length ; ++i)
781 tty_insert_flip_char(&port->port, 796 tty_insert_flip_char(&port->port,
782 data[i], err); 797 data[i], TTY_NORMAL);
783 } else { 798 } else {
784 /* some bytes had errors, every byte has status */ 799 /* some bytes had errors, every byte has status */
785 dev_dbg(&port->dev, "%s - RX error!!!!\n", __func__); 800 dev_dbg(&port->dev, "%s - RX error!!!!\n", __func__);
786 for (i = 0; i + 1 < urb->actual_length; i += 2) { 801 for (i = 0; i + 1 < urb->actual_length; i += 2) {
787 int stat = data[i], flag = 0; 802 int stat = data[i];
788 if (stat & RXERROR_OVERRUN) 803 int flag = TTY_NORMAL;
789 flag |= TTY_OVERRUN; 804
790 if (stat & RXERROR_FRAMING) 805 if (stat & RXERROR_OVERRUN) {
791 flag |= TTY_FRAME; 806 tty_insert_flip_char(
792 if (stat & RXERROR_PARITY) 807 &port->port, 0,
793 flag |= TTY_PARITY; 808 TTY_OVERRUN);
809 }
794 /* XXX should handle break (0x10) */ 810 /* XXX should handle break (0x10) */
811 if (stat & RXERROR_PARITY)
812 flag = TTY_PARITY;
813 else if (stat & RXERROR_FRAMING)
814 flag = TTY_FRAME;
815
795 tty_insert_flip_char(&port->port, 816 tty_insert_flip_char(&port->port,
796 data[i+1], flag); 817 data[i+1], flag);
797 } 818 }
diff --git a/drivers/usb/serial/ssu100.c b/drivers/usb/serial/ssu100.c
index a7fe664b6b7d..70a098de429f 100644
--- a/drivers/usb/serial/ssu100.c
+++ b/drivers/usb/serial/ssu100.c
@@ -490,10 +490,9 @@ static void ssu100_update_lsr(struct usb_serial_port *port, u8 lsr,
490 if (*tty_flag == TTY_NORMAL) 490 if (*tty_flag == TTY_NORMAL)
491 *tty_flag = TTY_FRAME; 491 *tty_flag = TTY_FRAME;
492 } 492 }
493 if (lsr & UART_LSR_OE){ 493 if (lsr & UART_LSR_OE) {
494 port->icount.overrun++; 494 port->icount.overrun++;
495 if (*tty_flag == TTY_NORMAL) 495 tty_insert_flip_char(&port->port, 0, TTY_OVERRUN);
496 *tty_flag = TTY_OVERRUN;
497 } 496 }
498 } 497 }
499 498
@@ -511,12 +510,8 @@ static void ssu100_process_read_urb(struct urb *urb)
511 if ((len >= 4) && 510 if ((len >= 4) &&
512 (packet[0] == 0x1b) && (packet[1] == 0x1b) && 511 (packet[0] == 0x1b) && (packet[1] == 0x1b) &&
513 ((packet[2] == 0x00) || (packet[2] == 0x01))) { 512 ((packet[2] == 0x00) || (packet[2] == 0x01))) {
514 if (packet[2] == 0x00) { 513 if (packet[2] == 0x00)
515 ssu100_update_lsr(port, packet[3], &flag); 514 ssu100_update_lsr(port, packet[3], &flag);
516 if (flag == TTY_OVERRUN)
517 tty_insert_flip_char(&port->port, 0,
518 TTY_OVERRUN);
519 }
520 if (packet[2] == 0x01) 515 if (packet[2] == 0x01)
521 ssu100_update_msr(port, packet[3]); 516 ssu100_update_msr(port, packet[3]);
522 517
diff --git a/drivers/usb/storage/unusual_uas.h b/drivers/usb/storage/unusual_uas.h
index 2fefaf923e4a..18a283d6de1c 100644
--- a/drivers/usb/storage/unusual_uas.h
+++ b/drivers/usb/storage/unusual_uas.h
@@ -103,3 +103,10 @@ UNUSUAL_DEV(0x2109, 0x0711, 0x0000, 0x9999,
103 "VL711", 103 "VL711",
104 USB_SC_DEVICE, USB_PR_DEVICE, NULL, 104 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
105 US_FL_NO_ATA_1X), 105 US_FL_NO_ATA_1X),
106
107/* Reported-by: Hans de Goede <hdegoede@redhat.com> */
108UNUSUAL_DEV(0x4971, 0x1012, 0x0000, 0x9999,
109 "Hitachi",
110 "External HDD",
111 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
112 US_FL_IGNORE_UAS),
diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index 69906cacd04f..a17f11850669 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -1312,6 +1312,7 @@ static int
1312vhost_scsi_set_endpoint(struct vhost_scsi *vs, 1312vhost_scsi_set_endpoint(struct vhost_scsi *vs,
1313 struct vhost_scsi_target *t) 1313 struct vhost_scsi_target *t)
1314{ 1314{
1315 struct se_portal_group *se_tpg;
1315 struct tcm_vhost_tport *tv_tport; 1316 struct tcm_vhost_tport *tv_tport;
1316 struct tcm_vhost_tpg *tpg; 1317 struct tcm_vhost_tpg *tpg;
1317 struct tcm_vhost_tpg **vs_tpg; 1318 struct tcm_vhost_tpg **vs_tpg;
@@ -1359,6 +1360,21 @@ vhost_scsi_set_endpoint(struct vhost_scsi *vs,
1359 ret = -EEXIST; 1360 ret = -EEXIST;
1360 goto out; 1361 goto out;
1361 } 1362 }
1363 /*
1364 * In order to ensure individual vhost-scsi configfs
1365 * groups cannot be removed while in use by vhost ioctl,
1366 * go ahead and take an explicit se_tpg->tpg_group.cg_item
1367 * dependency now.
1368 */
1369 se_tpg = &tpg->se_tpg;
1370 ret = configfs_depend_item(se_tpg->se_tpg_tfo->tf_subsys,
1371 &se_tpg->tpg_group.cg_item);
1372 if (ret) {
1373 pr_warn("configfs_depend_item() failed: %d\n", ret);
1374 kfree(vs_tpg);
1375 mutex_unlock(&tpg->tv_tpg_mutex);
1376 goto out;
1377 }
1362 tpg->tv_tpg_vhost_count++; 1378 tpg->tv_tpg_vhost_count++;
1363 tpg->vhost_scsi = vs; 1379 tpg->vhost_scsi = vs;
1364 vs_tpg[tpg->tport_tpgt] = tpg; 1380 vs_tpg[tpg->tport_tpgt] = tpg;
@@ -1401,6 +1417,7 @@ static int
1401vhost_scsi_clear_endpoint(struct vhost_scsi *vs, 1417vhost_scsi_clear_endpoint(struct vhost_scsi *vs,
1402 struct vhost_scsi_target *t) 1418 struct vhost_scsi_target *t)
1403{ 1419{
1420 struct se_portal_group *se_tpg;
1404 struct tcm_vhost_tport *tv_tport; 1421 struct tcm_vhost_tport *tv_tport;
1405 struct tcm_vhost_tpg *tpg; 1422 struct tcm_vhost_tpg *tpg;
1406 struct vhost_virtqueue *vq; 1423 struct vhost_virtqueue *vq;
@@ -1449,6 +1466,13 @@ vhost_scsi_clear_endpoint(struct vhost_scsi *vs,
1449 vs->vs_tpg[target] = NULL; 1466 vs->vs_tpg[target] = NULL;
1450 match = true; 1467 match = true;
1451 mutex_unlock(&tpg->tv_tpg_mutex); 1468 mutex_unlock(&tpg->tv_tpg_mutex);
1469 /*
1470 * Release se_tpg->tpg_group.cg_item configfs dependency now
1471 * to allow vhost-scsi WWPN se_tpg->tpg_group shutdown to occur.
1472 */
1473 se_tpg = &tpg->se_tpg;
1474 configfs_undepend_item(se_tpg->se_tpg_tfo->tf_subsys,
1475 &se_tpg->tpg_group.cg_item);
1452 } 1476 }
1453 if (match) { 1477 if (match) {
1454 for (i = 0; i < VHOST_SCSI_MAX_VQ; i++) { 1478 for (i = 0; i < VHOST_SCSI_MAX_VQ; i++) {
diff --git a/drivers/watchdog/s3c2410_wdt.c b/drivers/watchdog/s3c2410_wdt.c
index 8532c3e2aea7..1626dc66e763 100644
--- a/drivers/watchdog/s3c2410_wdt.c
+++ b/drivers/watchdog/s3c2410_wdt.c
@@ -161,7 +161,7 @@ static const struct s3c2410_wdt_variant drv_data_exynos5420 = {
161static const struct s3c2410_wdt_variant drv_data_exynos7 = { 161static const struct s3c2410_wdt_variant drv_data_exynos7 = {
162 .disable_reg = EXYNOS5_WDT_DISABLE_REG_OFFSET, 162 .disable_reg = EXYNOS5_WDT_DISABLE_REG_OFFSET,
163 .mask_reset_reg = EXYNOS5_WDT_MASK_RESET_REG_OFFSET, 163 .mask_reset_reg = EXYNOS5_WDT_MASK_RESET_REG_OFFSET,
164 .mask_bit = 0, 164 .mask_bit = 23,
165 .rst_stat_reg = EXYNOS5_RST_STAT_REG_OFFSET, 165 .rst_stat_reg = EXYNOS5_RST_STAT_REG_OFFSET,
166 .rst_stat_bit = 23, /* A57 WDTRESET */ 166 .rst_stat_bit = 23, /* A57 WDTRESET */
167 .quirks = QUIRK_HAS_PMU_CONFIG | QUIRK_HAS_RST_STAT, 167 .quirks = QUIRK_HAS_PMU_CONFIG | QUIRK_HAS_RST_STAT,