aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-04-29 14:18:34 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-04-29 14:18:34 -0400
commit4f567cbc957a7cffd1a428a000d93bd903f42349 (patch)
treee648bfed3732a23031a32811b20975827dad62d2
parent92ddcf4a011a95dac98d3bbb0211a2fa42f13dc1 (diff)
parent0e27263926699fcbbd574cff4dd6920007a50e8a (diff)
Merge tag 'char-misc-3.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc
Pull char/misc driver update from Greg Kroah-Hartman: "Here's the big char / misc driver update for 3.10-rc1 A number of various driver updates, the majority being new functionality in the MEI driver subsystem (it's now a subsystem, it started out just a single driver), extcon updates, memory updates, hyper-v updates, and a bunch of other small stuff that doesn't fit in any other tree. All of these have been in linux-next for a while" * tag 'char-misc-3.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc: (148 commits) Tools: hv: Fix a checkpatch warning tools: hv: skip iso9660 mounts in hv_vss_daemon tools: hv: use FIFREEZE/FITHAW in hv_vss_daemon tools: hv: use getmntent in hv_vss_daemon Tools: hv: Fix a checkpatch warning tools: hv: fix checks for origin of netlink message in hv_vss_daemon Tools: hv: fix warnings in hv_vss_daemon misc: mark spear13xx-pcie-gadget as broken mei: fix krealloc() misuse in in mei_cl_irq_read_msg() mei: reduce flow control only for completed messages mei: reseting -> resetting mei: fix reading large reposnes mei: revamp mei_irq_read_client_message function mei: revamp mei_amthif_irq_read_message mei: revamp hbm state machine Revert "drivers/scsi: use module_pcmcia_driver() in pcmcia drivers" Revert "scsi: pcmcia: nsp_cs: remove module init/exit function prototypes" scsi: pcmcia: nsp_cs: remove module init/exit function prototypes mei: wd: fix line over 80 characters misc: tsl2550: Use dev_pm_ops ...
-rw-r--r--Documentation/ABI/testing/sysfs-bus-mei7
-rw-r--r--Documentation/devicetree/bindings/arm/msm/ssbi.txt18
-rw-r--r--Documentation/misc-devices/mei/mei-client-bus.txt138
-rw-r--r--MAINTAINERS1
-rw-r--r--arch/arm/boot/dts/msm8660-surf.dts6
-rw-r--r--arch/arm/boot/dts/msm8960-cdp.dts6
-rw-r--r--drivers/Kconfig2
-rw-r--r--drivers/Makefile1
-rw-r--r--drivers/ata/pata_pcmcia.c14
-rw-r--r--drivers/bluetooth/bluecard_cs.c15
-rw-r--r--drivers/bluetooth/bt3c_cs.c15
-rw-r--r--drivers/bluetooth/btuart_cs.c15
-rw-r--r--drivers/bluetooth/dtl1_cs.c15
-rw-r--r--drivers/char/applicom.c4
-rw-r--r--drivers/char/hw_random/mxc-rnga.c13
-rw-r--r--drivers/char/hw_random/tx4939-rng.c13
-rw-r--r--drivers/char/tile-srom.c2
-rw-r--r--drivers/extcon/extcon-arizona.c498
-rw-r--r--drivers/extcon/extcon-max77693.c10
-rw-r--r--drivers/extcon/extcon-max8997.c12
-rw-r--r--drivers/hv/Makefile2
-rw-r--r--drivers/hv/channel_mgmt.c11
-rw-r--r--drivers/hv/hv.c5
-rw-r--r--drivers/hv/hv_balloon.c544
-rw-r--r--drivers/hv/hv_snapshot.c287
-rw-r--r--drivers/hv/hv_util.c10
-rw-r--r--drivers/hv/ring_buffer.c1
-rw-r--r--drivers/ipack/carriers/tpci200.c14
-rw-r--r--drivers/ipack/ipack.c36
-rw-r--r--drivers/isdn/hardware/avm/avm_cs.c14
-rw-r--r--drivers/isdn/hisax/avma1_cs.c14
-rw-r--r--drivers/isdn/hisax/elsa_cs.c14
-rw-r--r--drivers/isdn/hisax/sedlbauer_cs.c14
-rw-r--r--drivers/isdn/hisax/teles_cs.c14
-rw-r--r--drivers/memory/emif.c141
-rw-r--r--drivers/memory/tegra30-mc.c2
-rw-r--r--drivers/mfd/Kconfig2
-rw-r--r--drivers/mfd/pm8921-core.c14
-rw-r--r--drivers/mfd/wm5102-tables.c8
-rw-r--r--drivers/misc/Kconfig10
-rw-r--r--drivers/misc/Makefile2
-rw-r--r--drivers/misc/apds9802als.c25
-rw-r--r--drivers/misc/apds990x.c9
-rw-r--r--drivers/misc/arm-charlcd.c13
-rw-r--r--drivers/misc/atmel_pwm.c12
-rw-r--r--drivers/misc/bh1770glc.c7
-rw-r--r--drivers/misc/bh1780gli.c10
-rw-r--r--drivers/misc/cs5535-mfgpt.c41
-rw-r--r--drivers/misc/dummy-irq.c59
-rw-r--r--drivers/misc/eeprom/at25.c4
-rw-r--r--drivers/misc/eeprom/eeprom_93xx46.c6
-rw-r--r--drivers/misc/ep93xx_pwm.c13
-rw-r--r--drivers/misc/fsa9480.c19
-rw-r--r--drivers/misc/isl29003.c19
-rw-r--r--drivers/misc/lattice-ecp3-config.c2
-rw-r--r--drivers/misc/mei/Kconfig5
-rw-r--r--drivers/misc/mei/Makefile9
-rw-r--r--drivers/misc/mei/amthif.c21
-rw-r--r--drivers/misc/mei/bus.c528
-rw-r--r--drivers/misc/mei/client.c116
-rw-r--r--drivers/misc/mei/client.h7
-rw-r--r--drivers/misc/mei/debugfs.c143
-rw-r--r--drivers/misc/mei/hbm.c82
-rw-r--r--drivers/misc/mei/hbm.h25
-rw-r--r--drivers/misc/mei/hw-me.c124
-rw-r--r--drivers/misc/mei/hw-me.h6
-rw-r--r--drivers/misc/mei/init.c70
-rw-r--r--drivers/misc/mei/interrupt.c242
-rw-r--r--drivers/misc/mei/main.c127
-rw-r--r--drivers/misc/mei/mei_dev.h166
-rw-r--r--drivers/misc/mei/nfc.c554
-rw-r--r--drivers/misc/mei/pci-me.c46
-rw-r--r--drivers/misc/mei/wd.c3
-rw-r--r--drivers/misc/tsl2550.c21
-rw-r--r--drivers/mmc/host/sdricoh_cs.c20
-rw-r--r--drivers/net/arcnet/com20020_cs.c14
-rw-r--r--drivers/net/can/sja1000/ems_pcmcia.c13
-rw-r--r--drivers/net/can/sja1000/peak_pcmcia.c13
-rw-r--r--drivers/net/can/softing/softing_cs.c16
-rw-r--r--drivers/net/ethernet/3com/3c574_cs.c14
-rw-r--r--drivers/net/ethernet/3com/3c589_cs.c14
-rw-r--r--drivers/net/ethernet/8390/axnet_cs.c14
-rw-r--r--drivers/net/ethernet/8390/pcnet_cs.c14
-rw-r--r--drivers/net/ethernet/amd/nmclan_cs.c14
-rw-r--r--drivers/net/ethernet/fujitsu/fmvj18x_cs.c14
-rw-r--r--drivers/net/ethernet/smsc/smc91c92_cs.c14
-rw-r--r--drivers/net/ethernet/xircom/xirc2ps_cs.c16
-rw-r--r--drivers/net/wireless/airo_cs.c14
-rw-r--r--drivers/net/wireless/atmel_cs.c14
-rw-r--r--drivers/net/wireless/b43/pcmcia.c4
-rw-r--r--drivers/net/wireless/hostap/hostap_cs.c15
-rw-r--r--drivers/net/wireless/libertas/if_cs.c25
-rw-r--r--drivers/net/wireless/orinoco/orinoco_cs.c16
-rw-r--r--drivers/net/wireless/orinoco/spectrum_cs.c16
-rw-r--r--drivers/net/wireless/wl3501_cs.c14
-rw-r--r--drivers/parport/parport_amiga.c15
-rw-r--r--drivers/parport/parport_cs.c14
-rw-r--r--drivers/parport/parport_gsc.c4
-rw-r--r--drivers/parport/parport_sunbpp.c5
-rw-r--r--drivers/parport/procfs.c6
-rw-r--r--drivers/ssbi/Kconfig16
-rw-r--r--drivers/ssbi/Makefile1
-rw-r--r--drivers/ssbi/ssbi.c379
-rw-r--r--drivers/tty/serial/8250/serial_cs.c14
-rw-r--r--drivers/uio/uio.c1
-rw-r--r--drivers/usb/host/sl811_cs.c15
-rw-r--r--drivers/w1/masters/mxc_w1.c6
-rw-r--r--drivers/w1/slaves/Kconfig10
-rw-r--r--drivers/w1/slaves/w1_ds2408.c25
-rw-r--r--include/linux/hyperv.h69
-rw-r--r--include/linux/ipack.h42
-rw-r--r--include/linux/mei_cl_bus.h44
-rw-r--r--include/linux/mfd/arizona/core.h3
-rw-r--r--include/linux/mfd/arizona/pdata.h21
-rw-r--r--include/linux/mfd/arizona/registers.h4
-rw-r--r--include/linux/mod_devicetable.h9
-rw-r--r--include/linux/platform_data/emif_plat.h1
-rw-r--r--include/linux/ssbi.h38
-rw-r--r--include/pcmcia/ds.h12
-rw-r--r--include/uapi/linux/connector.h5
-rw-r--r--mm/page_alloc.c1
-rw-r--r--scripts/mod/devicetable-offsets.c3
-rw-r--r--scripts/mod/file2alias.c12
-rw-r--r--sound/pcmcia/pdaudiocf/pdaudiocf.c15
-rw-r--r--sound/pcmcia/vx/vxpocket.c14
-rw-r--r--sound/soc/codecs/arizona.c33
-rw-r--r--sound/soc/codecs/arizona.h3
-rw-r--r--sound/soc/codecs/wm5102.c8
-rw-r--r--sound/soc/codecs/wm5110.c8
-rw-r--r--tools/hv/hv_kvp_daemon.c16
-rw-r--r--tools/hv/hv_vss_daemon.c249
131 files changed, 4596 insertions, 1331 deletions
diff --git a/Documentation/ABI/testing/sysfs-bus-mei b/Documentation/ABI/testing/sysfs-bus-mei
new file mode 100644
index 000000000000..2066f0bbd453
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-mei
@@ -0,0 +1,7 @@
1What: /sys/bus/mei/devices/.../modalias
2Date: March 2013
3KernelVersion: 3.10
4Contact: Samuel Ortiz <sameo@linux.intel.com>
5 linux-mei@linux.intel.com
6Description: Stores the same MODALIAS value emitted by uevent
7 Format: mei:<mei device name>
diff --git a/Documentation/devicetree/bindings/arm/msm/ssbi.txt b/Documentation/devicetree/bindings/arm/msm/ssbi.txt
new file mode 100644
index 000000000000..54fd5ced3401
--- /dev/null
+++ b/Documentation/devicetree/bindings/arm/msm/ssbi.txt
@@ -0,0 +1,18 @@
1* Qualcomm SSBI
2
3Some Qualcomm MSM devices contain a point-to-point serial bus used to
4communicate with a limited range of devices (mostly power management
5chips).
6
7These require the following properties:
8
9- compatible: "qcom,ssbi"
10
11- qcom,controller-type
12 indicates the SSBI bus variant the controller should use to talk
13 with the slave device. This should be one of "ssbi", "ssbi2", or
14 "pmic-arbiter". The type chosen is determined by the attached
15 slave.
16
17The slave device should be the single child node of the ssbi device
18with a compatible field.
diff --git a/Documentation/misc-devices/mei/mei-client-bus.txt b/Documentation/misc-devices/mei/mei-client-bus.txt
new file mode 100644
index 000000000000..f83910a8ce76
--- /dev/null
+++ b/Documentation/misc-devices/mei/mei-client-bus.txt
@@ -0,0 +1,138 @@
1Intel(R) Management Engine (ME) Client bus API
2===============================================
3
4
5Rationale
6=========
7MEI misc character device is useful for dedicated applications to send and receive
8data to the many FW appliance found in Intel's ME from the user space.
9However for some of the ME functionalities it make sense to leverage existing software
10stack and expose them through existing kernel subsystems.
11
12In order to plug seamlessly into the kernel device driver model we add kernel virtual
13bus abstraction on top of the MEI driver. This allows implementing linux kernel drivers
14for the various MEI features as a stand alone entities found in their respective subsystem.
15Existing device drivers can even potentially be re-used by adding an MEI CL bus layer to
16the existing code.
17
18
19MEI CL bus API
20===========
21A driver implementation for an MEI Client is very similar to existing bus
22based device drivers. The driver registers itself as an MEI CL bus driver through
23the mei_cl_driver structure:
24
25struct mei_cl_driver {
26 struct device_driver driver;
27 const char *name;
28
29 const struct mei_cl_device_id *id_table;
30
31 int (*probe)(struct mei_cl_device *dev, const struct mei_cl_id *id);
32 int (*remove)(struct mei_cl_device *dev);
33};
34
35struct mei_cl_id {
36 char name[MEI_NAME_SIZE];
37 kernel_ulong_t driver_info;
38};
39
40The mei_cl_id structure allows the driver to bind itself against a device name.
41
42To actually register a driver on the ME Client bus one must call the mei_cl_add_driver()
43API. This is typically called at module init time.
44
45Once registered on the ME Client bus, a driver will typically try to do some I/O on
46this bus and this should be done through the mei_cl_send() and mei_cl_recv()
47routines. The latter is synchronous (blocks and sleeps until data shows up).
48In order for drivers to be notified of pending events waiting for them (e.g.
49an Rx event) they can register an event handler through the
50mei_cl_register_event_cb() routine. Currently only the MEI_EVENT_RX event
51will trigger an event handler call and the driver implementation is supposed
52to call mei_recv() from the event handler in order to fetch the pending
53received buffers.
54
55
56Example
57=======
58As a theoretical example let's pretend the ME comes with a "contact" NFC IP.
59The driver init and exit routines for this device would look like:
60
61#define CONTACT_DRIVER_NAME "contact"
62
63static struct mei_cl_device_id contact_mei_cl_tbl[] = {
64 { CONTACT_DRIVER_NAME, },
65
66 /* required last entry */
67 { }
68};
69MODULE_DEVICE_TABLE(mei_cl, contact_mei_cl_tbl);
70
71static struct mei_cl_driver contact_driver = {
72 .id_table = contact_mei_tbl,
73 .name = CONTACT_DRIVER_NAME,
74
75 .probe = contact_probe,
76 .remove = contact_remove,
77};
78
79static int contact_init(void)
80{
81 int r;
82
83 r = mei_cl_driver_register(&contact_driver);
84 if (r) {
85 pr_err(CONTACT_DRIVER_NAME ": driver registration failed\n");
86 return r;
87 }
88
89 return 0;
90}
91
92static void __exit contact_exit(void)
93{
94 mei_cl_driver_unregister(&contact_driver);
95}
96
97module_init(contact_init);
98module_exit(contact_exit);
99
100And the driver's simplified probe routine would look like that:
101
102int contact_probe(struct mei_cl_device *dev, struct mei_cl_device_id *id)
103{
104 struct contact_driver *contact;
105
106 [...]
107 mei_cl_enable_device(dev);
108
109 mei_cl_register_event_cb(dev, contact_event_cb, contact);
110
111 return 0;
112 }
113
114In the probe routine the driver first enable the MEI device and then registers
115an ME bus event handler which is as close as it can get to registering a
116threaded IRQ handler.
117The handler implementation will typically call some I/O routine depending on
118the pending events:
119
120#define MAX_NFC_PAYLOAD 128
121
122static void contact_event_cb(struct mei_cl_device *dev, u32 events,
123 void *context)
124{
125 struct contact_driver *contact = context;
126
127 if (events & BIT(MEI_EVENT_RX)) {
128 u8 payload[MAX_NFC_PAYLOAD];
129 int payload_size;
130
131 payload_size = mei_recv(dev, payload, MAX_NFC_PAYLOAD);
132 if (payload_size <= 0)
133 return;
134
135 /* Hook to the NFC subsystem */
136 nfc_hci_recv_frame(contact->hdev, payload, payload_size);
137 }
138}
diff --git a/MAINTAINERS b/MAINTAINERS
index fb2fc3026968..8ba3b484d826 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1031,6 +1031,7 @@ F: drivers/mmc/host/msm_sdcc.h
1031F: drivers/tty/serial/msm_serial.h 1031F: drivers/tty/serial/msm_serial.h
1032F: drivers/tty/serial/msm_serial.c 1032F: drivers/tty/serial/msm_serial.c
1033F: drivers/*/pm8???-* 1033F: drivers/*/pm8???-*
1034F: drivers/ssbi/
1034F: include/linux/mfd/pm8xxx/ 1035F: include/linux/mfd/pm8xxx/
1035T: git git://git.kernel.org/pub/scm/linux/kernel/git/davidb/linux-msm.git 1036T: git git://git.kernel.org/pub/scm/linux/kernel/git/davidb/linux-msm.git
1036S: Maintained 1037S: Maintained
diff --git a/arch/arm/boot/dts/msm8660-surf.dts b/arch/arm/boot/dts/msm8660-surf.dts
index 31f2157cd7d7..67f8670c4d6a 100644
--- a/arch/arm/boot/dts/msm8660-surf.dts
+++ b/arch/arm/boot/dts/msm8660-surf.dts
@@ -38,4 +38,10 @@
38 <0x19c00000 0x1000>; 38 <0x19c00000 0x1000>;
39 interrupts = <0 195 0x0>; 39 interrupts = <0 195 0x0>;
40 }; 40 };
41
42 qcom,ssbi@500000 {
43 compatible = "qcom,ssbi";
44 reg = <0x500000 0x1000>;
45 qcom,controller-type = "pmic-arbiter";
46 };
41}; 47};
diff --git a/arch/arm/boot/dts/msm8960-cdp.dts b/arch/arm/boot/dts/msm8960-cdp.dts
index 9e621b5ad3dd..c9b09a813a4b 100644
--- a/arch/arm/boot/dts/msm8960-cdp.dts
+++ b/arch/arm/boot/dts/msm8960-cdp.dts
@@ -38,4 +38,10 @@
38 <0x16400000 0x1000>; 38 <0x16400000 0x1000>;
39 interrupts = <0 154 0x0>; 39 interrupts = <0 154 0x0>;
40 }; 40 };
41
42 qcom,ssbi@500000 {
43 compatible = "qcom,ssbi";
44 reg = <0x500000 0x1000>;
45 qcom,controller-type = "pmic-arbiter";
46 };
41}; 47};
diff --git a/drivers/Kconfig b/drivers/Kconfig
index 202fa6d051b9..78a956e286e6 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -52,6 +52,8 @@ source "drivers/i2c/Kconfig"
52 52
53source "drivers/spi/Kconfig" 53source "drivers/spi/Kconfig"
54 54
55source "drivers/ssbi/Kconfig"
56
55source "drivers/hsi/Kconfig" 57source "drivers/hsi/Kconfig"
56 58
57source "drivers/pps/Kconfig" 59source "drivers/pps/Kconfig"
diff --git a/drivers/Makefile b/drivers/Makefile
index dce39a95fa71..4865ed24708a 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -114,6 +114,7 @@ obj-y += firmware/
114obj-$(CONFIG_CRYPTO) += crypto/ 114obj-$(CONFIG_CRYPTO) += crypto/
115obj-$(CONFIG_SUPERH) += sh/ 115obj-$(CONFIG_SUPERH) += sh/
116obj-$(CONFIG_ARCH_SHMOBILE) += sh/ 116obj-$(CONFIG_ARCH_SHMOBILE) += sh/
117obj-$(CONFIG_SSBI) += ssbi/
117ifndef CONFIG_ARCH_USES_GETTIMEOFFSET 118ifndef CONFIG_ARCH_USES_GETTIMEOFFSET
118obj-y += clocksource/ 119obj-y += clocksource/
119endif 120endif
diff --git a/drivers/ata/pata_pcmcia.c b/drivers/ata/pata_pcmcia.c
index 958238dda8fc..40254f4df584 100644
--- a/drivers/ata/pata_pcmcia.c
+++ b/drivers/ata/pata_pcmcia.c
@@ -387,21 +387,9 @@ static struct pcmcia_driver pcmcia_driver = {
387 .probe = pcmcia_init_one, 387 .probe = pcmcia_init_one,
388 .remove = pcmcia_remove_one, 388 .remove = pcmcia_remove_one,
389}; 389};
390 390module_pcmcia_driver(pcmcia_driver);
391static int __init pcmcia_init(void)
392{
393 return pcmcia_register_driver(&pcmcia_driver);
394}
395
396static void __exit pcmcia_exit(void)
397{
398 pcmcia_unregister_driver(&pcmcia_driver);
399}
400 391
401MODULE_AUTHOR("Alan Cox"); 392MODULE_AUTHOR("Alan Cox");
402MODULE_DESCRIPTION("low-level driver for PCMCIA ATA"); 393MODULE_DESCRIPTION("low-level driver for PCMCIA ATA");
403MODULE_LICENSE("GPL"); 394MODULE_LICENSE("GPL");
404MODULE_VERSION(DRV_VERSION); 395MODULE_VERSION(DRV_VERSION);
405
406module_init(pcmcia_init);
407module_exit(pcmcia_exit);
diff --git a/drivers/bluetooth/bluecard_cs.c b/drivers/bluetooth/bluecard_cs.c
index 0d26851d6e49..6c3e3d43c718 100644
--- a/drivers/bluetooth/bluecard_cs.c
+++ b/drivers/bluetooth/bluecard_cs.c
@@ -934,17 +934,4 @@ static struct pcmcia_driver bluecard_driver = {
934 .remove = bluecard_detach, 934 .remove = bluecard_detach,
935 .id_table = bluecard_ids, 935 .id_table = bluecard_ids,
936}; 936};
937 937module_pcmcia_driver(bluecard_driver);
938static int __init init_bluecard_cs(void)
939{
940 return pcmcia_register_driver(&bluecard_driver);
941}
942
943
944static void __exit exit_bluecard_cs(void)
945{
946 pcmcia_unregister_driver(&bluecard_driver);
947}
948
949module_init(init_bluecard_cs);
950module_exit(exit_bluecard_cs);
diff --git a/drivers/bluetooth/bt3c_cs.c b/drivers/bluetooth/bt3c_cs.c
index 7ffd3f407144..a1aaa3ba2a4b 100644
--- a/drivers/bluetooth/bt3c_cs.c
+++ b/drivers/bluetooth/bt3c_cs.c
@@ -760,17 +760,4 @@ static struct pcmcia_driver bt3c_driver = {
760 .remove = bt3c_detach, 760 .remove = bt3c_detach,
761 .id_table = bt3c_ids, 761 .id_table = bt3c_ids,
762}; 762};
763 763module_pcmcia_driver(bt3c_driver);
764static int __init init_bt3c_cs(void)
765{
766 return pcmcia_register_driver(&bt3c_driver);
767}
768
769
770static void __exit exit_bt3c_cs(void)
771{
772 pcmcia_unregister_driver(&bt3c_driver);
773}
774
775module_init(init_bt3c_cs);
776module_exit(exit_bt3c_cs);
diff --git a/drivers/bluetooth/btuart_cs.c b/drivers/bluetooth/btuart_cs.c
index 35a553a90616..beb262f2dc4d 100644
--- a/drivers/bluetooth/btuart_cs.c
+++ b/drivers/bluetooth/btuart_cs.c
@@ -688,17 +688,4 @@ static struct pcmcia_driver btuart_driver = {
688 .remove = btuart_detach, 688 .remove = btuart_detach,
689 .id_table = btuart_ids, 689 .id_table = btuart_ids,
690}; 690};
691 691module_pcmcia_driver(btuart_driver);
692static int __init init_btuart_cs(void)
693{
694 return pcmcia_register_driver(&btuart_driver);
695}
696
697
698static void __exit exit_btuart_cs(void)
699{
700 pcmcia_unregister_driver(&btuart_driver);
701}
702
703module_init(init_btuart_cs);
704module_exit(exit_btuart_cs);
diff --git a/drivers/bluetooth/dtl1_cs.c b/drivers/bluetooth/dtl1_cs.c
index 036cb366fe6e..33f3a6950c0e 100644
--- a/drivers/bluetooth/dtl1_cs.c
+++ b/drivers/bluetooth/dtl1_cs.c
@@ -628,17 +628,4 @@ static struct pcmcia_driver dtl1_driver = {
628 .remove = dtl1_detach, 628 .remove = dtl1_detach,
629 .id_table = dtl1_ids, 629 .id_table = dtl1_ids,
630}; 630};
631 631module_pcmcia_driver(dtl1_driver);
632static int __init init_dtl1_cs(void)
633{
634 return pcmcia_register_driver(&dtl1_driver);
635}
636
637
638static void __exit exit_dtl1_cs(void)
639{
640 pcmcia_unregister_driver(&dtl1_driver);
641}
642
643module_init(init_dtl1_cs);
644module_exit(exit_dtl1_cs);
diff --git a/drivers/char/applicom.c b/drivers/char/applicom.c
index 25373df1dcf8..974321a2508d 100644
--- a/drivers/char/applicom.c
+++ b/drivers/char/applicom.c
@@ -804,8 +804,8 @@ static long ac_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
804 804
805 printk(KERN_INFO "Prom version board %d ....... V%d.%d %s", 805 printk(KERN_INFO "Prom version board %d ....... V%d.%d %s",
806 i+1, 806 i+1,
807 (int)(readb(apbs[IndexCard].RamIO + VERS) >> 4), 807 (int)(readb(apbs[i].RamIO + VERS) >> 4),
808 (int)(readb(apbs[IndexCard].RamIO + VERS) & 0xF), 808 (int)(readb(apbs[i].RamIO + VERS) & 0xF),
809 boardname); 809 boardname);
810 810
811 811
diff --git a/drivers/char/hw_random/mxc-rnga.c b/drivers/char/hw_random/mxc-rnga.c
index f05d85713fd3..895d0b8fb9ab 100644
--- a/drivers/char/hw_random/mxc-rnga.c
+++ b/drivers/char/hw_random/mxc-rnga.c
@@ -228,18 +228,7 @@ static struct platform_driver mxc_rnga_driver = {
228 .remove = __exit_p(mxc_rnga_remove), 228 .remove = __exit_p(mxc_rnga_remove),
229}; 229};
230 230
231static int __init mod_init(void) 231module_platform_driver_probe(mxc_rnga_driver, mxc_rnga_probe);
232{
233 return platform_driver_probe(&mxc_rnga_driver, mxc_rnga_probe);
234}
235
236static void __exit mod_exit(void)
237{
238 platform_driver_unregister(&mxc_rnga_driver);
239}
240
241module_init(mod_init);
242module_exit(mod_exit);
243 232
244MODULE_AUTHOR("Freescale Semiconductor, Inc."); 233MODULE_AUTHOR("Freescale Semiconductor, Inc.");
245MODULE_DESCRIPTION("H/W RNGA driver for i.MX"); 234MODULE_DESCRIPTION("H/W RNGA driver for i.MX");
diff --git a/drivers/char/hw_random/tx4939-rng.c b/drivers/char/hw_random/tx4939-rng.c
index 30991989d65b..d34a24a0d484 100644
--- a/drivers/char/hw_random/tx4939-rng.c
+++ b/drivers/char/hw_random/tx4939-rng.c
@@ -166,18 +166,7 @@ static struct platform_driver tx4939_rng_driver = {
166 .remove = tx4939_rng_remove, 166 .remove = tx4939_rng_remove,
167}; 167};
168 168
169static int __init tx4939rng_init(void) 169module_platform_driver_probe(tx4939_rng_driver, tx4939_rng_probe);
170{
171 return platform_driver_probe(&tx4939_rng_driver, tx4939_rng_probe);
172}
173
174static void __exit tx4939rng_exit(void)
175{
176 platform_driver_unregister(&tx4939_rng_driver);
177}
178
179module_init(tx4939rng_init);
180module_exit(tx4939rng_exit);
181 170
182MODULE_DESCRIPTION("H/W Random Number Generator (RNG) driver for TX4939"); 171MODULE_DESCRIPTION("H/W Random Number Generator (RNG) driver for TX4939");
183MODULE_LICENSE("GPL"); 172MODULE_LICENSE("GPL");
diff --git a/drivers/char/tile-srom.c b/drivers/char/tile-srom.c
index 3b22a606f79d..2e2036e940fc 100644
--- a/drivers/char/tile-srom.c
+++ b/drivers/char/tile-srom.c
@@ -371,7 +371,7 @@ static int srom_setup_minor(struct srom_dev *srom, int index)
371 371
372 dev = device_create(srom_class, &platform_bus, 372 dev = device_create(srom_class, &platform_bus,
373 MKDEV(srom_major, index), srom, "%d", index); 373 MKDEV(srom_major, index), srom, "%d", index);
374 return IS_ERR(dev) ? PTR_ERR(dev) : 0; 374 return PTR_RET(dev);
375} 375}
376 376
377/** srom_init() - Initialize the driver's module. */ 377/** srom_init() - Initialize the driver's module. */
diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c
index dc357a4051f6..7a1b4a7791ba 100644
--- a/drivers/extcon/extcon-arizona.c
+++ b/drivers/extcon/extcon-arizona.c
@@ -33,12 +33,17 @@
33#include <linux/mfd/arizona/pdata.h> 33#include <linux/mfd/arizona/pdata.h>
34#include <linux/mfd/arizona/registers.h> 34#include <linux/mfd/arizona/registers.h>
35 35
36#define ARIZONA_NUM_BUTTONS 6 36#define ARIZONA_MAX_MICD_RANGE 8
37 37
38#define ARIZONA_ACCDET_MODE_MIC 0 38#define ARIZONA_ACCDET_MODE_MIC 0
39#define ARIZONA_ACCDET_MODE_HPL 1 39#define ARIZONA_ACCDET_MODE_HPL 1
40#define ARIZONA_ACCDET_MODE_HPR 2 40#define ARIZONA_ACCDET_MODE_HPR 2
41 41
42#define ARIZONA_HPDET_MAX 10000
43
44#define HPDET_DEBOUNCE 500
45#define DEFAULT_MICD_TIMEOUT 2000
46
42struct arizona_extcon_info { 47struct arizona_extcon_info {
43 struct device *dev; 48 struct device *dev;
44 struct arizona *arizona; 49 struct arizona *arizona;
@@ -46,17 +51,27 @@ struct arizona_extcon_info {
46 struct regulator *micvdd; 51 struct regulator *micvdd;
47 struct input_dev *input; 52 struct input_dev *input;
48 53
54 u16 last_jackdet;
55
49 int micd_mode; 56 int micd_mode;
50 const struct arizona_micd_config *micd_modes; 57 const struct arizona_micd_config *micd_modes;
51 int micd_num_modes; 58 int micd_num_modes;
52 59
60 const struct arizona_micd_range *micd_ranges;
61 int num_micd_ranges;
62
63 int micd_timeout;
64
53 bool micd_reva; 65 bool micd_reva;
54 bool micd_clamp; 66 bool micd_clamp;
55 67
56 struct delayed_work hpdet_work; 68 struct delayed_work hpdet_work;
69 struct delayed_work micd_detect_work;
70 struct delayed_work micd_timeout_work;
57 71
58 bool hpdet_active; 72 bool hpdet_active;
59 bool hpdet_done; 73 bool hpdet_done;
74 bool hpdet_retried;
60 75
61 int num_hpdet_res; 76 int num_hpdet_res;
62 unsigned int hpdet_res[3]; 77 unsigned int hpdet_res[3];
@@ -71,20 +86,25 @@ struct arizona_extcon_info {
71}; 86};
72 87
73static const struct arizona_micd_config micd_default_modes[] = { 88static const struct arizona_micd_config micd_default_modes[] = {
74 { 0, 2 << ARIZONA_MICD_BIAS_SRC_SHIFT, 1 },
75 { ARIZONA_ACCDET_SRC, 1 << ARIZONA_MICD_BIAS_SRC_SHIFT, 0 }, 89 { ARIZONA_ACCDET_SRC, 1 << ARIZONA_MICD_BIAS_SRC_SHIFT, 0 },
90 { 0, 2 << ARIZONA_MICD_BIAS_SRC_SHIFT, 1 },
76}; 91};
77 92
78static struct { 93static const struct arizona_micd_range micd_default_ranges[] = {
79 u16 status; 94 { .max = 11, .key = BTN_0 },
80 int report; 95 { .max = 28, .key = BTN_1 },
81} arizona_lvl_to_key[ARIZONA_NUM_BUTTONS] = { 96 { .max = 54, .key = BTN_2 },
82 { 0x1, BTN_0 }, 97 { .max = 100, .key = BTN_3 },
83 { 0x2, BTN_1 }, 98 { .max = 186, .key = BTN_4 },
84 { 0x4, BTN_2 }, 99 { .max = 430, .key = BTN_5 },
85 { 0x8, BTN_3 }, 100};
86 { 0x10, BTN_4 }, 101
87 { 0x20, BTN_5 }, 102static const int arizona_micd_levels[] = {
103 3, 6, 8, 11, 13, 16, 18, 21, 23, 26, 28, 31, 34, 36, 39, 41, 44, 46,
104 49, 52, 54, 57, 60, 62, 65, 67, 70, 73, 75, 78, 81, 83, 89, 94, 100,
105 105, 111, 116, 122, 127, 139, 150, 161, 173, 186, 196, 209, 220, 245,
106 270, 295, 321, 348, 375, 402, 430, 489, 550, 614, 681, 752, 903, 1071,
107 1257,
88}; 108};
89 109
90#define ARIZONA_CABLE_MECHANICAL 0 110#define ARIZONA_CABLE_MECHANICAL 0
@@ -100,10 +120,63 @@ static const char *arizona_cable[] = {
100 NULL, 120 NULL,
101}; 121};
102 122
123static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info);
124
125static void arizona_extcon_do_magic(struct arizona_extcon_info *info,
126 unsigned int magic)
127{
128 struct arizona *arizona = info->arizona;
129 int ret;
130
131 mutex_lock(&arizona->dapm->card->dapm_mutex);
132
133 arizona->hpdet_magic = magic;
134
135 /* Keep the HP output stages disabled while doing the magic */
136 if (magic) {
137 ret = regmap_update_bits(arizona->regmap,
138 ARIZONA_OUTPUT_ENABLES_1,
139 ARIZONA_OUT1L_ENA |
140 ARIZONA_OUT1R_ENA, 0);
141 if (ret != 0)
142 dev_warn(arizona->dev,
143 "Failed to disable headphone outputs: %d\n",
144 ret);
145 }
146
147 ret = regmap_update_bits(arizona->regmap, 0x225, 0x4000,
148 magic);
149 if (ret != 0)
150 dev_warn(arizona->dev, "Failed to do magic: %d\n",
151 ret);
152
153 ret = regmap_update_bits(arizona->regmap, 0x226, 0x4000,
154 magic);
155 if (ret != 0)
156 dev_warn(arizona->dev, "Failed to do magic: %d\n",
157 ret);
158
159 /* Restore the desired state while not doing the magic */
160 if (!magic) {
161 ret = regmap_update_bits(arizona->regmap,
162 ARIZONA_OUTPUT_ENABLES_1,
163 ARIZONA_OUT1L_ENA |
164 ARIZONA_OUT1R_ENA, arizona->hp_ena);
165 if (ret != 0)
166 dev_warn(arizona->dev,
167 "Failed to restore headphone outputs: %d\n",
168 ret);
169 }
170
171 mutex_unlock(&arizona->dapm->card->dapm_mutex);
172}
173
103static void arizona_extcon_set_mode(struct arizona_extcon_info *info, int mode) 174static void arizona_extcon_set_mode(struct arizona_extcon_info *info, int mode)
104{ 175{
105 struct arizona *arizona = info->arizona; 176 struct arizona *arizona = info->arizona;
106 177
178 mode %= info->micd_num_modes;
179
107 if (arizona->pdata.micd_pol_gpio > 0) 180 if (arizona->pdata.micd_pol_gpio > 0)
108 gpio_set_value_cansleep(arizona->pdata.micd_pol_gpio, 181 gpio_set_value_cansleep(arizona->pdata.micd_pol_gpio,
109 info->micd_modes[mode].gpio); 182 info->micd_modes[mode].gpio);
@@ -330,7 +403,7 @@ static int arizona_hpdet_read(struct arizona_extcon_info *info)
330 /* If we go out of range report top of range */ 403 /* If we go out of range report top of range */
331 if (val < 100 || val > 0x3fb) { 404 if (val < 100 || val > 0x3fb) {
332 dev_dbg(arizona->dev, "Measurement out of range\n"); 405 dev_dbg(arizona->dev, "Measurement out of range\n");
333 return 10000; 406 return ARIZONA_HPDET_MAX;
334 } 407 }
335 408
336 dev_dbg(arizona->dev, "HPDET read %d in range %d\n", 409 dev_dbg(arizona->dev, "HPDET read %d in range %d\n",
@@ -391,7 +464,8 @@ static int arizona_hpdet_read(struct arizona_extcon_info *info)
391 return val; 464 return val;
392} 465}
393 466
394static int arizona_hpdet_do_id(struct arizona_extcon_info *info, int *reading) 467static int arizona_hpdet_do_id(struct arizona_extcon_info *info, int *reading,
468 bool *mic)
395{ 469{
396 struct arizona *arizona = info->arizona; 470 struct arizona *arizona = info->arizona;
397 int id_gpio = arizona->pdata.hpdet_id_gpio; 471 int id_gpio = arizona->pdata.hpdet_id_gpio;
@@ -403,32 +477,8 @@ static int arizona_hpdet_do_id(struct arizona_extcon_info *info, int *reading)
403 if (arizona->pdata.hpdet_acc_id) { 477 if (arizona->pdata.hpdet_acc_id) {
404 info->hpdet_res[info->num_hpdet_res++] = *reading; 478 info->hpdet_res[info->num_hpdet_res++] = *reading;
405 479
406 /*
407 * If the impedence is too high don't measure the
408 * second ground.
409 */
410 if (info->num_hpdet_res == 1 && *reading >= 45) {
411 dev_dbg(arizona->dev, "Skipping ground flip\n");
412 info->hpdet_res[info->num_hpdet_res++] = *reading;
413 }
414
415 if (info->num_hpdet_res == 1) {
416 dev_dbg(arizona->dev, "Flipping ground\n");
417
418 regmap_update_bits(arizona->regmap,
419 ARIZONA_ACCESSORY_DETECT_MODE_1,
420 ARIZONA_ACCDET_SRC,
421 ~info->micd_modes[0].src);
422
423 regmap_update_bits(arizona->regmap,
424 ARIZONA_HEADPHONE_DETECT_1,
425 ARIZONA_HP_POLL, ARIZONA_HP_POLL);
426 return -EAGAIN;
427 }
428
429 /* Only check the mic directly if we didn't already ID it */ 480 /* Only check the mic directly if we didn't already ID it */
430 if (id_gpio && info->num_hpdet_res == 2 && 481 if (id_gpio && info->num_hpdet_res == 1) {
431 !((info->hpdet_res[0] > info->hpdet_res[1] * 2))) {
432 dev_dbg(arizona->dev, "Measuring mic\n"); 482 dev_dbg(arizona->dev, "Measuring mic\n");
433 483
434 regmap_update_bits(arizona->regmap, 484 regmap_update_bits(arizona->regmap,
@@ -447,22 +497,28 @@ static int arizona_hpdet_do_id(struct arizona_extcon_info *info, int *reading)
447 } 497 }
448 498
449 /* OK, got both. Now, compare... */ 499 /* OK, got both. Now, compare... */
450 dev_dbg(arizona->dev, "HPDET measured %d %d %d\n", 500 dev_dbg(arizona->dev, "HPDET measured %d %d\n",
451 info->hpdet_res[0], info->hpdet_res[1], 501 info->hpdet_res[0], info->hpdet_res[1]);
452 info->hpdet_res[2]);
453
454 502
455 /* Take the headphone impedance for the main report */ 503 /* Take the headphone impedance for the main report */
456 *reading = info->hpdet_res[0]; 504 *reading = info->hpdet_res[0];
457 505
506 /* Sometimes we get false readings due to slow insert */
507 if (*reading >= ARIZONA_HPDET_MAX && !info->hpdet_retried) {
508 dev_dbg(arizona->dev, "Retrying high impedance\n");
509 info->num_hpdet_res = 0;
510 info->hpdet_retried = true;
511 arizona_start_hpdet_acc_id(info);
512 pm_runtime_put(info->dev);
513 return -EAGAIN;
514 }
515
458 /* 516 /*
459 * Either the two grounds measure differently or we 517 * If we measure the mic as
460 * measure the mic as high impedance.
461 */ 518 */
462 if ((info->hpdet_res[0] > info->hpdet_res[1] * 2) || 519 if (!id_gpio || info->hpdet_res[1] > 50) {
463 (id_gpio && info->hpdet_res[2] > 10)) {
464 dev_dbg(arizona->dev, "Detected mic\n"); 520 dev_dbg(arizona->dev, "Detected mic\n");
465 info->mic = true; 521 *mic = true;
466 info->detecting = true; 522 info->detecting = true;
467 } else { 523 } else {
468 dev_dbg(arizona->dev, "Detected headphone\n"); 524 dev_dbg(arizona->dev, "Detected headphone\n");
@@ -484,8 +540,8 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
484 struct arizona *arizona = info->arizona; 540 struct arizona *arizona = info->arizona;
485 int id_gpio = arizona->pdata.hpdet_id_gpio; 541 int id_gpio = arizona->pdata.hpdet_id_gpio;
486 int report = ARIZONA_CABLE_HEADPHONE; 542 int report = ARIZONA_CABLE_HEADPHONE;
487 unsigned int val;
488 int ret, reading; 543 int ret, reading;
544 bool mic = false;
489 545
490 mutex_lock(&info->lock); 546 mutex_lock(&info->lock);
491 547
@@ -521,7 +577,7 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
521 ARIZONA_HP_IMPEDANCE_RANGE_MASK | ARIZONA_HP_POLL, 577 ARIZONA_HP_IMPEDANCE_RANGE_MASK | ARIZONA_HP_POLL,
522 0); 578 0);
523 579
524 ret = arizona_hpdet_do_id(info, &reading); 580 ret = arizona_hpdet_do_id(info, &reading, &mic);
525 if (ret == -EAGAIN) { 581 if (ret == -EAGAIN) {
526 goto out; 582 goto out;
527 } else if (ret < 0) { 583 } else if (ret < 0) {
@@ -539,28 +595,7 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
539 dev_err(arizona->dev, "Failed to report HP/line: %d\n", 595 dev_err(arizona->dev, "Failed to report HP/line: %d\n",
540 ret); 596 ret);
541 597
542 mutex_lock(&arizona->dapm->card->dapm_mutex); 598 arizona_extcon_do_magic(info, 0);
543
544 ret = regmap_read(arizona->regmap, ARIZONA_OUTPUT_ENABLES_1, &val);
545 if (ret != 0) {
546 dev_err(arizona->dev, "Failed to read output enables: %d\n",
547 ret);
548 val = 0;
549 }
550
551 if (!(val & (ARIZONA_OUT1L_ENA | ARIZONA_OUT1R_ENA))) {
552 ret = regmap_update_bits(arizona->regmap, 0x225, 0x4000, 0);
553 if (ret != 0)
554 dev_warn(arizona->dev, "Failed to undo magic: %d\n",
555 ret);
556
557 ret = regmap_update_bits(arizona->regmap, 0x226, 0x4000, 0);
558 if (ret != 0)
559 dev_warn(arizona->dev, "Failed to undo magic: %d\n",
560 ret);
561 }
562
563 mutex_unlock(&arizona->dapm->card->dapm_mutex);
564 599
565done: 600done:
566 if (id_gpio) 601 if (id_gpio)
@@ -572,7 +607,7 @@ done:
572 ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC); 607 ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
573 608
574 /* If we have a mic then reenable MICDET */ 609 /* If we have a mic then reenable MICDET */
575 if (info->mic) 610 if (mic || info->mic)
576 arizona_start_mic(info); 611 arizona_start_mic(info);
577 612
578 if (info->hpdet_active) { 613 if (info->hpdet_active) {
@@ -606,13 +641,7 @@ static void arizona_identify_headphone(struct arizona_extcon_info *info)
606 if (info->mic) 641 if (info->mic)
607 arizona_stop_mic(info); 642 arizona_stop_mic(info);
608 643
609 ret = regmap_update_bits(arizona->regmap, 0x225, 0x4000, 0x4000); 644 arizona_extcon_do_magic(info, 0x4000);
610 if (ret != 0)
611 dev_warn(arizona->dev, "Failed to do magic: %d\n", ret);
612
613 ret = regmap_update_bits(arizona->regmap, 0x226, 0x4000, 0x4000);
614 if (ret != 0)
615 dev_warn(arizona->dev, "Failed to do magic: %d\n", ret);
616 645
617 ret = regmap_update_bits(arizona->regmap, 646 ret = regmap_update_bits(arizona->regmap,
618 ARIZONA_ACCESSORY_DETECT_MODE_1, 647 ARIZONA_ACCESSORY_DETECT_MODE_1,
@@ -653,7 +682,8 @@ err:
653static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info) 682static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info)
654{ 683{
655 struct arizona *arizona = info->arizona; 684 struct arizona *arizona = info->arizona;
656 unsigned int val; 685 int hp_reading = 32;
686 bool mic;
657 int ret; 687 int ret;
658 688
659 dev_dbg(arizona->dev, "Starting identification via HPDET\n"); 689 dev_dbg(arizona->dev, "Starting identification via HPDET\n");
@@ -663,32 +693,7 @@ static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info)
663 693
664 info->hpdet_active = true; 694 info->hpdet_active = true;
665 695
666 arizona_extcon_pulse_micbias(info); 696 arizona_extcon_do_magic(info, 0x4000);
667
668 mutex_lock(&arizona->dapm->card->dapm_mutex);
669
670 ret = regmap_read(arizona->regmap, ARIZONA_OUTPUT_ENABLES_1, &val);
671 if (ret != 0) {
672 dev_err(arizona->dev, "Failed to read output enables: %d\n",
673 ret);
674 val = 0;
675 }
676
677 if (!(val & (ARIZONA_OUT1L_ENA | ARIZONA_OUT1R_ENA))) {
678 ret = regmap_update_bits(arizona->regmap, 0x225, 0x4000,
679 0x4000);
680 if (ret != 0)
681 dev_warn(arizona->dev, "Failed to do magic: %d\n",
682 ret);
683
684 ret = regmap_update_bits(arizona->regmap, 0x226, 0x4000,
685 0x4000);
686 if (ret != 0)
687 dev_warn(arizona->dev, "Failed to do magic: %d\n",
688 ret);
689 }
690
691 mutex_unlock(&arizona->dapm->card->dapm_mutex);
692 697
693 ret = regmap_update_bits(arizona->regmap, 698 ret = regmap_update_bits(arizona->regmap,
694 ARIZONA_ACCESSORY_DETECT_MODE_1, 699 ARIZONA_ACCESSORY_DETECT_MODE_1,
@@ -700,12 +705,18 @@ static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info)
700 goto err; 705 goto err;
701 } 706 }
702 707
703 ret = regmap_update_bits(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1, 708 if (arizona->pdata.hpdet_acc_id_line) {
704 ARIZONA_HP_POLL, ARIZONA_HP_POLL); 709 ret = regmap_update_bits(arizona->regmap,
705 if (ret != 0) { 710 ARIZONA_HEADPHONE_DETECT_1,
706 dev_err(arizona->dev, "Can't start HPDETL measurement: %d\n", 711 ARIZONA_HP_POLL, ARIZONA_HP_POLL);
707 ret); 712 if (ret != 0) {
708 goto err; 713 dev_err(arizona->dev,
714 "Can't start HPDETL measurement: %d\n",
715 ret);
716 goto err;
717 }
718 } else {
719 arizona_hpdet_do_id(info, &hp_reading, &mic);
709 } 720 }
710 721
711 return; 722 return;
@@ -724,28 +735,58 @@ err:
724 info->hpdet_active = false; 735 info->hpdet_active = false;
725} 736}
726 737
727static irqreturn_t arizona_micdet(int irq, void *data) 738static void arizona_micd_timeout_work(struct work_struct *work)
728{ 739{
729 struct arizona_extcon_info *info = data; 740 struct arizona_extcon_info *info = container_of(work,
741 struct arizona_extcon_info,
742 micd_timeout_work.work);
743
744 mutex_lock(&info->lock);
745
746 dev_dbg(info->arizona->dev, "MICD timed out, reporting HP\n");
747 arizona_identify_headphone(info);
748
749 info->detecting = false;
750
751 arizona_stop_mic(info);
752
753 mutex_unlock(&info->lock);
754}
755
756static void arizona_micd_detect(struct work_struct *work)
757{
758 struct arizona_extcon_info *info = container_of(work,
759 struct arizona_extcon_info,
760 micd_detect_work.work);
730 struct arizona *arizona = info->arizona; 761 struct arizona *arizona = info->arizona;
731 unsigned int val, lvl; 762 unsigned int val = 0, lvl;
732 int ret, i; 763 int ret, i, key;
764
765 cancel_delayed_work_sync(&info->micd_timeout_work);
733 766
734 mutex_lock(&info->lock); 767 mutex_lock(&info->lock);
735 768
736 ret = regmap_read(arizona->regmap, ARIZONA_MIC_DETECT_3, &val); 769 for (i = 0; i < 10 && !(val & 0x7fc); i++) {
737 if (ret != 0) { 770 ret = regmap_read(arizona->regmap, ARIZONA_MIC_DETECT_3, &val);
738 dev_err(arizona->dev, "Failed to read MICDET: %d\n", ret); 771 if (ret != 0) {
739 mutex_unlock(&info->lock); 772 dev_err(arizona->dev, "Failed to read MICDET: %d\n", ret);
740 return IRQ_NONE; 773 mutex_unlock(&info->lock);
741 } 774 return;
775 }
742 776
743 dev_dbg(arizona->dev, "MICDET: %x\n", val); 777 dev_dbg(arizona->dev, "MICDET: %x\n", val);
778
779 if (!(val & ARIZONA_MICD_VALID)) {
780 dev_warn(arizona->dev, "Microphone detection state invalid\n");
781 mutex_unlock(&info->lock);
782 return;
783 }
784 }
744 785
745 if (!(val & ARIZONA_MICD_VALID)) { 786 if (i == 10 && !(val & 0x7fc)) {
746 dev_warn(arizona->dev, "Microphone detection state invalid\n"); 787 dev_err(arizona->dev, "Failed to get valid MICDET value\n");
747 mutex_unlock(&info->lock); 788 mutex_unlock(&info->lock);
748 return IRQ_NONE; 789 return;
749 } 790 }
750 791
751 /* Due to jack detect this should never happen */ 792 /* Due to jack detect this should never happen */
@@ -786,7 +827,7 @@ static irqreturn_t arizona_micdet(int irq, void *data)
786 * impedence then give up and report headphones. 827 * impedence then give up and report headphones.
787 */ 828 */
788 if (info->detecting && (val & 0x3f8)) { 829 if (info->detecting && (val & 0x3f8)) {
789 if (info->jack_flips >= info->micd_num_modes) { 830 if (info->jack_flips >= info->micd_num_modes * 10) {
790 dev_dbg(arizona->dev, "Detected HP/line\n"); 831 dev_dbg(arizona->dev, "Detected HP/line\n");
791 arizona_identify_headphone(info); 832 arizona_identify_headphone(info);
792 833
@@ -816,12 +857,17 @@ static irqreturn_t arizona_micdet(int irq, void *data)
816 lvl = val & ARIZONA_MICD_LVL_MASK; 857 lvl = val & ARIZONA_MICD_LVL_MASK;
817 lvl >>= ARIZONA_MICD_LVL_SHIFT; 858 lvl >>= ARIZONA_MICD_LVL_SHIFT;
818 859
819 for (i = 0; i < ARIZONA_NUM_BUTTONS; i++) 860 for (i = 0; i < info->num_micd_ranges; i++)
820 if (lvl & arizona_lvl_to_key[i].status) 861 input_report_key(info->input,
821 input_report_key(info->input, 862 info->micd_ranges[i].key, 0);
822 arizona_lvl_to_key[i].report, 863
823 1); 864 WARN_ON(!lvl);
824 input_sync(info->input); 865 WARN_ON(ffs(lvl) - 1 >= info->num_micd_ranges);
866 if (lvl && ffs(lvl) - 1 < info->num_micd_ranges) {
867 key = info->micd_ranges[ffs(lvl) - 1].key;
868 input_report_key(info->input, key, 1);
869 input_sync(info->input);
870 }
825 871
826 } else if (info->detecting) { 872 } else if (info->detecting) {
827 dev_dbg(arizona->dev, "Headphone detected\n"); 873 dev_dbg(arizona->dev, "Headphone detected\n");
@@ -835,16 +881,41 @@ static irqreturn_t arizona_micdet(int irq, void *data)
835 } 881 }
836 } else { 882 } else {
837 dev_dbg(arizona->dev, "Mic button released\n"); 883 dev_dbg(arizona->dev, "Mic button released\n");
838 for (i = 0; i < ARIZONA_NUM_BUTTONS; i++) 884 for (i = 0; i < info->num_micd_ranges; i++)
839 input_report_key(info->input, 885 input_report_key(info->input,
840 arizona_lvl_to_key[i].report, 0); 886 info->micd_ranges[i].key, 0);
841 input_sync(info->input); 887 input_sync(info->input);
842 arizona_extcon_pulse_micbias(info); 888 arizona_extcon_pulse_micbias(info);
843 } 889 }
844 890
845handled: 891handled:
892 if (info->detecting)
893 schedule_delayed_work(&info->micd_timeout_work,
894 msecs_to_jiffies(info->micd_timeout));
895
846 pm_runtime_mark_last_busy(info->dev); 896 pm_runtime_mark_last_busy(info->dev);
847 mutex_unlock(&info->lock); 897 mutex_unlock(&info->lock);
898}
899
900static irqreturn_t arizona_micdet(int irq, void *data)
901{
902 struct arizona_extcon_info *info = data;
903 struct arizona *arizona = info->arizona;
904 int debounce = arizona->pdata.micd_detect_debounce;
905
906 cancel_delayed_work_sync(&info->micd_detect_work);
907 cancel_delayed_work_sync(&info->micd_timeout_work);
908
909 mutex_lock(&info->lock);
910 if (!info->detecting)
911 debounce = 0;
912 mutex_unlock(&info->lock);
913
914 if (debounce)
915 schedule_delayed_work(&info->micd_detect_work,
916 msecs_to_jiffies(debounce));
917 else
918 arizona_micd_detect(&info->micd_detect_work.work);
848 919
849 return IRQ_HANDLED; 920 return IRQ_HANDLED;
850} 921}
@@ -865,11 +936,13 @@ static irqreturn_t arizona_jackdet(int irq, void *data)
865 struct arizona_extcon_info *info = data; 936 struct arizona_extcon_info *info = data;
866 struct arizona *arizona = info->arizona; 937 struct arizona *arizona = info->arizona;
867 unsigned int val, present, mask; 938 unsigned int val, present, mask;
939 bool cancelled_hp, cancelled_mic;
868 int ret, i; 940 int ret, i;
869 941
870 pm_runtime_get_sync(info->dev); 942 cancelled_hp = cancel_delayed_work_sync(&info->hpdet_work);
943 cancelled_mic = cancel_delayed_work_sync(&info->micd_timeout_work);
871 944
872 cancel_delayed_work_sync(&info->hpdet_work); 945 pm_runtime_get_sync(info->dev);
873 946
874 mutex_lock(&info->lock); 947 mutex_lock(&info->lock);
875 948
@@ -890,7 +963,22 @@ static irqreturn_t arizona_jackdet(int irq, void *data)
890 return IRQ_NONE; 963 return IRQ_NONE;
891 } 964 }
892 965
893 if ((val & mask) == present) { 966 val &= mask;
967 if (val == info->last_jackdet) {
968 dev_dbg(arizona->dev, "Suppressing duplicate JACKDET\n");
969 if (cancelled_hp)
970 schedule_delayed_work(&info->hpdet_work,
971 msecs_to_jiffies(HPDET_DEBOUNCE));
972
973 if (cancelled_mic)
974 schedule_delayed_work(&info->micd_timeout_work,
975 msecs_to_jiffies(info->micd_timeout));
976
977 goto out;
978 }
979 info->last_jackdet = val;
980
981 if (info->last_jackdet == present) {
894 dev_dbg(arizona->dev, "Detected jack\n"); 982 dev_dbg(arizona->dev, "Detected jack\n");
895 ret = extcon_set_cable_state_(&info->edev, 983 ret = extcon_set_cable_state_(&info->edev,
896 ARIZONA_CABLE_MECHANICAL, true); 984 ARIZONA_CABLE_MECHANICAL, true);
@@ -907,7 +995,7 @@ static irqreturn_t arizona_jackdet(int irq, void *data)
907 arizona_start_mic(info); 995 arizona_start_mic(info);
908 } else { 996 } else {
909 schedule_delayed_work(&info->hpdet_work, 997 schedule_delayed_work(&info->hpdet_work,
910 msecs_to_jiffies(250)); 998 msecs_to_jiffies(HPDET_DEBOUNCE));
911 } 999 }
912 1000
913 regmap_update_bits(arizona->regmap, 1001 regmap_update_bits(arizona->regmap,
@@ -923,10 +1011,11 @@ static irqreturn_t arizona_jackdet(int irq, void *data)
923 info->hpdet_res[i] = 0; 1011 info->hpdet_res[i] = 0;
924 info->mic = false; 1012 info->mic = false;
925 info->hpdet_done = false; 1013 info->hpdet_done = false;
1014 info->hpdet_retried = false;
926 1015
927 for (i = 0; i < ARIZONA_NUM_BUTTONS; i++) 1016 for (i = 0; i < info->num_micd_ranges; i++)
928 input_report_key(info->input, 1017 input_report_key(info->input,
929 arizona_lvl_to_key[i].report, 0); 1018 info->micd_ranges[i].key, 0);
930 input_sync(info->input); 1019 input_sync(info->input);
931 1020
932 ret = extcon_update_state(&info->edev, 0xffffffff, 0); 1021 ret = extcon_update_state(&info->edev, 0xffffffff, 0);
@@ -940,6 +1029,11 @@ static irqreturn_t arizona_jackdet(int irq, void *data)
940 ARIZONA_MICD_CLAMP_DB | ARIZONA_JD1_DB); 1029 ARIZONA_MICD_CLAMP_DB | ARIZONA_JD1_DB);
941 } 1030 }
942 1031
1032 if (arizona->pdata.micd_timeout)
1033 info->micd_timeout = arizona->pdata.micd_timeout;
1034 else
1035 info->micd_timeout = DEFAULT_MICD_TIMEOUT;
1036
943 /* Clear trig_sts to make sure DCVDD is not forced up */ 1037 /* Clear trig_sts to make sure DCVDD is not forced up */
944 regmap_write(arizona->regmap, ARIZONA_AOD_WKUP_AND_TRIG, 1038 regmap_write(arizona->regmap, ARIZONA_AOD_WKUP_AND_TRIG,
945 ARIZONA_MICD_CLAMP_FALL_TRIG_STS | 1039 ARIZONA_MICD_CLAMP_FALL_TRIG_STS |
@@ -947,6 +1041,7 @@ static irqreturn_t arizona_jackdet(int irq, void *data)
947 ARIZONA_JD1_FALL_TRIG_STS | 1041 ARIZONA_JD1_FALL_TRIG_STS |
948 ARIZONA_JD1_RISE_TRIG_STS); 1042 ARIZONA_JD1_RISE_TRIG_STS);
949 1043
1044out:
950 mutex_unlock(&info->lock); 1045 mutex_unlock(&info->lock);
951 1046
952 pm_runtime_mark_last_busy(info->dev); 1047 pm_runtime_mark_last_busy(info->dev);
@@ -955,13 +1050,34 @@ static irqreturn_t arizona_jackdet(int irq, void *data)
955 return IRQ_HANDLED; 1050 return IRQ_HANDLED;
956} 1051}
957 1052
1053/* Map a level onto a slot in the register bank */
1054static void arizona_micd_set_level(struct arizona *arizona, int index,
1055 unsigned int level)
1056{
1057 int reg;
1058 unsigned int mask;
1059
1060 reg = ARIZONA_MIC_DETECT_LEVEL_4 - (index / 2);
1061
1062 if (!(index % 2)) {
1063 mask = 0x3f00;
1064 level <<= 8;
1065 } else {
1066 mask = 0x3f;
1067 }
1068
1069 /* Program the level itself */
1070 regmap_update_bits(arizona->regmap, reg, mask, level);
1071}
1072
958static int arizona_extcon_probe(struct platform_device *pdev) 1073static int arizona_extcon_probe(struct platform_device *pdev)
959{ 1074{
960 struct arizona *arizona = dev_get_drvdata(pdev->dev.parent); 1075 struct arizona *arizona = dev_get_drvdata(pdev->dev.parent);
961 struct arizona_pdata *pdata; 1076 struct arizona_pdata *pdata;
962 struct arizona_extcon_info *info; 1077 struct arizona_extcon_info *info;
1078 unsigned int val;
963 int jack_irq_fall, jack_irq_rise; 1079 int jack_irq_fall, jack_irq_rise;
964 int ret, mode, i; 1080 int ret, mode, i, j;
965 1081
966 if (!arizona->dapm || !arizona->dapm->card) 1082 if (!arizona->dapm || !arizona->dapm->card)
967 return -EPROBE_DEFER; 1083 return -EPROBE_DEFER;
@@ -985,7 +1101,10 @@ static int arizona_extcon_probe(struct platform_device *pdev)
985 mutex_init(&info->lock); 1101 mutex_init(&info->lock);
986 info->arizona = arizona; 1102 info->arizona = arizona;
987 info->dev = &pdev->dev; 1103 info->dev = &pdev->dev;
1104 info->last_jackdet = ~(ARIZONA_MICD_CLAMP_STS | ARIZONA_JD1_STS);
988 INIT_DELAYED_WORK(&info->hpdet_work, arizona_hpdet_work); 1105 INIT_DELAYED_WORK(&info->hpdet_work, arizona_hpdet_work);
1106 INIT_DELAYED_WORK(&info->micd_detect_work, arizona_micd_detect);
1107 INIT_DELAYED_WORK(&info->micd_timeout_work, arizona_micd_timeout_work);
989 platform_set_drvdata(pdev, info); 1108 platform_set_drvdata(pdev, info);
990 1109
991 switch (arizona->type) { 1110 switch (arizona->type) {
@@ -1014,6 +1133,17 @@ static int arizona_extcon_probe(struct platform_device *pdev)
1014 goto err; 1133 goto err;
1015 } 1134 }
1016 1135
1136 info->input = devm_input_allocate_device(&pdev->dev);
1137 if (!info->input) {
1138 dev_err(arizona->dev, "Can't allocate input dev\n");
1139 ret = -ENOMEM;
1140 goto err_register;
1141 }
1142
1143 info->input->name = "Headset";
1144 info->input->phys = "arizona/extcon";
1145 info->input->dev.parent = &pdev->dev;
1146
1017 if (pdata->num_micd_configs) { 1147 if (pdata->num_micd_configs) {
1018 info->micd_modes = pdata->micd_configs; 1148 info->micd_modes = pdata->micd_configs;
1019 info->micd_num_modes = pdata->num_micd_configs; 1149 info->micd_num_modes = pdata->num_micd_configs;
@@ -1069,15 +1199,79 @@ static int arizona_extcon_probe(struct platform_device *pdev)
1069 arizona->pdata.micd_dbtime 1199 arizona->pdata.micd_dbtime
1070 << ARIZONA_MICD_DBTIME_SHIFT); 1200 << ARIZONA_MICD_DBTIME_SHIFT);
1071 1201
1202 BUILD_BUG_ON(ARRAY_SIZE(arizona_micd_levels) != 0x40);
1203
1204 if (arizona->pdata.num_micd_ranges) {
1205 info->micd_ranges = pdata->micd_ranges;
1206 info->num_micd_ranges = pdata->num_micd_ranges;
1207 } else {
1208 info->micd_ranges = micd_default_ranges;
1209 info->num_micd_ranges = ARRAY_SIZE(micd_default_ranges);
1210 }
1211
1212 if (arizona->pdata.num_micd_ranges > ARIZONA_MAX_MICD_RANGE) {
1213 dev_err(arizona->dev, "Too many MICD ranges: %d\n",
1214 arizona->pdata.num_micd_ranges);
1215 }
1216
1217 if (info->num_micd_ranges > 1) {
1218 for (i = 1; i < info->num_micd_ranges; i++) {
1219 if (info->micd_ranges[i - 1].max >
1220 info->micd_ranges[i].max) {
1221 dev_err(arizona->dev,
1222 "MICD ranges must be sorted\n");
1223 ret = -EINVAL;
1224 goto err_input;
1225 }
1226 }
1227 }
1228
1229 /* Disable all buttons by default */
1230 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_2,
1231 ARIZONA_MICD_LVL_SEL_MASK, 0x81);
1232
1233 /* Set up all the buttons the user specified */
1234 for (i = 0; i < info->num_micd_ranges; i++) {
1235 for (j = 0; j < ARRAY_SIZE(arizona_micd_levels); j++)
1236 if (arizona_micd_levels[j] >= info->micd_ranges[i].max)
1237 break;
1238
1239 if (j == ARRAY_SIZE(arizona_micd_levels)) {
1240 dev_err(arizona->dev, "Unsupported MICD level %d\n",
1241 info->micd_ranges[i].max);
1242 ret = -EINVAL;
1243 goto err_input;
1244 }
1245
1246 dev_dbg(arizona->dev, "%d ohms for MICD threshold %d\n",
1247 arizona_micd_levels[j], i);
1248
1249 arizona_micd_set_level(arizona, i, j);
1250 input_set_capability(info->input, EV_KEY,
1251 info->micd_ranges[i].key);
1252
1253 /* Enable reporting of that range */
1254 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_2,
1255 1 << i, 1 << i);
1256 }
1257
1258 /* Set all the remaining keys to a maximum */
1259 for (; i < ARIZONA_MAX_MICD_RANGE; i++)
1260 arizona_micd_set_level(arizona, i, 0x3f);
1261
1072 /* 1262 /*
1073 * If we have a clamp use it, activating in conjunction with 1263 * If we have a clamp use it, activating in conjunction with
1074 * GPIO5 if that is connected for jack detect operation. 1264 * GPIO5 if that is connected for jack detect operation.
1075 */ 1265 */
1076 if (info->micd_clamp) { 1266 if (info->micd_clamp) {
1077 if (arizona->pdata.jd_gpio5) { 1267 if (arizona->pdata.jd_gpio5) {
1078 /* Put the GPIO into input mode */ 1268 /* Put the GPIO into input mode with optional pull */
1269 val = 0xc101;
1270 if (arizona->pdata.jd_gpio5_nopull)
1271 val &= ~ARIZONA_GPN_PU;
1272
1079 regmap_write(arizona->regmap, ARIZONA_GPIO5_CTRL, 1273 regmap_write(arizona->regmap, ARIZONA_GPIO5_CTRL,
1080 0xc101); 1274 val);
1081 1275
1082 regmap_update_bits(arizona->regmap, 1276 regmap_update_bits(arizona->regmap,
1083 ARIZONA_MICD_CLAMP_CONTROL, 1277 ARIZONA_MICD_CLAMP_CONTROL,
@@ -1096,20 +1290,6 @@ static int arizona_extcon_probe(struct platform_device *pdev)
1096 1290
1097 arizona_extcon_set_mode(info, 0); 1291 arizona_extcon_set_mode(info, 0);
1098 1292
1099 info->input = devm_input_allocate_device(&pdev->dev);
1100 if (!info->input) {
1101 dev_err(arizona->dev, "Can't allocate input dev\n");
1102 ret = -ENOMEM;
1103 goto err_register;
1104 }
1105
1106 for (i = 0; i < ARIZONA_NUM_BUTTONS; i++)
1107 input_set_capability(info->input, EV_KEY,
1108 arizona_lvl_to_key[i].report);
1109 info->input->name = "Headset";
1110 info->input->phys = "arizona/extcon";
1111 info->input->dev.parent = &pdev->dev;
1112
1113 pm_runtime_enable(&pdev->dev); 1293 pm_runtime_enable(&pdev->dev);
1114 pm_runtime_idle(&pdev->dev); 1294 pm_runtime_idle(&pdev->dev);
1115 pm_runtime_get_sync(&pdev->dev); 1295 pm_runtime_get_sync(&pdev->dev);
diff --git a/drivers/extcon/extcon-max77693.c b/drivers/extcon/extcon-max77693.c
index 8f3c947b0029..b56bdaa27d4b 100644
--- a/drivers/extcon/extcon-max77693.c
+++ b/drivers/extcon/extcon-max77693.c
@@ -38,7 +38,7 @@
38 * extcon-max77693 driver use 'default_init_data' to bring up base operation 38 * extcon-max77693 driver use 'default_init_data' to bring up base operation
39 * of MAX77693 MUIC device. 39 * of MAX77693 MUIC device.
40 */ 40 */
41struct max77693_reg_data default_init_data[] = { 41static struct max77693_reg_data default_init_data[] = {
42 { 42 {
43 /* STATUS2 - [3]ChgDetRun */ 43 /* STATUS2 - [3]ChgDetRun */
44 .addr = MAX77693_MUIC_REG_STATUS2, 44 .addr = MAX77693_MUIC_REG_STATUS2,
@@ -258,7 +258,7 @@ static int max77693_muic_set_debounce_time(struct max77693_muic_info *info,
258 CONTROL3_ADCDBSET_MASK); 258 CONTROL3_ADCDBSET_MASK);
259 if (ret) { 259 if (ret) {
260 dev_err(info->dev, "failed to set ADC debounce time\n"); 260 dev_err(info->dev, "failed to set ADC debounce time\n");
261 return -EAGAIN; 261 return ret;
262 } 262 }
263 break; 263 break;
264 default: 264 default:
@@ -294,7 +294,7 @@ static int max77693_muic_set_path(struct max77693_muic_info *info,
294 MAX77693_MUIC_REG_CTRL1, ctrl1, COMP_SW_MASK); 294 MAX77693_MUIC_REG_CTRL1, ctrl1, COMP_SW_MASK);
295 if (ret < 0) { 295 if (ret < 0) {
296 dev_err(info->dev, "failed to update MUIC register\n"); 296 dev_err(info->dev, "failed to update MUIC register\n");
297 return -EAGAIN; 297 return ret;
298 } 298 }
299 299
300 if (attached) 300 if (attached)
@@ -307,7 +307,7 @@ static int max77693_muic_set_path(struct max77693_muic_info *info,
307 CONTROL2_LOWPWR_MASK | CONTROL2_CPEN_MASK); 307 CONTROL2_LOWPWR_MASK | CONTROL2_CPEN_MASK);
308 if (ret < 0) { 308 if (ret < 0) {
309 dev_err(info->dev, "failed to update MUIC register\n"); 309 dev_err(info->dev, "failed to update MUIC register\n");
310 return -EAGAIN; 310 return ret;
311 } 311 }
312 312
313 dev_info(info->dev, 313 dev_info(info->dev,
@@ -1035,7 +1035,7 @@ static int max77693_muic_detect_accessory(struct max77693_muic_info *info)
1035 if (ret) { 1035 if (ret) {
1036 dev_err(info->dev, "failed to read MUIC register\n"); 1036 dev_err(info->dev, "failed to read MUIC register\n");
1037 mutex_unlock(&info->mutex); 1037 mutex_unlock(&info->mutex);
1038 return -EINVAL; 1038 return ret;
1039 } 1039 }
1040 1040
1041 adc = max77693_muic_get_cable_type(info, MAX77693_CABLE_GROUP_ADC, 1041 adc = max77693_muic_get_cable_type(info, MAX77693_CABLE_GROUP_ADC,
diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c
index 69641bcae325..67d6738d85a0 100644
--- a/drivers/extcon/extcon-max8997.c
+++ b/drivers/extcon/extcon-max8997.c
@@ -196,7 +196,7 @@ static int max8997_muic_set_debounce_time(struct max8997_muic_info *info,
196 CONTROL3_ADCDBSET_MASK); 196 CONTROL3_ADCDBSET_MASK);
197 if (ret) { 197 if (ret) {
198 dev_err(info->dev, "failed to set ADC debounce time\n"); 198 dev_err(info->dev, "failed to set ADC debounce time\n");
199 return -EAGAIN; 199 return ret;
200 } 200 }
201 break; 201 break;
202 default: 202 default:
@@ -232,7 +232,7 @@ static int max8997_muic_set_path(struct max8997_muic_info *info,
232 MAX8997_MUIC_REG_CONTROL1, ctrl1, COMP_SW_MASK); 232 MAX8997_MUIC_REG_CONTROL1, ctrl1, COMP_SW_MASK);
233 if (ret < 0) { 233 if (ret < 0) {
234 dev_err(info->dev, "failed to update MUIC register\n"); 234 dev_err(info->dev, "failed to update MUIC register\n");
235 return -EAGAIN; 235 return ret;
236 } 236 }
237 237
238 if (attached) 238 if (attached)
@@ -245,7 +245,7 @@ static int max8997_muic_set_path(struct max8997_muic_info *info,
245 CONTROL2_LOWPWR_MASK | CONTROL2_CPEN_MASK); 245 CONTROL2_LOWPWR_MASK | CONTROL2_CPEN_MASK);
246 if (ret < 0) { 246 if (ret < 0) {
247 dev_err(info->dev, "failed to update MUIC register\n"); 247 dev_err(info->dev, "failed to update MUIC register\n");
248 return -EAGAIN; 248 return ret;
249 } 249 }
250 250
251 dev_info(info->dev, 251 dev_info(info->dev,
@@ -397,7 +397,7 @@ static int max8997_muic_handle_jig_uart(struct max8997_muic_info *info,
397 ret = max8997_muic_set_path(info, info->path_uart, attached); 397 ret = max8997_muic_set_path(info, info->path_uart, attached);
398 if (ret) { 398 if (ret) {
399 dev_err(info->dev, "failed to update muic register\n"); 399 dev_err(info->dev, "failed to update muic register\n");
400 return -EINVAL; 400 return ret;
401 } 401 }
402 402
403 extcon_set_cable_state(info->edev, "JIG", attached); 403 extcon_set_cable_state(info->edev, "JIG", attached);
@@ -608,7 +608,7 @@ static int max8997_muic_detect_dev(struct max8997_muic_info *info)
608 if (ret) { 608 if (ret) {
609 dev_err(info->dev, "failed to read MUIC register\n"); 609 dev_err(info->dev, "failed to read MUIC register\n");
610 mutex_unlock(&info->mutex); 610 mutex_unlock(&info->mutex);
611 return -EINVAL; 611 return ret;
612 } 612 }
613 613
614 adc = max8997_muic_get_cable_type(info, MAX8997_CABLE_GROUP_ADC, 614 adc = max8997_muic_get_cable_type(info, MAX8997_CABLE_GROUP_ADC,
@@ -646,7 +646,7 @@ static void max8997_muic_detect_cable_wq(struct work_struct *work)
646 646
647 ret = max8997_muic_detect_dev(info); 647 ret = max8997_muic_detect_dev(info);
648 if (ret < 0) 648 if (ret < 0)
649 pr_err("failed to detect cable type\n"); 649 dev_err(info->dev, "failed to detect cable type\n");
650} 650}
651 651
652static int max8997_muic_probe(struct platform_device *pdev) 652static int max8997_muic_probe(struct platform_device *pdev)
diff --git a/drivers/hv/Makefile b/drivers/hv/Makefile
index e6abfa02d8b7..0a74b5661186 100644
--- a/drivers/hv/Makefile
+++ b/drivers/hv/Makefile
@@ -5,4 +5,4 @@ obj-$(CONFIG_HYPERV_BALLOON) += hv_balloon.o
5hv_vmbus-y := vmbus_drv.o \ 5hv_vmbus-y := vmbus_drv.o \
6 hv.o connection.o channel.o \ 6 hv.o connection.o channel.o \
7 channel_mgmt.o ring_buffer.o 7 channel_mgmt.o ring_buffer.o
8hv_utils-y := hv_util.o hv_kvp.o 8hv_utils-y := hv_util.o hv_kvp.o hv_snapshot.o
diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c
index ff1be167eb04..bad8128b283a 100644
--- a/drivers/hv/channel_mgmt.c
+++ b/drivers/hv/channel_mgmt.c
@@ -165,8 +165,19 @@ static void vmbus_process_rescind_offer(struct work_struct *work)
165 struct vmbus_channel *channel = container_of(work, 165 struct vmbus_channel *channel = container_of(work,
166 struct vmbus_channel, 166 struct vmbus_channel,
167 work); 167 work);
168 unsigned long flags;
169 struct vmbus_channel_relid_released msg;
168 170
169 vmbus_device_unregister(channel->device_obj); 171 vmbus_device_unregister(channel->device_obj);
172 memset(&msg, 0, sizeof(struct vmbus_channel_relid_released));
173 msg.child_relid = channel->offermsg.child_relid;
174 msg.header.msgtype = CHANNELMSG_RELID_RELEASED;
175 vmbus_post_msg(&msg, sizeof(struct vmbus_channel_relid_released));
176
177 spin_lock_irqsave(&vmbus_connection.channel_lock, flags);
178 list_del(&channel->listentry);
179 spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags);
180 free_channel(channel);
170} 181}
171 182
172void vmbus_free_channels(void) 183void vmbus_free_channels(void)
diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
index 731158910c1e..ae4923756d98 100644
--- a/drivers/hv/hv.c
+++ b/drivers/hv/hv.c
@@ -289,9 +289,8 @@ void hv_synic_init(void *arg)
289 /* Check the version */ 289 /* Check the version */
290 rdmsrl(HV_X64_MSR_SVERSION, version); 290 rdmsrl(HV_X64_MSR_SVERSION, version);
291 291
292 hv_context.event_dpc[cpu] = (struct tasklet_struct *) 292 hv_context.event_dpc[cpu] = kmalloc(sizeof(struct tasklet_struct),
293 kmalloc(sizeof(struct tasklet_struct), 293 GFP_ATOMIC);
294 GFP_ATOMIC);
295 if (hv_context.event_dpc[cpu] == NULL) { 294 if (hv_context.event_dpc[cpu] == NULL) {
296 pr_err("Unable to allocate event dpc\n"); 295 pr_err("Unable to allocate event dpc\n");
297 goto cleanup; 296 goto cleanup;
diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
index 37873213e24f..4c605c70ebf9 100644
--- a/drivers/hv/hv_balloon.c
+++ b/drivers/hv/hv_balloon.c
@@ -117,7 +117,14 @@ union dm_caps {
117 struct { 117 struct {
118 __u64 balloon:1; 118 __u64 balloon:1;
119 __u64 hot_add:1; 119 __u64 hot_add:1;
120 __u64 reservedz:62; 120 /*
121 * To support guests that may have alignment
122 * limitations on hot-add, the guest can specify
123 * its alignment requirements; a value of n
124 * represents an alignment of 2^n in mega bytes.
125 */
126 __u64 hot_add_alignment:4;
127 __u64 reservedz:58;
121 } cap_bits; 128 } cap_bits;
122 __u64 caps; 129 __u64 caps;
123} __packed; 130} __packed;
@@ -412,13 +419,45 @@ struct dm_info_msg {
412 * End protocol definitions. 419 * End protocol definitions.
413 */ 420 */
414 421
415static bool hot_add; 422/*
423 * State to manage hot adding memory into the guest.
424 * The range start_pfn : end_pfn specifies the range
425 * that the host has asked us to hot add. The range
426 * start_pfn : ha_end_pfn specifies the range that we have
427 * currently hot added. We hot add in multiples of 128M
428 * chunks; it is possible that we may not be able to bring
429 * online all the pages in the region. The range
430 * covered_start_pfn : covered_end_pfn defines the pages that can
431 * be brough online.
432 */
433
434struct hv_hotadd_state {
435 struct list_head list;
436 unsigned long start_pfn;
437 unsigned long covered_start_pfn;
438 unsigned long covered_end_pfn;
439 unsigned long ha_end_pfn;
440 unsigned long end_pfn;
441};
442
443struct balloon_state {
444 __u32 num_pages;
445 struct work_struct wrk;
446};
447
448struct hot_add_wrk {
449 union dm_mem_page_range ha_page_range;
450 union dm_mem_page_range ha_region_range;
451 struct work_struct wrk;
452};
453
454static bool hot_add = true;
416static bool do_hot_add; 455static bool do_hot_add;
417/* 456/*
418 * Delay reporting memory pressure by 457 * Delay reporting memory pressure by
419 * the specified number of seconds. 458 * the specified number of seconds.
420 */ 459 */
421static uint pressure_report_delay = 30; 460static uint pressure_report_delay = 45;
422 461
423module_param(hot_add, bool, (S_IRUGO | S_IWUSR)); 462module_param(hot_add, bool, (S_IRUGO | S_IWUSR));
424MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add"); 463MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
@@ -446,6 +485,7 @@ enum hv_dm_state {
446static __u8 recv_buffer[PAGE_SIZE]; 485static __u8 recv_buffer[PAGE_SIZE];
447static __u8 *send_buffer; 486static __u8 *send_buffer;
448#define PAGES_IN_2M 512 487#define PAGES_IN_2M 512
488#define HA_CHUNK (32 * 1024)
449 489
450struct hv_dynmem_device { 490struct hv_dynmem_device {
451 struct hv_device *dev; 491 struct hv_device *dev;
@@ -459,7 +499,28 @@ struct hv_dynmem_device {
459 unsigned int num_pages_ballooned; 499 unsigned int num_pages_ballooned;
460 500
461 /* 501 /*
462 * This thread handles both balloon/hot-add 502 * State to manage the ballooning (up) operation.
503 */
504 struct balloon_state balloon_wrk;
505
506 /*
507 * State to execute the "hot-add" operation.
508 */
509 struct hot_add_wrk ha_wrk;
510
511 /*
512 * This state tracks if the host has specified a hot-add
513 * region.
514 */
515 bool host_specified_ha_region;
516
517 /*
518 * State to synchronize hot-add.
519 */
520 struct completion ol_waitevent;
521 bool ha_waiting;
522 /*
523 * This thread handles hot-add
463 * requests from the host as well as notifying 524 * requests from the host as well as notifying
464 * the host with regards to memory pressure in 525 * the host with regards to memory pressure in
465 * the guest. 526 * the guest.
@@ -467,6 +528,11 @@ struct hv_dynmem_device {
467 struct task_struct *thread; 528 struct task_struct *thread;
468 529
469 /* 530 /*
531 * A list of hot-add regions.
532 */
533 struct list_head ha_region_list;
534
535 /*
470 * We start with the highest version we can support 536 * We start with the highest version we can support
471 * and downgrade based on the host; we save here the 537 * and downgrade based on the host; we save here the
472 * next version to try. 538 * next version to try.
@@ -476,35 +542,358 @@ struct hv_dynmem_device {
476 542
477static struct hv_dynmem_device dm_device; 543static struct hv_dynmem_device dm_device;
478 544
479static void hot_add_req(struct hv_dynmem_device *dm, struct dm_hot_add *msg) 545#ifdef CONFIG_MEMORY_HOTPLUG
546
547static void hv_bring_pgs_online(unsigned long start_pfn, unsigned long size)
480{ 548{
549 int i;
481 550
482 struct dm_hot_add_response resp; 551 for (i = 0; i < size; i++) {
552 struct page *pg;
553 pg = pfn_to_page(start_pfn + i);
554 __online_page_set_limits(pg);
555 __online_page_increment_counters(pg);
556 __online_page_free(pg);
557 }
558}
483 559
484 if (do_hot_add) { 560static void hv_mem_hot_add(unsigned long start, unsigned long size,
561 unsigned long pfn_count,
562 struct hv_hotadd_state *has)
563{
564 int ret = 0;
565 int i, nid, t;
566 unsigned long start_pfn;
567 unsigned long processed_pfn;
568 unsigned long total_pfn = pfn_count;
569
570 for (i = 0; i < (size/HA_CHUNK); i++) {
571 start_pfn = start + (i * HA_CHUNK);
572 has->ha_end_pfn += HA_CHUNK;
573
574 if (total_pfn > HA_CHUNK) {
575 processed_pfn = HA_CHUNK;
576 total_pfn -= HA_CHUNK;
577 } else {
578 processed_pfn = total_pfn;
579 total_pfn = 0;
580 }
581
582 has->covered_end_pfn += processed_pfn;
583
584 init_completion(&dm_device.ol_waitevent);
585 dm_device.ha_waiting = true;
586
587 nid = memory_add_physaddr_to_nid(PFN_PHYS(start_pfn));
588 ret = add_memory(nid, PFN_PHYS((start_pfn)),
589 (HA_CHUNK << PAGE_SHIFT));
485 590
486 pr_info("Memory hot add not supported\n"); 591 if (ret) {
592 pr_info("hot_add memory failed error is %d\n", ret);
593 if (ret == -EEXIST) {
594 /*
595 * This error indicates that the error
596 * is not a transient failure. This is the
597 * case where the guest's physical address map
598 * precludes hot adding memory. Stop all further
599 * memory hot-add.
600 */
601 do_hot_add = false;
602 }
603 has->ha_end_pfn -= HA_CHUNK;
604 has->covered_end_pfn -= processed_pfn;
605 break;
606 }
487 607
488 /* 608 /*
489 * Currently we do not support hot add. 609 * Wait for the memory block to be onlined.
490 * Just fail the request.
491 */ 610 */
611 t = wait_for_completion_timeout(&dm_device.ol_waitevent, 5*HZ);
612 if (t == 0) {
613 pr_info("hot_add memory timedout\n");
614 has->ha_end_pfn -= HA_CHUNK;
615 has->covered_end_pfn -= processed_pfn;
616 break;
617 }
618
619 }
620
621 return;
622}
623
624static void hv_online_page(struct page *pg)
625{
626 struct list_head *cur;
627 struct hv_hotadd_state *has;
628 unsigned long cur_start_pgp;
629 unsigned long cur_end_pgp;
630
631 if (dm_device.ha_waiting) {
632 dm_device.ha_waiting = false;
633 complete(&dm_device.ol_waitevent);
634 }
635
636 list_for_each(cur, &dm_device.ha_region_list) {
637 has = list_entry(cur, struct hv_hotadd_state, list);
638 cur_start_pgp = (unsigned long)
639 pfn_to_page(has->covered_start_pfn);
640 cur_end_pgp = (unsigned long)pfn_to_page(has->covered_end_pfn);
641
642 if (((unsigned long)pg >= cur_start_pgp) &&
643 ((unsigned long)pg < cur_end_pgp)) {
644 /*
645 * This frame is currently backed; online the
646 * page.
647 */
648 __online_page_set_limits(pg);
649 __online_page_increment_counters(pg);
650 __online_page_free(pg);
651 has->covered_start_pfn++;
652 }
653 }
654}
655
656static bool pfn_covered(unsigned long start_pfn, unsigned long pfn_cnt)
657{
658 struct list_head *cur;
659 struct hv_hotadd_state *has;
660 unsigned long residual, new_inc;
661
662 if (list_empty(&dm_device.ha_region_list))
663 return false;
664
665 list_for_each(cur, &dm_device.ha_region_list) {
666 has = list_entry(cur, struct hv_hotadd_state, list);
667
668 /*
669 * If the pfn range we are dealing with is not in the current
670 * "hot add block", move on.
671 */
672 if ((start_pfn >= has->end_pfn))
673 continue;
674 /*
675 * If the current hot add-request extends beyond
676 * our current limit; extend it.
677 */
678 if ((start_pfn + pfn_cnt) > has->end_pfn) {
679 residual = (start_pfn + pfn_cnt - has->end_pfn);
680 /*
681 * Extend the region by multiples of HA_CHUNK.
682 */
683 new_inc = (residual / HA_CHUNK) * HA_CHUNK;
684 if (residual % HA_CHUNK)
685 new_inc += HA_CHUNK;
686
687 has->end_pfn += new_inc;
688 }
689
690 /*
691 * If the current start pfn is not where the covered_end
692 * is, update it.
693 */
694
695 if (has->covered_end_pfn != start_pfn) {
696 has->covered_end_pfn = start_pfn;
697 has->covered_start_pfn = start_pfn;
698 }
699 return true;
700
492 } 701 }
493 702
703 return false;
704}
705
706static unsigned long handle_pg_range(unsigned long pg_start,
707 unsigned long pg_count)
708{
709 unsigned long start_pfn = pg_start;
710 unsigned long pfn_cnt = pg_count;
711 unsigned long size;
712 struct list_head *cur;
713 struct hv_hotadd_state *has;
714 unsigned long pgs_ol = 0;
715 unsigned long old_covered_state;
716
717 if (list_empty(&dm_device.ha_region_list))
718 return 0;
719
720 list_for_each(cur, &dm_device.ha_region_list) {
721 has = list_entry(cur, struct hv_hotadd_state, list);
722
723 /*
724 * If the pfn range we are dealing with is not in the current
725 * "hot add block", move on.
726 */
727 if ((start_pfn >= has->end_pfn))
728 continue;
729
730 old_covered_state = has->covered_end_pfn;
731
732 if (start_pfn < has->ha_end_pfn) {
733 /*
734 * This is the case where we are backing pages
735 * in an already hot added region. Bring
736 * these pages online first.
737 */
738 pgs_ol = has->ha_end_pfn - start_pfn;
739 if (pgs_ol > pfn_cnt)
740 pgs_ol = pfn_cnt;
741 hv_bring_pgs_online(start_pfn, pgs_ol);
742 has->covered_end_pfn += pgs_ol;
743 has->covered_start_pfn += pgs_ol;
744 pfn_cnt -= pgs_ol;
745 }
746
747 if ((has->ha_end_pfn < has->end_pfn) && (pfn_cnt > 0)) {
748 /*
749 * We have some residual hot add range
750 * that needs to be hot added; hot add
751 * it now. Hot add a multiple of
752 * of HA_CHUNK that fully covers the pages
753 * we have.
754 */
755 size = (has->end_pfn - has->ha_end_pfn);
756 if (pfn_cnt <= size) {
757 size = ((pfn_cnt / HA_CHUNK) * HA_CHUNK);
758 if (pfn_cnt % HA_CHUNK)
759 size += HA_CHUNK;
760 } else {
761 pfn_cnt = size;
762 }
763 hv_mem_hot_add(has->ha_end_pfn, size, pfn_cnt, has);
764 }
765 /*
766 * If we managed to online any pages that were given to us,
767 * we declare success.
768 */
769 return has->covered_end_pfn - old_covered_state;
770
771 }
772
773 return 0;
774}
775
776static unsigned long process_hot_add(unsigned long pg_start,
777 unsigned long pfn_cnt,
778 unsigned long rg_start,
779 unsigned long rg_size)
780{
781 struct hv_hotadd_state *ha_region = NULL;
782
783 if (pfn_cnt == 0)
784 return 0;
785
786 if (!dm_device.host_specified_ha_region)
787 if (pfn_covered(pg_start, pfn_cnt))
788 goto do_pg_range;
789
790 /*
791 * If the host has specified a hot-add range; deal with it first.
792 */
793
794 if (rg_size != 0) {
795 ha_region = kzalloc(sizeof(struct hv_hotadd_state), GFP_KERNEL);
796 if (!ha_region)
797 return 0;
798
799 INIT_LIST_HEAD(&ha_region->list);
800
801 list_add_tail(&ha_region->list, &dm_device.ha_region_list);
802 ha_region->start_pfn = rg_start;
803 ha_region->ha_end_pfn = rg_start;
804 ha_region->covered_start_pfn = pg_start;
805 ha_region->covered_end_pfn = pg_start;
806 ha_region->end_pfn = rg_start + rg_size;
807 }
808
809do_pg_range:
810 /*
811 * Process the page range specified; bringing them
812 * online if possible.
813 */
814 return handle_pg_range(pg_start, pfn_cnt);
815}
816
817#endif
818
819static void hot_add_req(struct work_struct *dummy)
820{
821 struct dm_hot_add_response resp;
822#ifdef CONFIG_MEMORY_HOTPLUG
823 unsigned long pg_start, pfn_cnt;
824 unsigned long rg_start, rg_sz;
825#endif
826 struct hv_dynmem_device *dm = &dm_device;
827
494 memset(&resp, 0, sizeof(struct dm_hot_add_response)); 828 memset(&resp, 0, sizeof(struct dm_hot_add_response));
495 resp.hdr.type = DM_MEM_HOT_ADD_RESPONSE; 829 resp.hdr.type = DM_MEM_HOT_ADD_RESPONSE;
496 resp.hdr.size = sizeof(struct dm_hot_add_response); 830 resp.hdr.size = sizeof(struct dm_hot_add_response);
497 resp.hdr.trans_id = atomic_inc_return(&trans_id); 831 resp.hdr.trans_id = atomic_inc_return(&trans_id);
498 832
499 resp.page_count = 0; 833#ifdef CONFIG_MEMORY_HOTPLUG
500 resp.result = 0; 834 pg_start = dm->ha_wrk.ha_page_range.finfo.start_page;
835 pfn_cnt = dm->ha_wrk.ha_page_range.finfo.page_cnt;
836
837 rg_start = dm->ha_wrk.ha_region_range.finfo.start_page;
838 rg_sz = dm->ha_wrk.ha_region_range.finfo.page_cnt;
839
840 if ((rg_start == 0) && (!dm->host_specified_ha_region)) {
841 unsigned long region_size;
842 unsigned long region_start;
843
844 /*
845 * The host has not specified the hot-add region.
846 * Based on the hot-add page range being specified,
847 * compute a hot-add region that can cover the pages
848 * that need to be hot-added while ensuring the alignment
849 * and size requirements of Linux as it relates to hot-add.
850 */
851 region_start = pg_start;
852 region_size = (pfn_cnt / HA_CHUNK) * HA_CHUNK;
853 if (pfn_cnt % HA_CHUNK)
854 region_size += HA_CHUNK;
855
856 region_start = (pg_start / HA_CHUNK) * HA_CHUNK;
857
858 rg_start = region_start;
859 rg_sz = region_size;
860 }
861
862 if (do_hot_add)
863 resp.page_count = process_hot_add(pg_start, pfn_cnt,
864 rg_start, rg_sz);
865#endif
866 /*
867 * The result field of the response structure has the
868 * following semantics:
869 *
870 * 1. If all or some pages hot-added: Guest should return success.
871 *
872 * 2. If no pages could be hot-added:
873 *
874 * If the guest returns success, then the host
875 * will not attempt any further hot-add operations. This
876 * signifies a permanent failure.
877 *
878 * If the guest returns failure, then this failure will be
879 * treated as a transient failure and the host may retry the
880 * hot-add operation after some delay.
881 */
882 if (resp.page_count > 0)
883 resp.result = 1;
884 else if (!do_hot_add)
885 resp.result = 1;
886 else
887 resp.result = 0;
888
889 if (!do_hot_add || (resp.page_count == 0))
890 pr_info("Memory hot add failed\n");
501 891
502 dm->state = DM_INITIALIZED; 892 dm->state = DM_INITIALIZED;
503 vmbus_sendpacket(dm->dev->channel, &resp, 893 vmbus_sendpacket(dm->dev->channel, &resp,
504 sizeof(struct dm_hot_add_response), 894 sizeof(struct dm_hot_add_response),
505 (unsigned long)NULL, 895 (unsigned long)NULL,
506 VM_PKT_DATA_INBAND, 0); 896 VM_PKT_DATA_INBAND, 0);
507
508} 897}
509 898
510static void process_info(struct hv_dynmem_device *dm, struct dm_info_msg *msg) 899static void process_info(struct hv_dynmem_device *dm, struct dm_info_msg *msg)
@@ -523,7 +912,7 @@ static void process_info(struct hv_dynmem_device *dm, struct dm_info_msg *msg)
523 } 912 }
524} 913}
525 914
526unsigned long compute_balloon_floor(void) 915static unsigned long compute_balloon_floor(void)
527{ 916{
528 unsigned long min_pages; 917 unsigned long min_pages;
529#define MB2PAGES(mb) ((mb) << (20 - PAGE_SHIFT)) 918#define MB2PAGES(mb) ((mb) << (20 - PAGE_SHIFT))
@@ -644,6 +1033,14 @@ static int alloc_balloon_pages(struct hv_dynmem_device *dm, int num_pages,
644 1033
645 dm->num_pages_ballooned += alloc_unit; 1034 dm->num_pages_ballooned += alloc_unit;
646 1035
1036 /*
1037 * If we allocatted 2M pages; split them so we
1038 * can free them in any order we get.
1039 */
1040
1041 if (alloc_unit != 1)
1042 split_page(pg, get_order(alloc_unit << PAGE_SHIFT));
1043
647 bl_resp->range_count++; 1044 bl_resp->range_count++;
648 bl_resp->range_array[i].finfo.start_page = 1045 bl_resp->range_array[i].finfo.start_page =
649 page_to_pfn(pg); 1046 page_to_pfn(pg);
@@ -657,9 +1054,9 @@ static int alloc_balloon_pages(struct hv_dynmem_device *dm, int num_pages,
657 1054
658 1055
659 1056
660static void balloon_up(struct hv_dynmem_device *dm, struct dm_balloon *req) 1057static void balloon_up(struct work_struct *dummy)
661{ 1058{
662 int num_pages = req->num_pages; 1059 int num_pages = dm_device.balloon_wrk.num_pages;
663 int num_ballooned = 0; 1060 int num_ballooned = 0;
664 struct dm_balloon_response *bl_resp; 1061 struct dm_balloon_response *bl_resp;
665 int alloc_unit; 1062 int alloc_unit;
@@ -670,9 +1067,10 @@ static void balloon_up(struct hv_dynmem_device *dm, struct dm_balloon *req)
670 1067
671 1068
672 /* 1069 /*
673 * Currently, we only support 4k allocations. 1070 * We will attempt 2M allocations. However, if we fail to
1071 * allocate 2M chunks, we will go back to 4k allocations.
674 */ 1072 */
675 alloc_unit = 1; 1073 alloc_unit = 512;
676 1074
677 while (!done) { 1075 while (!done) {
678 bl_resp = (struct dm_balloon_response *)send_buffer; 1076 bl_resp = (struct dm_balloon_response *)send_buffer;
@@ -684,14 +1082,19 @@ static void balloon_up(struct hv_dynmem_device *dm, struct dm_balloon *req)
684 1082
685 1083
686 num_pages -= num_ballooned; 1084 num_pages -= num_ballooned;
687 num_ballooned = alloc_balloon_pages(dm, num_pages, 1085 num_ballooned = alloc_balloon_pages(&dm_device, num_pages,
688 bl_resp, alloc_unit, 1086 bl_resp, alloc_unit,
689 &alloc_error); 1087 &alloc_error);
690 1088
1089 if ((alloc_error) && (alloc_unit != 1)) {
1090 alloc_unit = 1;
1091 continue;
1092 }
1093
691 if ((alloc_error) || (num_ballooned == num_pages)) { 1094 if ((alloc_error) || (num_ballooned == num_pages)) {
692 bl_resp->more_pages = 0; 1095 bl_resp->more_pages = 0;
693 done = true; 1096 done = true;
694 dm->state = DM_INITIALIZED; 1097 dm_device.state = DM_INITIALIZED;
695 } 1098 }
696 1099
697 /* 1100 /*
@@ -719,7 +1122,7 @@ static void balloon_up(struct hv_dynmem_device *dm, struct dm_balloon *req)
719 pr_info("Balloon response failed\n"); 1122 pr_info("Balloon response failed\n");
720 1123
721 for (i = 0; i < bl_resp->range_count; i++) 1124 for (i = 0; i < bl_resp->range_count; i++)
722 free_balloon_pages(dm, 1125 free_balloon_pages(&dm_device,
723 &bl_resp->range_array[i]); 1126 &bl_resp->range_array[i]);
724 1127
725 done = true; 1128 done = true;
@@ -761,7 +1164,6 @@ static int dm_thread_func(void *dm_dev)
761{ 1164{
762 struct hv_dynmem_device *dm = dm_dev; 1165 struct hv_dynmem_device *dm = dm_dev;
763 int t; 1166 int t;
764 unsigned long scan_start;
765 1167
766 while (!kthread_should_stop()) { 1168 while (!kthread_should_stop()) {
767 t = wait_for_completion_timeout(&dm_device.config_event, 1*HZ); 1169 t = wait_for_completion_timeout(&dm_device.config_event, 1*HZ);
@@ -773,22 +1175,6 @@ static int dm_thread_func(void *dm_dev)
773 if (t == 0) 1175 if (t == 0)
774 post_status(dm); 1176 post_status(dm);
775 1177
776 scan_start = jiffies;
777 switch (dm->state) {
778 case DM_BALLOON_UP:
779 balloon_up(dm, (struct dm_balloon *)recv_buffer);
780 break;
781
782 case DM_HOT_ADD:
783 hot_add_req(dm, (struct dm_hot_add *)recv_buffer);
784 break;
785 default:
786 break;
787 }
788
789 if (!time_in_range(jiffies, scan_start, scan_start + HZ))
790 post_status(dm);
791
792 } 1178 }
793 1179
794 return 0; 1180 return 0;
@@ -861,6 +1247,10 @@ static void balloon_onchannelcallback(void *context)
861 struct dm_message *dm_msg; 1247 struct dm_message *dm_msg;
862 struct dm_header *dm_hdr; 1248 struct dm_header *dm_hdr;
863 struct hv_dynmem_device *dm = hv_get_drvdata(dev); 1249 struct hv_dynmem_device *dm = hv_get_drvdata(dev);
1250 struct dm_balloon *bal_msg;
1251 struct dm_hot_add *ha_msg;
1252 union dm_mem_page_range *ha_pg_range;
1253 union dm_mem_page_range *ha_region;
864 1254
865 memset(recv_buffer, 0, sizeof(recv_buffer)); 1255 memset(recv_buffer, 0, sizeof(recv_buffer));
866 vmbus_recvpacket(dev->channel, recv_buffer, 1256 vmbus_recvpacket(dev->channel, recv_buffer,
@@ -882,8 +1272,12 @@ static void balloon_onchannelcallback(void *context)
882 break; 1272 break;
883 1273
884 case DM_BALLOON_REQUEST: 1274 case DM_BALLOON_REQUEST:
1275 if (dm->state == DM_BALLOON_UP)
1276 pr_warn("Currently ballooning\n");
1277 bal_msg = (struct dm_balloon *)recv_buffer;
885 dm->state = DM_BALLOON_UP; 1278 dm->state = DM_BALLOON_UP;
886 complete(&dm->config_event); 1279 dm_device.balloon_wrk.num_pages = bal_msg->num_pages;
1280 schedule_work(&dm_device.balloon_wrk.wrk);
887 break; 1281 break;
888 1282
889 case DM_UNBALLOON_REQUEST: 1283 case DM_UNBALLOON_REQUEST:
@@ -893,8 +1287,31 @@ static void balloon_onchannelcallback(void *context)
893 break; 1287 break;
894 1288
895 case DM_MEM_HOT_ADD_REQUEST: 1289 case DM_MEM_HOT_ADD_REQUEST:
1290 if (dm->state == DM_HOT_ADD)
1291 pr_warn("Currently hot-adding\n");
896 dm->state = DM_HOT_ADD; 1292 dm->state = DM_HOT_ADD;
897 complete(&dm->config_event); 1293 ha_msg = (struct dm_hot_add *)recv_buffer;
1294 if (ha_msg->hdr.size == sizeof(struct dm_hot_add)) {
1295 /*
1296 * This is a normal hot-add request specifying
1297 * hot-add memory.
1298 */
1299 ha_pg_range = &ha_msg->range;
1300 dm->ha_wrk.ha_page_range = *ha_pg_range;
1301 dm->ha_wrk.ha_region_range.page_range = 0;
1302 } else {
1303 /*
1304 * Host is specifying that we first hot-add
1305 * a region and then partially populate this
1306 * region.
1307 */
1308 dm->host_specified_ha_region = true;
1309 ha_pg_range = &ha_msg->range;
1310 ha_region = &ha_pg_range[1];
1311 dm->ha_wrk.ha_page_range = *ha_pg_range;
1312 dm->ha_wrk.ha_region_range = *ha_region;
1313 }
1314 schedule_work(&dm_device.ha_wrk.wrk);
898 break; 1315 break;
899 1316
900 case DM_INFO_MESSAGE: 1317 case DM_INFO_MESSAGE:
@@ -937,6 +1354,10 @@ static int balloon_probe(struct hv_device *dev,
937 dm_device.next_version = DYNMEM_PROTOCOL_VERSION_WIN7; 1354 dm_device.next_version = DYNMEM_PROTOCOL_VERSION_WIN7;
938 init_completion(&dm_device.host_event); 1355 init_completion(&dm_device.host_event);
939 init_completion(&dm_device.config_event); 1356 init_completion(&dm_device.config_event);
1357 INIT_LIST_HEAD(&dm_device.ha_region_list);
1358 INIT_WORK(&dm_device.balloon_wrk.wrk, balloon_up);
1359 INIT_WORK(&dm_device.ha_wrk.wrk, hot_add_req);
1360 dm_device.host_specified_ha_region = false;
940 1361
941 dm_device.thread = 1362 dm_device.thread =
942 kthread_run(dm_thread_func, &dm_device, "hv_balloon"); 1363 kthread_run(dm_thread_func, &dm_device, "hv_balloon");
@@ -945,6 +1366,10 @@ static int balloon_probe(struct hv_device *dev,
945 goto probe_error1; 1366 goto probe_error1;
946 } 1367 }
947 1368
1369#ifdef CONFIG_MEMORY_HOTPLUG
1370 set_online_page_callback(&hv_online_page);
1371#endif
1372
948 hv_set_drvdata(dev, &dm_device); 1373 hv_set_drvdata(dev, &dm_device);
949 /* 1374 /*
950 * Initiate the hand shake with the host and negotiate 1375 * Initiate the hand shake with the host and negotiate
@@ -962,8 +1387,7 @@ static int balloon_probe(struct hv_device *dev,
962 ret = vmbus_sendpacket(dev->channel, &version_req, 1387 ret = vmbus_sendpacket(dev->channel, &version_req,
963 sizeof(struct dm_version_request), 1388 sizeof(struct dm_version_request),
964 (unsigned long)NULL, 1389 (unsigned long)NULL,
965 VM_PKT_DATA_INBAND, 1390 VM_PKT_DATA_INBAND, 0);
966 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
967 if (ret) 1391 if (ret)
968 goto probe_error2; 1392 goto probe_error2;
969 1393
@@ -990,13 +1414,13 @@ static int balloon_probe(struct hv_device *dev,
990 cap_msg.hdr.trans_id = atomic_inc_return(&trans_id); 1414 cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
991 1415
992 cap_msg.caps.cap_bits.balloon = 1; 1416 cap_msg.caps.cap_bits.balloon = 1;
1417 cap_msg.caps.cap_bits.hot_add = 1;
1418
993 /* 1419 /*
994 * While we currently don't support hot-add, 1420 * Specify our alignment requirements as it relates
995 * we still advertise this capability since the 1421 * memory hot-add. Specify 128MB alignment.
996 * host requires that guests partcipating in the
997 * dynamic memory protocol support hot add.
998 */ 1422 */
999 cap_msg.caps.cap_bits.hot_add = 1; 1423 cap_msg.caps.cap_bits.hot_add_alignment = 7;
1000 1424
1001 /* 1425 /*
1002 * Currently the host does not use these 1426 * Currently the host does not use these
@@ -1009,8 +1433,7 @@ static int balloon_probe(struct hv_device *dev,
1009 ret = vmbus_sendpacket(dev->channel, &cap_msg, 1433 ret = vmbus_sendpacket(dev->channel, &cap_msg,
1010 sizeof(struct dm_capabilities), 1434 sizeof(struct dm_capabilities),
1011 (unsigned long)NULL, 1435 (unsigned long)NULL,
1012 VM_PKT_DATA_INBAND, 1436 VM_PKT_DATA_INBAND, 0);
1013 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
1014 if (ret) 1437 if (ret)
1015 goto probe_error2; 1438 goto probe_error2;
1016 1439
@@ -1034,6 +1457,9 @@ static int balloon_probe(struct hv_device *dev,
1034 return 0; 1457 return 0;
1035 1458
1036probe_error2: 1459probe_error2:
1460#ifdef CONFIG_MEMORY_HOTPLUG
1461 restore_online_page_callback(&hv_online_page);
1462#endif
1037 kthread_stop(dm_device.thread); 1463 kthread_stop(dm_device.thread);
1038 1464
1039probe_error1: 1465probe_error1:
@@ -1046,13 +1472,26 @@ probe_error0:
1046static int balloon_remove(struct hv_device *dev) 1472static int balloon_remove(struct hv_device *dev)
1047{ 1473{
1048 struct hv_dynmem_device *dm = hv_get_drvdata(dev); 1474 struct hv_dynmem_device *dm = hv_get_drvdata(dev);
1475 struct list_head *cur, *tmp;
1476 struct hv_hotadd_state *has;
1049 1477
1050 if (dm->num_pages_ballooned != 0) 1478 if (dm->num_pages_ballooned != 0)
1051 pr_warn("Ballooned pages: %d\n", dm->num_pages_ballooned); 1479 pr_warn("Ballooned pages: %d\n", dm->num_pages_ballooned);
1052 1480
1481 cancel_work_sync(&dm->balloon_wrk.wrk);
1482 cancel_work_sync(&dm->ha_wrk.wrk);
1483
1053 vmbus_close(dev->channel); 1484 vmbus_close(dev->channel);
1054 kthread_stop(dm->thread); 1485 kthread_stop(dm->thread);
1055 kfree(send_buffer); 1486 kfree(send_buffer);
1487#ifdef CONFIG_MEMORY_HOTPLUG
1488 restore_online_page_callback(&hv_online_page);
1489#endif
1490 list_for_each_safe(cur, tmp, &dm->ha_region_list) {
1491 has = list_entry(cur, struct hv_hotadd_state, list);
1492 list_del(&has->list);
1493 kfree(has);
1494 }
1056 1495
1057 return 0; 1496 return 0;
1058} 1497}
@@ -1079,14 +1518,7 @@ static int __init init_balloon_drv(void)
1079 return vmbus_driver_register(&balloon_drv); 1518 return vmbus_driver_register(&balloon_drv);
1080} 1519}
1081 1520
1082static void exit_balloon_drv(void)
1083{
1084
1085 vmbus_driver_unregister(&balloon_drv);
1086}
1087
1088module_init(init_balloon_drv); 1521module_init(init_balloon_drv);
1089module_exit(exit_balloon_drv);
1090 1522
1091MODULE_DESCRIPTION("Hyper-V Balloon"); 1523MODULE_DESCRIPTION("Hyper-V Balloon");
1092MODULE_VERSION(HV_DRV_VERSION); 1524MODULE_VERSION(HV_DRV_VERSION);
diff --git a/drivers/hv/hv_snapshot.c b/drivers/hv/hv_snapshot.c
new file mode 100644
index 000000000000..8ad5653ce447
--- /dev/null
+++ b/drivers/hv/hv_snapshot.c
@@ -0,0 +1,287 @@
1/*
2 * An implementation of host initiated guest snapshot.
3 *
4 *
5 * Copyright (C) 2013, Microsoft, Inc.
6 * Author : K. Y. Srinivasan <kys@microsoft.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published
10 * by the Free Software Foundation.
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, GOOD TITLE or
15 * NON INFRINGEMENT. See the GNU General Public License for more
16 * details.
17 *
18 */
19#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20
21#include <linux/net.h>
22#include <linux/nls.h>
23#include <linux/connector.h>
24#include <linux/workqueue.h>
25#include <linux/hyperv.h>
26
27
28
29/*
30 * Global state maintained for transaction that is being processed.
31 * Note that only one transaction can be active at any point in time.
32 *
33 * This state is set when we receive a request from the host; we
34 * cleanup this state when the transaction is completed - when we respond
35 * to the host with the key value.
36 */
37
38static struct {
39 bool active; /* transaction status - active or not */
40 int recv_len; /* number of bytes received. */
41 struct vmbus_channel *recv_channel; /* chn we got the request */
42 u64 recv_req_id; /* request ID. */
43 struct hv_vss_msg *msg; /* current message */
44} vss_transaction;
45
46
47static void vss_respond_to_host(int error);
48
49static struct cb_id vss_id = { CN_VSS_IDX, CN_VSS_VAL };
50static const char vss_name[] = "vss_kernel_module";
51static __u8 *recv_buffer;
52
53static void vss_send_op(struct work_struct *dummy);
54static DECLARE_WORK(vss_send_op_work, vss_send_op);
55
56/*
57 * Callback when data is received from user mode.
58 */
59
60static void
61vss_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp)
62{
63 struct hv_vss_msg *vss_msg;
64
65 vss_msg = (struct hv_vss_msg *)msg->data;
66
67 if (vss_msg->vss_hdr.operation == VSS_OP_REGISTER) {
68 pr_info("VSS daemon registered\n");
69 vss_transaction.active = false;
70 if (vss_transaction.recv_channel != NULL)
71 hv_vss_onchannelcallback(vss_transaction.recv_channel);
72 return;
73
74 }
75 vss_respond_to_host(vss_msg->error);
76}
77
78
79static void vss_send_op(struct work_struct *dummy)
80{
81 int op = vss_transaction.msg->vss_hdr.operation;
82 struct cn_msg *msg;
83 struct hv_vss_msg *vss_msg;
84
85 msg = kzalloc(sizeof(*msg) + sizeof(*vss_msg), GFP_ATOMIC);
86 if (!msg)
87 return;
88
89 vss_msg = (struct hv_vss_msg *)msg->data;
90
91 msg->id.idx = CN_VSS_IDX;
92 msg->id.val = CN_VSS_VAL;
93
94 vss_msg->vss_hdr.operation = op;
95 msg->len = sizeof(struct hv_vss_msg);
96
97 cn_netlink_send(msg, 0, GFP_ATOMIC);
98 kfree(msg);
99
100 return;
101}
102
103/*
104 * Send a response back to the host.
105 */
106
107static void
108vss_respond_to_host(int error)
109{
110 struct icmsg_hdr *icmsghdrp;
111 u32 buf_len;
112 struct vmbus_channel *channel;
113 u64 req_id;
114
115 /*
116 * If a transaction is not active; log and return.
117 */
118
119 if (!vss_transaction.active) {
120 /*
121 * This is a spurious call!
122 */
123 pr_warn("VSS: Transaction not active\n");
124 return;
125 }
126 /*
127 * Copy the global state for completing the transaction. Note that
128 * only one transaction can be active at a time.
129 */
130
131 buf_len = vss_transaction.recv_len;
132 channel = vss_transaction.recv_channel;
133 req_id = vss_transaction.recv_req_id;
134 vss_transaction.active = false;
135
136 icmsghdrp = (struct icmsg_hdr *)
137 &recv_buffer[sizeof(struct vmbuspipe_hdr)];
138
139 if (channel->onchannel_callback == NULL)
140 /*
141 * We have raced with util driver being unloaded;
142 * silently return.
143 */
144 return;
145
146 icmsghdrp->status = error;
147
148 icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION | ICMSGHDRFLAG_RESPONSE;
149
150 vmbus_sendpacket(channel, recv_buffer, buf_len, req_id,
151 VM_PKT_DATA_INBAND, 0);
152
153}
154
155/*
156 * This callback is invoked when we get a VSS message from the host.
157 * The host ensures that only one VSS transaction can be active at a time.
158 */
159
160void hv_vss_onchannelcallback(void *context)
161{
162 struct vmbus_channel *channel = context;
163 u32 recvlen;
164 u64 requestid;
165 struct hv_vss_msg *vss_msg;
166
167
168 struct icmsg_hdr *icmsghdrp;
169 struct icmsg_negotiate *negop = NULL;
170
171 if (vss_transaction.active) {
172 /*
173 * We will defer processing this callback once
174 * the current transaction is complete.
175 */
176 vss_transaction.recv_channel = channel;
177 return;
178 }
179
180 vmbus_recvpacket(channel, recv_buffer, PAGE_SIZE * 2, &recvlen,
181 &requestid);
182
183 if (recvlen > 0) {
184 icmsghdrp = (struct icmsg_hdr *)&recv_buffer[
185 sizeof(struct vmbuspipe_hdr)];
186
187 if (icmsghdrp->icmsgtype == ICMSGTYPE_NEGOTIATE) {
188 vmbus_prep_negotiate_resp(icmsghdrp, negop,
189 recv_buffer, MAX_SRV_VER, MAX_SRV_VER);
190 /*
191 * We currently negotiate the highest number the
192 * host has presented. If this version is not
193 * atleast 5.0, reject.
194 */
195 negop = (struct icmsg_negotiate *)&recv_buffer[
196 sizeof(struct vmbuspipe_hdr) +
197 sizeof(struct icmsg_hdr)];
198
199 if (negop->icversion_data[1].major < 5)
200 negop->icframe_vercnt = 0;
201 } else {
202 vss_msg = (struct hv_vss_msg *)&recv_buffer[
203 sizeof(struct vmbuspipe_hdr) +
204 sizeof(struct icmsg_hdr)];
205
206 /*
207 * Stash away this global state for completing the
208 * transaction; note transactions are serialized.
209 */
210
211 vss_transaction.recv_len = recvlen;
212 vss_transaction.recv_channel = channel;
213 vss_transaction.recv_req_id = requestid;
214 vss_transaction.active = true;
215 vss_transaction.msg = (struct hv_vss_msg *)vss_msg;
216
217 switch (vss_msg->vss_hdr.operation) {
218 /*
219 * Initiate a "freeze/thaw"
220 * operation in the guest.
221 * We respond to the host once
222 * the operation is complete.
223 *
224 * We send the message to the
225 * user space daemon and the
226 * operation is performed in
227 * the daemon.
228 */
229 case VSS_OP_FREEZE:
230 case VSS_OP_THAW:
231 schedule_work(&vss_send_op_work);
232 return;
233
234 case VSS_OP_HOT_BACKUP:
235 vss_msg->vss_cf.flags =
236 VSS_HBU_NO_AUTO_RECOVERY;
237 vss_respond_to_host(0);
238 return;
239
240 case VSS_OP_GET_DM_INFO:
241 vss_msg->dm_info.flags = 0;
242 vss_respond_to_host(0);
243 return;
244
245 default:
246 vss_respond_to_host(0);
247 return;
248
249 }
250
251 }
252
253 icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION
254 | ICMSGHDRFLAG_RESPONSE;
255
256 vmbus_sendpacket(channel, recv_buffer,
257 recvlen, requestid,
258 VM_PKT_DATA_INBAND, 0);
259 }
260
261}
262
263int
264hv_vss_init(struct hv_util_service *srv)
265{
266 int err;
267
268 err = cn_add_callback(&vss_id, vss_name, vss_cn_callback);
269 if (err)
270 return err;
271 recv_buffer = srv->recv_buffer;
272
273 /*
274 * When this driver loads, the user level daemon that
275 * processes the host requests may not yet be running.
276 * Defer processing channel callbacks until the daemon
277 * has registered.
278 */
279 vss_transaction.active = true;
280 return 0;
281}
282
283void hv_vss_deinit(void)
284{
285 cn_del_callback(&vss_id);
286 cancel_work_sync(&vss_send_op_work);
287}
diff --git a/drivers/hv/hv_util.c b/drivers/hv/hv_util.c
index 1d4cbd8e8261..2f561c5dfe24 100644
--- a/drivers/hv/hv_util.c
+++ b/drivers/hv/hv_util.c
@@ -49,6 +49,12 @@ static struct hv_util_service util_kvp = {
49 .util_deinit = hv_kvp_deinit, 49 .util_deinit = hv_kvp_deinit,
50}; 50};
51 51
52static struct hv_util_service util_vss = {
53 .util_cb = hv_vss_onchannelcallback,
54 .util_init = hv_vss_init,
55 .util_deinit = hv_vss_deinit,
56};
57
52static void perform_shutdown(struct work_struct *dummy) 58static void perform_shutdown(struct work_struct *dummy)
53{ 59{
54 orderly_poweroff(true); 60 orderly_poweroff(true);
@@ -339,6 +345,10 @@ static const struct hv_vmbus_device_id id_table[] = {
339 { HV_KVP_GUID, 345 { HV_KVP_GUID,
340 .driver_data = (unsigned long)&util_kvp 346 .driver_data = (unsigned long)&util_kvp
341 }, 347 },
348 /* VSS GUID */
349 { HV_VSS_GUID,
350 .driver_data = (unsigned long)&util_vss
351 },
342 { }, 352 { },
343}; 353};
344 354
diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c
index cafa72ffdc30..d6fbb5772b8d 100644
--- a/drivers/hv/ring_buffer.c
+++ b/drivers/hv/ring_buffer.c
@@ -71,6 +71,7 @@ u32 hv_end_read(struct hv_ring_buffer_info *rbi)
71 71
72static bool hv_need_to_signal(u32 old_write, struct hv_ring_buffer_info *rbi) 72static bool hv_need_to_signal(u32 old_write, struct hv_ring_buffer_info *rbi)
73{ 73{
74 smp_mb();
74 if (rbi->ring_buffer->interrupt_mask) 75 if (rbi->ring_buffer->interrupt_mask)
75 return false; 76 return false;
76 77
diff --git a/drivers/ipack/carriers/tpci200.c b/drivers/ipack/carriers/tpci200.c
index 0246b1fddffe..c276fde318e5 100644
--- a/drivers/ipack/carriers/tpci200.c
+++ b/drivers/ipack/carriers/tpci200.c
@@ -480,6 +480,7 @@ static void tpci200_release_device(struct ipack_device *dev)
480 480
481static int tpci200_create_device(struct tpci200_board *tpci200, int i) 481static int tpci200_create_device(struct tpci200_board *tpci200, int i)
482{ 482{
483 int ret;
483 enum ipack_space space; 484 enum ipack_space space;
484 struct ipack_device *dev = 485 struct ipack_device *dev =
485 kzalloc(sizeof(struct ipack_device), GFP_KERNEL); 486 kzalloc(sizeof(struct ipack_device), GFP_KERNEL);
@@ -495,7 +496,18 @@ static int tpci200_create_device(struct tpci200_board *tpci200, int i)
495 + tpci200_space_interval[space] * i; 496 + tpci200_space_interval[space] * i;
496 dev->region[space].size = tpci200_space_size[space]; 497 dev->region[space].size = tpci200_space_size[space];
497 } 498 }
498 return ipack_device_register(dev); 499
500 ret = ipack_device_init(dev);
501 if (ret < 0) {
502 ipack_put_device(dev);
503 return ret;
504 }
505
506 ret = ipack_device_add(dev);
507 if (ret < 0)
508 ipack_put_device(dev);
509
510 return ret;
499} 511}
500 512
501static int tpci200_pci_probe(struct pci_dev *pdev, 513static int tpci200_pci_probe(struct pci_dev *pdev,
diff --git a/drivers/ipack/ipack.c b/drivers/ipack/ipack.c
index 7ec6b208b1cb..6e066c53acce 100644
--- a/drivers/ipack/ipack.c
+++ b/drivers/ipack/ipack.c
@@ -227,7 +227,7 @@ static int ipack_unregister_bus_member(struct device *dev, void *data)
227 struct ipack_bus_device *bus = data; 227 struct ipack_bus_device *bus = data;
228 228
229 if (idev->bus == bus) 229 if (idev->bus == bus)
230 ipack_device_unregister(idev); 230 ipack_device_del(idev);
231 231
232 return 1; 232 return 1;
233} 233}
@@ -419,7 +419,7 @@ out:
419 return ret; 419 return ret;
420} 420}
421 421
422int ipack_device_register(struct ipack_device *dev) 422int ipack_device_init(struct ipack_device *dev)
423{ 423{
424 int ret; 424 int ret;
425 425
@@ -428,6 +428,7 @@ int ipack_device_register(struct ipack_device *dev)
428 dev->dev.parent = dev->bus->parent; 428 dev->dev.parent = dev->bus->parent;
429 dev_set_name(&dev->dev, 429 dev_set_name(&dev->dev,
430 "ipack-dev.%u.%u", dev->bus->bus_nr, dev->slot); 430 "ipack-dev.%u.%u", dev->bus->bus_nr, dev->slot);
431 device_initialize(&dev->dev);
431 432
432 if (dev->bus->ops->set_clockrate(dev, 8)) 433 if (dev->bus->ops->set_clockrate(dev, 8))
433 dev_warn(&dev->dev, "failed to switch to 8 MHz operation for reading of device ID.\n"); 434 dev_warn(&dev->dev, "failed to switch to 8 MHz operation for reading of device ID.\n");
@@ -447,19 +448,34 @@ int ipack_device_register(struct ipack_device *dev)
447 dev_err(&dev->dev, "failed to switch to 32 MHz operation.\n"); 448 dev_err(&dev->dev, "failed to switch to 32 MHz operation.\n");
448 } 449 }
449 450
450 ret = device_register(&dev->dev); 451 return 0;
451 if (ret < 0) 452}
452 kfree(dev->id); 453EXPORT_SYMBOL_GPL(ipack_device_init);
453 454
454 return ret; 455int ipack_device_add(struct ipack_device *dev)
456{
457 return device_add(&dev->dev);
458}
459EXPORT_SYMBOL_GPL(ipack_device_add);
460
461void ipack_device_del(struct ipack_device *dev)
462{
463 device_del(&dev->dev);
464 ipack_put_device(dev);
465}
466EXPORT_SYMBOL_GPL(ipack_device_del);
467
468void ipack_get_device(struct ipack_device *dev)
469{
470 get_device(&dev->dev);
455} 471}
456EXPORT_SYMBOL_GPL(ipack_device_register); 472EXPORT_SYMBOL_GPL(ipack_get_device);
457 473
458void ipack_device_unregister(struct ipack_device *dev) 474void ipack_put_device(struct ipack_device *dev)
459{ 475{
460 device_unregister(&dev->dev); 476 put_device(&dev->dev);
461} 477}
462EXPORT_SYMBOL_GPL(ipack_device_unregister); 478EXPORT_SYMBOL_GPL(ipack_put_device);
463 479
464static int __init ipack_init(void) 480static int __init ipack_init(void)
465{ 481{
diff --git a/drivers/isdn/hardware/avm/avm_cs.c b/drivers/isdn/hardware/avm/avm_cs.c
index c21353d8e915..62b8030ee331 100644
--- a/drivers/isdn/hardware/avm/avm_cs.c
+++ b/drivers/isdn/hardware/avm/avm_cs.c
@@ -163,16 +163,4 @@ static struct pcmcia_driver avmcs_driver = {
163 .remove = avmcs_detach, 163 .remove = avmcs_detach,
164 .id_table = avmcs_ids, 164 .id_table = avmcs_ids,
165}; 165};
166 166module_pcmcia_driver(avmcs_driver);
167static int __init avmcs_init(void)
168{
169 return pcmcia_register_driver(&avmcs_driver);
170}
171
172static void __exit avmcs_exit(void)
173{
174 pcmcia_unregister_driver(&avmcs_driver);
175}
176
177module_init(avmcs_init);
178module_exit(avmcs_exit);
diff --git a/drivers/isdn/hisax/avma1_cs.c b/drivers/isdn/hisax/avma1_cs.c
index 4e676bcf8506..baad94ec1f4a 100644
--- a/drivers/isdn/hisax/avma1_cs.c
+++ b/drivers/isdn/hisax/avma1_cs.c
@@ -159,16 +159,4 @@ static struct pcmcia_driver avma1cs_driver = {
159 .remove = avma1cs_detach, 159 .remove = avma1cs_detach,
160 .id_table = avma1cs_ids, 160 .id_table = avma1cs_ids,
161}; 161};
162 162module_pcmcia_driver(avma1cs_driver);
163static int __init init_avma1_cs(void)
164{
165 return pcmcia_register_driver(&avma1cs_driver);
166}
167
168static void __exit exit_avma1_cs(void)
169{
170 pcmcia_unregister_driver(&avma1cs_driver);
171}
172
173module_init(init_avma1_cs);
174module_exit(exit_avma1_cs);
diff --git a/drivers/isdn/hisax/elsa_cs.c b/drivers/isdn/hisax/elsa_cs.c
index ebe56918f6fc..40f6fad79de3 100644
--- a/drivers/isdn/hisax/elsa_cs.c
+++ b/drivers/isdn/hisax/elsa_cs.c
@@ -215,16 +215,4 @@ static struct pcmcia_driver elsa_cs_driver = {
215 .suspend = elsa_suspend, 215 .suspend = elsa_suspend,
216 .resume = elsa_resume, 216 .resume = elsa_resume,
217}; 217};
218 218module_pcmcia_driver(elsa_cs_driver);
219static int __init init_elsa_cs(void)
220{
221 return pcmcia_register_driver(&elsa_cs_driver);
222}
223
224static void __exit exit_elsa_cs(void)
225{
226 pcmcia_unregister_driver(&elsa_cs_driver);
227}
228
229module_init(init_elsa_cs);
230module_exit(exit_elsa_cs);
diff --git a/drivers/isdn/hisax/sedlbauer_cs.c b/drivers/isdn/hisax/sedlbauer_cs.c
index 90f81291641b..92ef62d4caf4 100644
--- a/drivers/isdn/hisax/sedlbauer_cs.c
+++ b/drivers/isdn/hisax/sedlbauer_cs.c
@@ -206,16 +206,4 @@ static struct pcmcia_driver sedlbauer_driver = {
206 .suspend = sedlbauer_suspend, 206 .suspend = sedlbauer_suspend,
207 .resume = sedlbauer_resume, 207 .resume = sedlbauer_resume,
208}; 208};
209 209module_pcmcia_driver(sedlbauer_driver);
210static int __init init_sedlbauer_cs(void)
211{
212 return pcmcia_register_driver(&sedlbauer_driver);
213}
214
215static void __exit exit_sedlbauer_cs(void)
216{
217 pcmcia_unregister_driver(&sedlbauer_driver);
218}
219
220module_init(init_sedlbauer_cs);
221module_exit(exit_sedlbauer_cs);
diff --git a/drivers/isdn/hisax/teles_cs.c b/drivers/isdn/hisax/teles_cs.c
index f2476ffb04fd..b8dd14958757 100644
--- a/drivers/isdn/hisax/teles_cs.c
+++ b/drivers/isdn/hisax/teles_cs.c
@@ -197,16 +197,4 @@ static struct pcmcia_driver teles_cs_driver = {
197 .suspend = teles_suspend, 197 .suspend = teles_suspend,
198 .resume = teles_resume, 198 .resume = teles_resume,
199}; 199};
200 200module_pcmcia_driver(teles_cs_driver);
201static int __init init_teles_cs(void)
202{
203 return pcmcia_register_driver(&teles_cs_driver);
204}
205
206static void __exit exit_teles_cs(void)
207{
208 pcmcia_unregister_driver(&teles_cs_driver);
209}
210
211module_init(init_teles_cs);
212module_exit(exit_teles_cs);
diff --git a/drivers/memory/emif.c b/drivers/memory/emif.c
index df0873694858..cadf1cc19aaf 100644
--- a/drivers/memory/emif.c
+++ b/drivers/memory/emif.c
@@ -25,6 +25,7 @@
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/list.h> 26#include <linux/list.h>
27#include <linux/spinlock.h> 27#include <linux/spinlock.h>
28#include <linux/pm.h>
28#include <memory/jedec_ddr.h> 29#include <memory/jedec_ddr.h>
29#include "emif.h" 30#include "emif.h"
30#include "of_memory.h" 31#include "of_memory.h"
@@ -256,6 +257,41 @@ static void set_lpmode(struct emif_data *emif, u8 lpmode)
256 u32 temp; 257 u32 temp;
257 void __iomem *base = emif->base; 258 void __iomem *base = emif->base;
258 259
260 /*
261 * Workaround for errata i743 - LPDDR2 Power-Down State is Not
262 * Efficient
263 *
264 * i743 DESCRIPTION:
265 * The EMIF supports power-down state for low power. The EMIF
266 * automatically puts the SDRAM into power-down after the memory is
267 * not accessed for a defined number of cycles and the
268 * EMIF_PWR_MGMT_CTRL[10:8] REG_LP_MODE bit field is set to 0x4.
269 * As the EMIF supports automatic output impedance calibration, a ZQ
270 * calibration long command is issued every time it exits active
271 * power-down and precharge power-down modes. The EMIF waits and
272 * blocks any other command during this calibration.
273 * The EMIF does not allow selective disabling of ZQ calibration upon
274 * exit of power-down mode. Due to very short periods of power-down
275 * cycles, ZQ calibration overhead creates bandwidth issues and
276 * increases overall system power consumption. On the other hand,
277 * issuing ZQ calibration long commands when exiting self-refresh is
278 * still required.
279 *
280 * WORKAROUND
281 * Because there is no power consumption benefit of the power-down due
282 * to the calibration and there is a performance risk, the guideline
283 * is to not allow power-down state and, therefore, to not have set
284 * the EMIF_PWR_MGMT_CTRL[10:8] REG_LP_MODE bit field to 0x4.
285 */
286 if ((emif->plat_data->ip_rev == EMIF_4D) &&
287 (EMIF_LP_MODE_PWR_DN == lpmode)) {
288 WARN_ONCE(1,
289 "REG_LP_MODE = LP_MODE_PWR_DN(4) is prohibited by"
290 "erratum i743 switch to LP_MODE_SELF_REFRESH(2)\n");
291 /* rollback LP_MODE to Self-refresh mode */
292 lpmode = EMIF_LP_MODE_SELF_REFRESH;
293 }
294
259 temp = readl(base + EMIF_POWER_MANAGEMENT_CONTROL); 295 temp = readl(base + EMIF_POWER_MANAGEMENT_CONTROL);
260 temp &= ~LP_MODE_MASK; 296 temp &= ~LP_MODE_MASK;
261 temp |= (lpmode << LP_MODE_SHIFT); 297 temp |= (lpmode << LP_MODE_SHIFT);
@@ -715,6 +751,8 @@ static u32 get_pwr_mgmt_ctrl(u32 freq, struct emif_data *emif, u32 ip_rev)
715 u32 timeout_perf = EMIF_LP_MODE_TIMEOUT_PERFORMANCE; 751 u32 timeout_perf = EMIF_LP_MODE_TIMEOUT_PERFORMANCE;
716 u32 timeout_pwr = EMIF_LP_MODE_TIMEOUT_POWER; 752 u32 timeout_pwr = EMIF_LP_MODE_TIMEOUT_POWER;
717 u32 freq_threshold = EMIF_LP_MODE_FREQ_THRESHOLD; 753 u32 freq_threshold = EMIF_LP_MODE_FREQ_THRESHOLD;
754 u32 mask;
755 u8 shift;
718 756
719 struct emif_custom_configs *cust_cfgs = emif->plat_data->custom_configs; 757 struct emif_custom_configs *cust_cfgs = emif->plat_data->custom_configs;
720 758
@@ -728,37 +766,59 @@ static u32 get_pwr_mgmt_ctrl(u32 freq, struct emif_data *emif, u32 ip_rev)
728 /* Timeout based on DDR frequency */ 766 /* Timeout based on DDR frequency */
729 timeout = freq >= freq_threshold ? timeout_perf : timeout_pwr; 767 timeout = freq >= freq_threshold ? timeout_perf : timeout_pwr;
730 768
731 /* The value to be set in register is "log2(timeout) - 3" */ 769 /*
770 * The value to be set in register is "log2(timeout) - 3"
771 * if timeout < 16 load 0 in register
772 * if timeout is not a power of 2, round to next highest power of 2
773 */
732 if (timeout < 16) { 774 if (timeout < 16) {
733 timeout = 0; 775 timeout = 0;
734 } else { 776 } else {
735 timeout = __fls(timeout) - 3;
736 if (timeout & (timeout - 1)) 777 if (timeout & (timeout - 1))
737 timeout++; 778 timeout <<= 1;
779 timeout = __fls(timeout) - 3;
738 } 780 }
739 781
740 switch (lpmode) { 782 switch (lpmode) {
741 case EMIF_LP_MODE_CLOCK_STOP: 783 case EMIF_LP_MODE_CLOCK_STOP:
742 pwr_mgmt_ctrl = (timeout << CS_TIM_SHIFT) | 784 shift = CS_TIM_SHIFT;
743 SR_TIM_MASK | PD_TIM_MASK; 785 mask = CS_TIM_MASK;
744 break; 786 break;
745 case EMIF_LP_MODE_SELF_REFRESH: 787 case EMIF_LP_MODE_SELF_REFRESH:
746 /* Workaround for errata i735 */ 788 /* Workaround for errata i735 */
747 if (timeout < 6) 789 if (timeout < 6)
748 timeout = 6; 790 timeout = 6;
749 791
750 pwr_mgmt_ctrl = (timeout << SR_TIM_SHIFT) | 792 shift = SR_TIM_SHIFT;
751 CS_TIM_MASK | PD_TIM_MASK; 793 mask = SR_TIM_MASK;
752 break; 794 break;
753 case EMIF_LP_MODE_PWR_DN: 795 case EMIF_LP_MODE_PWR_DN:
754 pwr_mgmt_ctrl = (timeout << PD_TIM_SHIFT) | 796 shift = PD_TIM_SHIFT;
755 CS_TIM_MASK | SR_TIM_MASK; 797 mask = PD_TIM_MASK;
756 break; 798 break;
757 case EMIF_LP_MODE_DISABLE: 799 case EMIF_LP_MODE_DISABLE:
758 default: 800 default:
759 pwr_mgmt_ctrl = CS_TIM_MASK | 801 mask = 0;
760 PD_TIM_MASK | SR_TIM_MASK; 802 shift = 0;
803 break;
761 } 804 }
805 /* Round to maximum in case of overflow, BUT warn! */
806 if (lpmode != EMIF_LP_MODE_DISABLE && timeout > mask >> shift) {
807 pr_err("TIMEOUT Overflow - lpmode=%d perf=%d pwr=%d freq=%d\n",
808 lpmode,
809 timeout_perf,
810 timeout_pwr,
811 freq_threshold);
812 WARN(1, "timeout=0x%02x greater than 0x%02x. Using max\n",
813 timeout, mask >> shift);
814 timeout = mask >> shift;
815 }
816
817 /* Setup required timing */
818 pwr_mgmt_ctrl = (timeout << shift) & mask;
819 /* setup a default mask for rest of the modes */
820 pwr_mgmt_ctrl |= (SR_TIM_MASK | CS_TIM_MASK | PD_TIM_MASK) &
821 ~mask;
762 822
763 /* No CS_TIM in EMIF_4D5 */ 823 /* No CS_TIM in EMIF_4D5 */
764 if (ip_rev == EMIF_4D5) 824 if (ip_rev == EMIF_4D5)
@@ -815,6 +875,8 @@ static void setup_registers(struct emif_data *emif, struct emif_regs *regs)
815 875
816 writel(regs->sdram_tim2_shdw, base + EMIF_SDRAM_TIMING_2_SHDW); 876 writel(regs->sdram_tim2_shdw, base + EMIF_SDRAM_TIMING_2_SHDW);
817 writel(regs->phy_ctrl_1_shdw, base + EMIF_DDR_PHY_CTRL_1_SHDW); 877 writel(regs->phy_ctrl_1_shdw, base + EMIF_DDR_PHY_CTRL_1_SHDW);
878 writel(regs->pwr_mgmt_ctrl_shdw,
879 base + EMIF_POWER_MANAGEMENT_CTRL_SHDW);
818 880
819 /* Settings specific for EMIF4D5 */ 881 /* Settings specific for EMIF4D5 */
820 if (emif->plat_data->ip_rev != EMIF_4D5) 882 if (emif->plat_data->ip_rev != EMIF_4D5)
@@ -892,6 +954,7 @@ static irqreturn_t handle_temp_alert(void __iomem *base, struct emif_data *emif)
892{ 954{
893 u32 old_temp_level; 955 u32 old_temp_level;
894 irqreturn_t ret = IRQ_HANDLED; 956 irqreturn_t ret = IRQ_HANDLED;
957 struct emif_custom_configs *custom_configs;
895 958
896 spin_lock_irqsave(&emif_lock, irq_state); 959 spin_lock_irqsave(&emif_lock, irq_state);
897 old_temp_level = emif->temperature_level; 960 old_temp_level = emif->temperature_level;
@@ -904,6 +967,29 @@ static irqreturn_t handle_temp_alert(void __iomem *base, struct emif_data *emif)
904 goto out; 967 goto out;
905 } 968 }
906 969
970 custom_configs = emif->plat_data->custom_configs;
971
972 /*
973 * IF we detect higher than "nominal rating" from DDR sensor
974 * on an unsupported DDR part, shutdown system
975 */
976 if (custom_configs && !(custom_configs->mask &
977 EMIF_CUSTOM_CONFIG_EXTENDED_TEMP_PART)) {
978 if (emif->temperature_level >= SDRAM_TEMP_HIGH_DERATE_REFRESH) {
979 dev_err(emif->dev,
980 "%s:NOT Extended temperature capable memory."
981 "Converting MR4=0x%02x as shutdown event\n",
982 __func__, emif->temperature_level);
983 /*
984 * Temperature far too high - do kernel_power_off()
985 * from thread context
986 */
987 emif->temperature_level = SDRAM_TEMP_VERY_HIGH_SHUTDOWN;
988 ret = IRQ_WAKE_THREAD;
989 goto out;
990 }
991 }
992
907 if (emif->temperature_level < old_temp_level || 993 if (emif->temperature_level < old_temp_level ||
908 emif->temperature_level == SDRAM_TEMP_VERY_HIGH_SHUTDOWN) { 994 emif->temperature_level == SDRAM_TEMP_VERY_HIGH_SHUTDOWN) {
909 /* 995 /*
@@ -965,7 +1051,14 @@ static irqreturn_t emif_threaded_isr(int irq, void *dev_id)
965 1051
966 if (emif->temperature_level == SDRAM_TEMP_VERY_HIGH_SHUTDOWN) { 1052 if (emif->temperature_level == SDRAM_TEMP_VERY_HIGH_SHUTDOWN) {
967 dev_emerg(emif->dev, "SDRAM temperature exceeds operating limit.. Needs shut down!!!\n"); 1053 dev_emerg(emif->dev, "SDRAM temperature exceeds operating limit.. Needs shut down!!!\n");
968 kernel_power_off(); 1054
1055 /* If we have Power OFF ability, use it, else try restarting */
1056 if (pm_power_off) {
1057 kernel_power_off();
1058 } else {
1059 WARN(1, "FIXME: NO pm_power_off!!! trying restart\n");
1060 kernel_restart("SDRAM Over-temp Emergency restart");
1061 }
969 return IRQ_HANDLED; 1062 return IRQ_HANDLED;
970 } 1063 }
971 1064
@@ -1170,7 +1263,7 @@ static void __init_or_module of_get_custom_configs(struct device_node *np_emif,
1170{ 1263{
1171 struct emif_custom_configs *cust_cfgs = NULL; 1264 struct emif_custom_configs *cust_cfgs = NULL;
1172 int len; 1265 int len;
1173 const int *lpmode, *poll_intvl; 1266 const __be32 *lpmode, *poll_intvl;
1174 1267
1175 lpmode = of_get_property(np_emif, "low-power-mode", &len); 1268 lpmode = of_get_property(np_emif, "low-power-mode", &len);
1176 poll_intvl = of_get_property(np_emif, "temp-alert-poll-interval", &len); 1269 poll_intvl = of_get_property(np_emif, "temp-alert-poll-interval", &len);
@@ -1184,7 +1277,7 @@ static void __init_or_module of_get_custom_configs(struct device_node *np_emif,
1184 1277
1185 if (lpmode) { 1278 if (lpmode) {
1186 cust_cfgs->mask |= EMIF_CUSTOM_CONFIG_LPMODE; 1279 cust_cfgs->mask |= EMIF_CUSTOM_CONFIG_LPMODE;
1187 cust_cfgs->lpmode = *lpmode; 1280 cust_cfgs->lpmode = be32_to_cpup(lpmode);
1188 of_property_read_u32(np_emif, 1281 of_property_read_u32(np_emif,
1189 "low-power-mode-timeout-performance", 1282 "low-power-mode-timeout-performance",
1190 &cust_cfgs->lpmode_timeout_performance); 1283 &cust_cfgs->lpmode_timeout_performance);
@@ -1199,9 +1292,13 @@ static void __init_or_module of_get_custom_configs(struct device_node *np_emif,
1199 if (poll_intvl) { 1292 if (poll_intvl) {
1200 cust_cfgs->mask |= 1293 cust_cfgs->mask |=
1201 EMIF_CUSTOM_CONFIG_TEMP_ALERT_POLL_INTERVAL; 1294 EMIF_CUSTOM_CONFIG_TEMP_ALERT_POLL_INTERVAL;
1202 cust_cfgs->temp_alert_poll_interval_ms = *poll_intvl; 1295 cust_cfgs->temp_alert_poll_interval_ms =
1296 be32_to_cpup(poll_intvl);
1203 } 1297 }
1204 1298
1299 if (of_find_property(np_emif, "extended-temp-part", &len))
1300 cust_cfgs->mask |= EMIF_CUSTOM_CONFIG_EXTENDED_TEMP_PART;
1301
1205 if (!is_custom_config_valid(cust_cfgs, emif->dev)) { 1302 if (!is_custom_config_valid(cust_cfgs, emif->dev)) {
1206 devm_kfree(emif->dev, cust_cfgs); 1303 devm_kfree(emif->dev, cust_cfgs);
1207 return; 1304 return;
@@ -1407,7 +1504,7 @@ static struct emif_data *__init_or_module get_device_details(
1407 if (pd->timings) { 1504 if (pd->timings) {
1408 temp = devm_kzalloc(dev, size, GFP_KERNEL); 1505 temp = devm_kzalloc(dev, size, GFP_KERNEL);
1409 if (temp) { 1506 if (temp) {
1410 memcpy(temp, pd->timings, sizeof(*pd->timings)); 1507 memcpy(temp, pd->timings, size);
1411 pd->timings = temp; 1508 pd->timings = temp;
1412 } else { 1509 } else {
1413 dev_warn(dev, "%s:%d: allocation error\n", __func__, 1510 dev_warn(dev, "%s:%d: allocation error\n", __func__,
@@ -1841,18 +1938,8 @@ static struct platform_driver emif_driver = {
1841 }, 1938 },
1842}; 1939};
1843 1940
1844static int __init_or_module emif_register(void) 1941module_platform_driver_probe(emif_driver, emif_probe);
1845{
1846 return platform_driver_probe(&emif_driver, emif_probe);
1847}
1848
1849static void __exit emif_unregister(void)
1850{
1851 platform_driver_unregister(&emif_driver);
1852}
1853 1942
1854module_init(emif_register);
1855module_exit(emif_unregister);
1856MODULE_DESCRIPTION("TI EMIF SDRAM Controller Driver"); 1943MODULE_DESCRIPTION("TI EMIF SDRAM Controller Driver");
1857MODULE_LICENSE("GPL"); 1944MODULE_LICENSE("GPL");
1858MODULE_ALIAS("platform:emif"); 1945MODULE_ALIAS("platform:emif");
diff --git a/drivers/memory/tegra30-mc.c b/drivers/memory/tegra30-mc.c
index 0b975986777d..f4ae074badc3 100644
--- a/drivers/memory/tegra30-mc.c
+++ b/drivers/memory/tegra30-mc.c
@@ -268,6 +268,7 @@ static const u32 tegra30_mc_ctx[] = {
268 MC_INTMASK, 268 MC_INTMASK,
269}; 269};
270 270
271#ifdef CONFIG_PM
271static int tegra30_mc_suspend(struct device *dev) 272static int tegra30_mc_suspend(struct device *dev)
272{ 273{
273 int i; 274 int i;
@@ -291,6 +292,7 @@ static int tegra30_mc_resume(struct device *dev)
291 mc_readl(mc, MC_TIMING_CONTROL); 292 mc_readl(mc, MC_TIMING_CONTROL);
292 return 0; 293 return 0;
293} 294}
295#endif
294 296
295static UNIVERSAL_DEV_PM_OPS(tegra30_mc_pm, 297static UNIVERSAL_DEV_PM_OPS(tegra30_mc_pm,
296 tegra30_mc_suspend, 298 tegra30_mc_suspend,
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index c346941a2515..ca86581d02ce 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -991,7 +991,7 @@ config MFD_PM8XXX
991 991
992config MFD_PM8921_CORE 992config MFD_PM8921_CORE
993 tristate "Qualcomm PM8921 PMIC chip" 993 tristate "Qualcomm PM8921 PMIC chip"
994 depends on MSM_SSBI 994 depends on SSBI && BROKEN
995 select MFD_CORE 995 select MFD_CORE
996 select MFD_PM8XXX 996 select MFD_PM8XXX
997 help 997 help
diff --git a/drivers/mfd/pm8921-core.c b/drivers/mfd/pm8921-core.c
index d4b297cbd801..ecc137ffa8c3 100644
--- a/drivers/mfd/pm8921-core.c
+++ b/drivers/mfd/pm8921-core.c
@@ -17,7 +17,7 @@
17#include <linux/platform_device.h> 17#include <linux/platform_device.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/err.h> 19#include <linux/err.h>
20#include <linux/msm_ssbi.h> 20#include <linux/ssbi.h>
21#include <linux/mfd/core.h> 21#include <linux/mfd/core.h>
22#include <linux/mfd/pm8xxx/pm8921.h> 22#include <linux/mfd/pm8xxx/pm8921.h>
23#include <linux/mfd/pm8xxx/core.h> 23#include <linux/mfd/pm8xxx/core.h>
@@ -35,7 +35,7 @@ static int pm8921_readb(const struct device *dev, u16 addr, u8 *val)
35 const struct pm8xxx_drvdata *pm8921_drvdata = dev_get_drvdata(dev); 35 const struct pm8xxx_drvdata *pm8921_drvdata = dev_get_drvdata(dev);
36 const struct pm8921 *pmic = pm8921_drvdata->pm_chip_data; 36 const struct pm8921 *pmic = pm8921_drvdata->pm_chip_data;
37 37
38 return msm_ssbi_read(pmic->dev->parent, addr, val, 1); 38 return ssbi_read(pmic->dev->parent, addr, val, 1);
39} 39}
40 40
41static int pm8921_writeb(const struct device *dev, u16 addr, u8 val) 41static int pm8921_writeb(const struct device *dev, u16 addr, u8 val)
@@ -43,7 +43,7 @@ static int pm8921_writeb(const struct device *dev, u16 addr, u8 val)
43 const struct pm8xxx_drvdata *pm8921_drvdata = dev_get_drvdata(dev); 43 const struct pm8xxx_drvdata *pm8921_drvdata = dev_get_drvdata(dev);
44 const struct pm8921 *pmic = pm8921_drvdata->pm_chip_data; 44 const struct pm8921 *pmic = pm8921_drvdata->pm_chip_data;
45 45
46 return msm_ssbi_write(pmic->dev->parent, addr, &val, 1); 46 return ssbi_write(pmic->dev->parent, addr, &val, 1);
47} 47}
48 48
49static int pm8921_read_buf(const struct device *dev, u16 addr, u8 *buf, 49static int pm8921_read_buf(const struct device *dev, u16 addr, u8 *buf,
@@ -52,7 +52,7 @@ static int pm8921_read_buf(const struct device *dev, u16 addr, u8 *buf,
52 const struct pm8xxx_drvdata *pm8921_drvdata = dev_get_drvdata(dev); 52 const struct pm8xxx_drvdata *pm8921_drvdata = dev_get_drvdata(dev);
53 const struct pm8921 *pmic = pm8921_drvdata->pm_chip_data; 53 const struct pm8921 *pmic = pm8921_drvdata->pm_chip_data;
54 54
55 return msm_ssbi_read(pmic->dev->parent, addr, buf, cnt); 55 return ssbi_read(pmic->dev->parent, addr, buf, cnt);
56} 56}
57 57
58static int pm8921_write_buf(const struct device *dev, u16 addr, u8 *buf, 58static int pm8921_write_buf(const struct device *dev, u16 addr, u8 *buf,
@@ -61,7 +61,7 @@ static int pm8921_write_buf(const struct device *dev, u16 addr, u8 *buf,
61 const struct pm8xxx_drvdata *pm8921_drvdata = dev_get_drvdata(dev); 61 const struct pm8xxx_drvdata *pm8921_drvdata = dev_get_drvdata(dev);
62 const struct pm8921 *pmic = pm8921_drvdata->pm_chip_data; 62 const struct pm8921 *pmic = pm8921_drvdata->pm_chip_data;
63 63
64 return msm_ssbi_write(pmic->dev->parent, addr, buf, cnt); 64 return ssbi_write(pmic->dev->parent, addr, buf, cnt);
65} 65}
66 66
67static int pm8921_read_irq_stat(const struct device *dev, int irq) 67static int pm8921_read_irq_stat(const struct device *dev, int irq)
@@ -124,7 +124,7 @@ static int pm8921_probe(struct platform_device *pdev)
124 } 124 }
125 125
126 /* Read PMIC chip revision */ 126 /* Read PMIC chip revision */
127 rc = msm_ssbi_read(pdev->dev.parent, REG_HWREV, &val, sizeof(val)); 127 rc = ssbi_read(pdev->dev.parent, REG_HWREV, &val, sizeof(val));
128 if (rc) { 128 if (rc) {
129 pr_err("Failed to read hw rev reg %d:rc=%d\n", REG_HWREV, rc); 129 pr_err("Failed to read hw rev reg %d:rc=%d\n", REG_HWREV, rc);
130 goto err_read_rev; 130 goto err_read_rev;
@@ -133,7 +133,7 @@ static int pm8921_probe(struct platform_device *pdev)
133 rev = val; 133 rev = val;
134 134
135 /* Read PMIC chip revision 2 */ 135 /* Read PMIC chip revision 2 */
136 rc = msm_ssbi_read(pdev->dev.parent, REG_HWREV_2, &val, sizeof(val)); 136 rc = ssbi_read(pdev->dev.parent, REG_HWREV_2, &val, sizeof(val));
137 if (rc) { 137 if (rc) {
138 pr_err("Failed to read hw rev 2 reg %d:rc=%d\n", 138 pr_err("Failed to read hw rev 2 reg %d:rc=%d\n",
139 REG_HWREV_2, rc); 139 REG_HWREV_2, rc);
diff --git a/drivers/mfd/wm5102-tables.c b/drivers/mfd/wm5102-tables.c
index a433f580aa4c..ca2aed6bc830 100644
--- a/drivers/mfd/wm5102-tables.c
+++ b/drivers/mfd/wm5102-tables.c
@@ -331,6 +331,10 @@ static const struct reg_default wm5102_reg_default[] = {
331 { 0x000002A3, 0x1102 }, /* R675 - Mic Detect 1 */ 331 { 0x000002A3, 0x1102 }, /* R675 - Mic Detect 1 */
332 { 0x000002A4, 0x009F }, /* R676 - Mic Detect 2 */ 332 { 0x000002A4, 0x009F }, /* R676 - Mic Detect 2 */
333 { 0x000002A5, 0x0000 }, /* R677 - Mic Detect 3 */ 333 { 0x000002A5, 0x0000 }, /* R677 - Mic Detect 3 */
334 { 0x000002A6, 0x3737 }, /* R678 - Mic Detect Level 1 */
335 { 0x000002A7, 0x372C }, /* R679 - Mic Detect Level 2 */
336 { 0x000002A8, 0x1422 }, /* R680 - Mic Detect Level 3 */
337 { 0x000002A9, 0x030A }, /* R681 - Mic Detect Level 4 */
334 { 0x000002C3, 0x0000 }, /* R707 - Mic noise mix control 1 */ 338 { 0x000002C3, 0x0000 }, /* R707 - Mic noise mix control 1 */
335 { 0x000002CB, 0x0000 }, /* R715 - Isolation control */ 339 { 0x000002CB, 0x0000 }, /* R715 - Isolation control */
336 { 0x000002D3, 0x0000 }, /* R723 - Jack detect analogue */ 340 { 0x000002D3, 0x0000 }, /* R723 - Jack detect analogue */
@@ -1090,6 +1094,10 @@ static bool wm5102_readable_register(struct device *dev, unsigned int reg)
1090 case ARIZONA_MIC_DETECT_1: 1094 case ARIZONA_MIC_DETECT_1:
1091 case ARIZONA_MIC_DETECT_2: 1095 case ARIZONA_MIC_DETECT_2:
1092 case ARIZONA_MIC_DETECT_3: 1096 case ARIZONA_MIC_DETECT_3:
1097 case ARIZONA_MIC_DETECT_LEVEL_1:
1098 case ARIZONA_MIC_DETECT_LEVEL_2:
1099 case ARIZONA_MIC_DETECT_LEVEL_3:
1100 case ARIZONA_MIC_DETECT_LEVEL_4:
1093 case ARIZONA_MIC_NOISE_MIX_CONTROL_1: 1101 case ARIZONA_MIC_NOISE_MIX_CONTROL_1:
1094 case ARIZONA_ISOLATION_CONTROL: 1102 case ARIZONA_ISOLATION_CONTROL:
1095 case ARIZONA_JACK_DETECT_ANALOGUE: 1103 case ARIZONA_JACK_DETECT_ANALOGUE:
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index e83fdfe0c8ca..e29e7980a359 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -93,6 +93,14 @@ config ATMEL_TCB_CLKSRC_BLOCK
93 TC can be used for other purposes, such as PWM generation and 93 TC can be used for other purposes, such as PWM generation and
94 interval timing. 94 interval timing.
95 95
96config DUMMY_IRQ
97 tristate "Dummy IRQ handler"
98 default n
99 ---help---
100 This module accepts a single 'irq' parameter, which it should register for.
101 The sole purpose of this module is to help with debugging of systems on
102 which spurious IRQs would happen on disabled IRQ vector.
103
96config IBM_ASM 104config IBM_ASM
97 tristate "Device driver for IBM RSA service processor" 105 tristate "Device driver for IBM RSA service processor"
98 depends on X86 && PCI && INPUT 106 depends on X86 && PCI && INPUT
@@ -398,7 +406,7 @@ config DS1682
398 406
399config SPEAR13XX_PCIE_GADGET 407config SPEAR13XX_PCIE_GADGET
400 bool "PCIe gadget support for SPEAr13XX platform" 408 bool "PCIe gadget support for SPEAr13XX platform"
401 depends on ARCH_SPEAR13XX 409 depends on ARCH_SPEAR13XX && BROKEN
402 default n 410 default n
403 help 411 help
404 This option enables gadget support for PCIe controller. If 412 This option enables gadget support for PCIe controller. If
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 35a1463c72d9..865cbc6a7ae1 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -13,6 +13,7 @@ obj-$(CONFIG_ATMEL_TCLIB) += atmel_tclib.o
13obj-$(CONFIG_BMP085) += bmp085.o 13obj-$(CONFIG_BMP085) += bmp085.o
14obj-$(CONFIG_BMP085_I2C) += bmp085-i2c.o 14obj-$(CONFIG_BMP085_I2C) += bmp085-i2c.o
15obj-$(CONFIG_BMP085_SPI) += bmp085-spi.o 15obj-$(CONFIG_BMP085_SPI) += bmp085-spi.o
16obj-$(CONFIG_DUMMY_IRQ) += dummy-irq.o
16obj-$(CONFIG_ICS932S401) += ics932s401.o 17obj-$(CONFIG_ICS932S401) += ics932s401.o
17obj-$(CONFIG_LKDTM) += lkdtm.o 18obj-$(CONFIG_LKDTM) += lkdtm.o
18obj-$(CONFIG_TIFM_CORE) += tifm_core.o 19obj-$(CONFIG_TIFM_CORE) += tifm_core.o
@@ -49,6 +50,5 @@ obj-y += carma/
49obj-$(CONFIG_USB_SWITCH_FSA9480) += fsa9480.o 50obj-$(CONFIG_USB_SWITCH_FSA9480) += fsa9480.o
50obj-$(CONFIG_ALTERA_STAPL) +=altera-stapl/ 51obj-$(CONFIG_ALTERA_STAPL) +=altera-stapl/
51obj-$(CONFIG_INTEL_MEI) += mei/ 52obj-$(CONFIG_INTEL_MEI) += mei/
52obj-$(CONFIG_MAX8997_MUIC) += max8997-muic.o
53obj-$(CONFIG_VMWARE_VMCI) += vmw_vmci/ 53obj-$(CONFIG_VMWARE_VMCI) += vmw_vmci/
54obj-$(CONFIG_LATTICE_ECP3_CONFIG) += lattice-ecp3-config.o 54obj-$(CONFIG_LATTICE_ECP3_CONFIG) += lattice-ecp3-config.o
diff --git a/drivers/misc/apds9802als.c b/drivers/misc/apds9802als.c
index d648b0893027..5b5fd8416b3e 100644
--- a/drivers/misc/apds9802als.c
+++ b/drivers/misc/apds9802als.c
@@ -272,19 +272,8 @@ static int apds9802als_remove(struct i2c_client *client)
272} 272}
273 273
274#ifdef CONFIG_PM 274#ifdef CONFIG_PM
275static int apds9802als_suspend(struct i2c_client *client, pm_message_t mesg)
276{
277 als_set_power_state(client, false);
278 return 0;
279}
280
281static int apds9802als_resume(struct i2c_client *client)
282{
283 als_set_default_config(client);
284 return 0;
285}
286 275
287static int apds9802als_runtime_suspend(struct device *dev) 276static int apds9802als_suspend(struct device *dev)
288{ 277{
289 struct i2c_client *client = to_i2c_client(dev); 278 struct i2c_client *client = to_i2c_client(dev);
290 279
@@ -292,7 +281,7 @@ static int apds9802als_runtime_suspend(struct device *dev)
292 return 0; 281 return 0;
293} 282}
294 283
295static int apds9802als_runtime_resume(struct device *dev) 284static int apds9802als_resume(struct device *dev)
296{ 285{
297 struct i2c_client *client = to_i2c_client(dev); 286 struct i2c_client *client = to_i2c_client(dev);
298 287
@@ -300,16 +289,12 @@ static int apds9802als_runtime_resume(struct device *dev)
300 return 0; 289 return 0;
301} 290}
302 291
303static const struct dev_pm_ops apds9802als_pm_ops = { 292static UNIVERSAL_DEV_PM_OPS(apds9802als_pm_ops, apds9802als_suspend,
304 .runtime_suspend = apds9802als_runtime_suspend, 293 apds9802als_resume, NULL);
305 .runtime_resume = apds9802als_runtime_resume,
306};
307 294
308#define APDS9802ALS_PM_OPS (&apds9802als_pm_ops) 295#define APDS9802ALS_PM_OPS (&apds9802als_pm_ops)
309 296
310#else /* CONFIG_PM */ 297#else /* CONFIG_PM */
311#define apds9802als_suspend NULL
312#define apds9802als_resume NULL
313#define APDS9802ALS_PM_OPS NULL 298#define APDS9802ALS_PM_OPS NULL
314#endif /* CONFIG_PM */ 299#endif /* CONFIG_PM */
315 300
@@ -327,8 +312,6 @@ static struct i2c_driver apds9802als_driver = {
327 }, 312 },
328 .probe = apds9802als_probe, 313 .probe = apds9802als_probe,
329 .remove = apds9802als_remove, 314 .remove = apds9802als_remove,
330 .suspend = apds9802als_suspend,
331 .resume = apds9802als_resume,
332 .id_table = apds9802als_id, 315 .id_table = apds9802als_id,
333}; 316};
334 317
diff --git a/drivers/misc/apds990x.c b/drivers/misc/apds990x.c
index 0e67f8263cd8..98f9bb26492a 100644
--- a/drivers/misc/apds990x.c
+++ b/drivers/misc/apds990x.c
@@ -700,9 +700,6 @@ static ssize_t apds990x_lux_calib_store(struct device *dev,
700 if (strict_strtoul(buf, 0, &value)) 700 if (strict_strtoul(buf, 0, &value))
701 return -EINVAL; 701 return -EINVAL;
702 702
703 if (chip->lux_calib > APDS_RANGE)
704 return -EINVAL;
705
706 chip->lux_calib = value; 703 chip->lux_calib = value;
707 704
708 return len; 705 return len;
@@ -1204,7 +1201,7 @@ static int apds990x_remove(struct i2c_client *client)
1204 return 0; 1201 return 0;
1205} 1202}
1206 1203
1207#ifdef CONFIG_PM 1204#ifdef CONFIG_PM_SLEEP
1208static int apds990x_suspend(struct device *dev) 1205static int apds990x_suspend(struct device *dev)
1209{ 1206{
1210 struct i2c_client *client = container_of(dev, struct i2c_client, dev); 1207 struct i2c_client *client = container_of(dev, struct i2c_client, dev);
@@ -1227,10 +1224,6 @@ static int apds990x_resume(struct device *dev)
1227 1224
1228 return 0; 1225 return 0;
1229} 1226}
1230#else
1231#define apds990x_suspend NULL
1232#define apds990x_resume NULL
1233#define apds990x_shutdown NULL
1234#endif 1227#endif
1235 1228
1236#ifdef CONFIG_PM_RUNTIME 1229#ifdef CONFIG_PM_RUNTIME
diff --git a/drivers/misc/arm-charlcd.c b/drivers/misc/arm-charlcd.c
index fe8616a8d287..48651ef0028c 100644
--- a/drivers/misc/arm-charlcd.c
+++ b/drivers/misc/arm-charlcd.c
@@ -378,18 +378,7 @@ static struct platform_driver charlcd_driver = {
378 .remove = __exit_p(charlcd_remove), 378 .remove = __exit_p(charlcd_remove),
379}; 379};
380 380
381static int __init charlcd_init(void) 381module_platform_driver_probe(charlcd_driver, charlcd_probe);
382{
383 return platform_driver_probe(&charlcd_driver, charlcd_probe);
384}
385
386static void __exit charlcd_exit(void)
387{
388 platform_driver_unregister(&charlcd_driver);
389}
390
391module_init(charlcd_init);
392module_exit(charlcd_exit);
393 382
394MODULE_AUTHOR("Linus Walleij <triad@df.lth.se>"); 383MODULE_AUTHOR("Linus Walleij <triad@df.lth.se>");
395MODULE_DESCRIPTION("ARM Character LCD Driver"); 384MODULE_DESCRIPTION("ARM Character LCD Driver");
diff --git a/drivers/misc/atmel_pwm.c b/drivers/misc/atmel_pwm.c
index 28f5aaa19d4a..494d0500bda6 100644
--- a/drivers/misc/atmel_pwm.c
+++ b/drivers/misc/atmel_pwm.c
@@ -393,17 +393,7 @@ static struct platform_driver atmel_pwm_driver = {
393 */ 393 */
394}; 394};
395 395
396static int __init pwm_init(void) 396module_platform_driver_probe(atmel_pwm_driver, pwm_probe);
397{
398 return platform_driver_probe(&atmel_pwm_driver, pwm_probe);
399}
400module_init(pwm_init);
401
402static void __exit pwm_exit(void)
403{
404 platform_driver_unregister(&atmel_pwm_driver);
405}
406module_exit(pwm_exit);
407 397
408MODULE_DESCRIPTION("Driver for AT32/AT91 PWM module"); 398MODULE_DESCRIPTION("Driver for AT32/AT91 PWM module");
409MODULE_LICENSE("GPL"); 399MODULE_LICENSE("GPL");
diff --git a/drivers/misc/bh1770glc.c b/drivers/misc/bh1770glc.c
index 2ed8fc3be7e6..f4975f7d0d5b 100644
--- a/drivers/misc/bh1770glc.c
+++ b/drivers/misc/bh1770glc.c
@@ -1310,7 +1310,7 @@ static int bh1770_remove(struct i2c_client *client)
1310 return 0; 1310 return 0;
1311} 1311}
1312 1312
1313#ifdef CONFIG_PM 1313#ifdef CONFIG_PM_SLEEP
1314static int bh1770_suspend(struct device *dev) 1314static int bh1770_suspend(struct device *dev)
1315{ 1315{
1316 struct i2c_client *client = container_of(dev, struct i2c_client, dev); 1316 struct i2c_client *client = container_of(dev, struct i2c_client, dev);
@@ -1346,11 +1346,6 @@ static int bh1770_resume(struct device *dev)
1346 } 1346 }
1347 return ret; 1347 return ret;
1348} 1348}
1349
1350#else
1351#define bh1770_suspend NULL
1352#define bh1770_shutdown NULL
1353#define bh1770_resume NULL
1354#endif 1349#endif
1355 1350
1356#ifdef CONFIG_PM_RUNTIME 1351#ifdef CONFIG_PM_RUNTIME
diff --git a/drivers/misc/bh1780gli.c b/drivers/misc/bh1780gli.c
index cf03d0abf33e..818f3a0e62bf 100644
--- a/drivers/misc/bh1780gli.c
+++ b/drivers/misc/bh1780gli.c
@@ -196,7 +196,7 @@ static int bh1780_remove(struct i2c_client *client)
196 return 0; 196 return 0;
197} 197}
198 198
199#ifdef CONFIG_PM 199#ifdef CONFIG_PM_SLEEP
200static int bh1780_suspend(struct device *dev) 200static int bh1780_suspend(struct device *dev)
201{ 201{
202 struct bh1780_data *ddata; 202 struct bh1780_data *ddata;
@@ -235,11 +235,9 @@ static int bh1780_resume(struct device *dev)
235 235
236 return 0; 236 return 0;
237} 237}
238#endif /* CONFIG_PM_SLEEP */
239
238static SIMPLE_DEV_PM_OPS(bh1780_pm, bh1780_suspend, bh1780_resume); 240static SIMPLE_DEV_PM_OPS(bh1780_pm, bh1780_suspend, bh1780_resume);
239#define BH1780_PMOPS (&bh1780_pm)
240#else
241#define BH1780_PMOPS NULL
242#endif /* CONFIG_PM */
243 241
244static const struct i2c_device_id bh1780_id[] = { 242static const struct i2c_device_id bh1780_id[] = {
245 { "bh1780", 0 }, 243 { "bh1780", 0 },
@@ -252,7 +250,7 @@ static struct i2c_driver bh1780_driver = {
252 .id_table = bh1780_id, 250 .id_table = bh1780_id,
253 .driver = { 251 .driver = {
254 .name = "bh1780", 252 .name = "bh1780",
255 .pm = BH1780_PMOPS, 253 .pm = &bh1780_pm,
256 }, 254 },
257}; 255};
258 256
diff --git a/drivers/misc/cs5535-mfgpt.c b/drivers/misc/cs5535-mfgpt.c
index 9858f36dad8b..effd8c6b2b94 100644
--- a/drivers/misc/cs5535-mfgpt.c
+++ b/drivers/misc/cs5535-mfgpt.c
@@ -24,8 +24,11 @@
24 24
25static int mfgpt_reset_timers; 25static int mfgpt_reset_timers;
26module_param_named(mfgptfix, mfgpt_reset_timers, int, 0644); 26module_param_named(mfgptfix, mfgpt_reset_timers, int, 0644);
27MODULE_PARM_DESC(mfgptfix, "Reset the MFGPT timers during init; " 27MODULE_PARM_DESC(mfgptfix, "Try to reset the MFGPT timers during init; "
28 "required by some broken BIOSes (ie, TinyBIOS < 0.99)."); 28 "required by some broken BIOSes (ie, TinyBIOS < 0.99) or kexec "
29 "(1 = reset the MFGPT using an undocumented bit, "
30 "2 = perform a soft reset by unconfiguring all timers); "
31 "use what works best for you.");
29 32
30struct cs5535_mfgpt_timer { 33struct cs5535_mfgpt_timer {
31 struct cs5535_mfgpt_chip *chip; 34 struct cs5535_mfgpt_chip *chip;
@@ -256,6 +259,28 @@ static void reset_all_timers(void)
256} 259}
257 260
258/* 261/*
262 * This is another sledgehammer to reset all MFGPT timers.
263 * Instead of using the undocumented bit method it clears
264 * IRQ, NMI and RESET settings.
265 */
266static void soft_reset(void)
267{
268 int i;
269 struct cs5535_mfgpt_timer t;
270
271 for (i = 0; i < MFGPT_MAX_TIMERS; i++) {
272 t.nr = i;
273
274 cs5535_mfgpt_toggle_event(&t, MFGPT_CMP1, MFGPT_EVENT_RESET, 0);
275 cs5535_mfgpt_toggle_event(&t, MFGPT_CMP2, MFGPT_EVENT_RESET, 0);
276 cs5535_mfgpt_toggle_event(&t, MFGPT_CMP1, MFGPT_EVENT_NMI, 0);
277 cs5535_mfgpt_toggle_event(&t, MFGPT_CMP2, MFGPT_EVENT_NMI, 0);
278 cs5535_mfgpt_toggle_event(&t, MFGPT_CMP1, MFGPT_EVENT_IRQ, 0);
279 cs5535_mfgpt_toggle_event(&t, MFGPT_CMP2, MFGPT_EVENT_IRQ, 0);
280 }
281}
282
283/*
259 * Check whether any MFGPTs are available for the kernel to use. In most 284 * Check whether any MFGPTs are available for the kernel to use. In most
260 * cases, firmware that uses AMD's VSA code will claim all timers during 285 * cases, firmware that uses AMD's VSA code will claim all timers during
261 * bootup; we certainly don't want to take them if they're already in use. 286 * bootup; we certainly don't want to take them if they're already in use.
@@ -271,15 +296,17 @@ static int scan_timers(struct cs5535_mfgpt_chip *mfgpt)
271 int i; 296 int i;
272 297
273 /* bios workaround */ 298 /* bios workaround */
274 if (mfgpt_reset_timers) 299 if (mfgpt_reset_timers == 1)
275 reset_all_timers(); 300 reset_all_timers();
301 else if (mfgpt_reset_timers == 2)
302 soft_reset();
276 303
277 /* just to be safe, protect this section w/ lock */ 304 /* just to be safe, protect this section w/ lock */
278 spin_lock_irqsave(&mfgpt->lock, flags); 305 spin_lock_irqsave(&mfgpt->lock, flags);
279 for (i = 0; i < MFGPT_MAX_TIMERS; i++) { 306 for (i = 0; i < MFGPT_MAX_TIMERS; i++) {
280 timer.nr = i; 307 timer.nr = i;
281 val = cs5535_mfgpt_read(&timer, MFGPT_REG_SETUP); 308 val = cs5535_mfgpt_read(&timer, MFGPT_REG_SETUP);
282 if (!(val & MFGPT_SETUP_SETUP)) { 309 if (!(val & MFGPT_SETUP_SETUP) || mfgpt_reset_timers == 2) {
283 __set_bit(i, mfgpt->avail); 310 __set_bit(i, mfgpt->avail);
284 timers++; 311 timers++;
285 } 312 }
@@ -294,6 +321,12 @@ static int cs5535_mfgpt_probe(struct platform_device *pdev)
294 struct resource *res; 321 struct resource *res;
295 int err = -EIO, t; 322 int err = -EIO, t;
296 323
324 if (mfgpt_reset_timers < 0 || mfgpt_reset_timers > 2) {
325 dev_err(&pdev->dev, "Bad mfgpt_reset_timers value: %i\n",
326 mfgpt_reset_timers);
327 goto done;
328 }
329
297 /* There are two ways to get the MFGPT base address; one is by 330 /* There are two ways to get the MFGPT base address; one is by
298 * fetching it from MSR_LBAR_MFGPT, the other is by reading the 331 * fetching it from MSR_LBAR_MFGPT, the other is by reading the
299 * PCI BAR info. The latter method is easier (especially across 332 * PCI BAR info. The latter method is easier (especially across
diff --git a/drivers/misc/dummy-irq.c b/drivers/misc/dummy-irq.c
new file mode 100644
index 000000000000..7014167e2c61
--- /dev/null
+++ b/drivers/misc/dummy-irq.c
@@ -0,0 +1,59 @@
1/*
2 * Dummy IRQ handler driver.
3 *
4 * This module only registers itself as a handler that is specified to it
5 * by the 'irq' parameter.
6 *
7 * The sole purpose of this module is to help with debugging of systems on
8 * which spurious IRQs would happen on disabled IRQ vector.
9 *
10 * Copyright (C) 2013 Jiri Kosina
11 */
12
13/*
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License version 2 as published by
16 * the Free Software Foundation.
17 */
18#include <linux/module.h>
19#include <linux/irq.h>
20#include <linux/interrupt.h>
21
22static int irq;
23
24static irqreturn_t dummy_interrupt(int irq, void *dev_id)
25{
26 static int count = 0;
27
28 if (count == 0) {
29 printk(KERN_INFO "dummy-irq: interrupt occured on IRQ %d\n",
30 irq);
31 count++;
32 }
33
34 return IRQ_NONE;
35}
36
37static int __init dummy_irq_init(void)
38{
39 if (request_irq(irq, &dummy_interrupt, IRQF_SHARED, "dummy_irq", &irq)) {
40 printk(KERN_ERR "dummy-irq: cannot register IRQ %d\n", irq);
41 return -EIO;
42 }
43 printk(KERN_INFO "dummy-irq: registered for IRQ %d\n", irq);
44 return 0;
45}
46
47static void __exit dummy_irq_exit(void)
48{
49 printk(KERN_INFO "dummy-irq unloaded\n");
50 free_irq(irq, &irq);
51}
52
53module_init(dummy_irq_init);
54module_exit(dummy_irq_exit);
55
56MODULE_LICENSE("GPL");
57MODULE_AUTHOR("Jiri Kosina");
58module_param(irq, uint, 0444);
59MODULE_PARM_DESC(irq, "The IRQ to register for");
diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c
index b08cf8a08789..ad8fd8e64937 100644
--- a/drivers/misc/eeprom/at25.c
+++ b/drivers/misc/eeprom/at25.c
@@ -412,7 +412,7 @@ static int at25_probe(struct spi_device *spi)
412 mutex_init(&at25->lock); 412 mutex_init(&at25->lock);
413 at25->chip = chip; 413 at25->chip = chip;
414 at25->spi = spi_dev_get(spi); 414 at25->spi = spi_dev_get(spi);
415 dev_set_drvdata(&spi->dev, at25); 415 spi_set_drvdata(spi, at25);
416 at25->addrlen = addrlen; 416 at25->addrlen = addrlen;
417 417
418 /* Export the EEPROM bytes through sysfs, since that's convenient. 418 /* Export the EEPROM bytes through sysfs, since that's convenient.
@@ -463,7 +463,7 @@ static int at25_remove(struct spi_device *spi)
463{ 463{
464 struct at25_data *at25; 464 struct at25_data *at25;
465 465
466 at25 = dev_get_drvdata(&spi->dev); 466 at25 = spi_get_drvdata(spi);
467 sysfs_remove_bin_file(&spi->dev.kobj, &at25->bin); 467 sysfs_remove_bin_file(&spi->dev.kobj, &at25->bin);
468 kfree(at25); 468 kfree(at25);
469 return 0; 469 return 0;
diff --git a/drivers/misc/eeprom/eeprom_93xx46.c b/drivers/misc/eeprom/eeprom_93xx46.c
index a6b5d5e73485..94cfc1212577 100644
--- a/drivers/misc/eeprom/eeprom_93xx46.c
+++ b/drivers/misc/eeprom/eeprom_93xx46.c
@@ -363,7 +363,7 @@ static int eeprom_93xx46_probe(struct spi_device *spi)
363 dev_err(&spi->dev, "can't create erase interface\n"); 363 dev_err(&spi->dev, "can't create erase interface\n");
364 } 364 }
365 365
366 dev_set_drvdata(&spi->dev, edev); 366 spi_set_drvdata(spi, edev);
367 return 0; 367 return 0;
368fail: 368fail:
369 kfree(edev); 369 kfree(edev);
@@ -372,13 +372,13 @@ fail:
372 372
373static int eeprom_93xx46_remove(struct spi_device *spi) 373static int eeprom_93xx46_remove(struct spi_device *spi)
374{ 374{
375 struct eeprom_93xx46_dev *edev = dev_get_drvdata(&spi->dev); 375 struct eeprom_93xx46_dev *edev = spi_get_drvdata(spi);
376 376
377 if (!(edev->pdata->flags & EE_READONLY)) 377 if (!(edev->pdata->flags & EE_READONLY))
378 device_remove_file(&spi->dev, &dev_attr_erase); 378 device_remove_file(&spi->dev, &dev_attr_erase);
379 379
380 sysfs_remove_bin_file(&spi->dev.kobj, &edev->bin); 380 sysfs_remove_bin_file(&spi->dev.kobj, &edev->bin);
381 dev_set_drvdata(&spi->dev, NULL); 381 spi_set_drvdata(spi, NULL);
382 kfree(edev); 382 kfree(edev);
383 return 0; 383 return 0;
384} 384}
diff --git a/drivers/misc/ep93xx_pwm.c b/drivers/misc/ep93xx_pwm.c
index 16d7179e2f9b..96787ec15cad 100644
--- a/drivers/misc/ep93xx_pwm.c
+++ b/drivers/misc/ep93xx_pwm.c
@@ -365,18 +365,7 @@ static struct platform_driver ep93xx_pwm_driver = {
365 .remove = __exit_p(ep93xx_pwm_remove), 365 .remove = __exit_p(ep93xx_pwm_remove),
366}; 366};
367 367
368static int __init ep93xx_pwm_init(void) 368module_platform_driver_probe(ep93xx_pwm_driver, ep93xx_pwm_probe);
369{
370 return platform_driver_probe(&ep93xx_pwm_driver, ep93xx_pwm_probe);
371}
372
373static void __exit ep93xx_pwm_exit(void)
374{
375 platform_driver_unregister(&ep93xx_pwm_driver);
376}
377
378module_init(ep93xx_pwm_init);
379module_exit(ep93xx_pwm_exit);
380 369
381MODULE_AUTHOR("Matthieu Crapet <mcrapet@gmail.com>, " 370MODULE_AUTHOR("Matthieu Crapet <mcrapet@gmail.com>, "
382 "H Hartley Sweeten <hsweeten@visionengravers.com>"); 371 "H Hartley Sweeten <hsweeten@visionengravers.com>");
diff --git a/drivers/misc/fsa9480.c b/drivers/misc/fsa9480.c
index e8cbb1c59f4c..a725c79c35f5 100644
--- a/drivers/misc/fsa9480.c
+++ b/drivers/misc/fsa9480.c
@@ -474,10 +474,11 @@ static int fsa9480_remove(struct i2c_client *client)
474 return 0; 474 return 0;
475} 475}
476 476
477#ifdef CONFIG_PM 477#ifdef CONFIG_PM_SLEEP
478 478
479static int fsa9480_suspend(struct i2c_client *client, pm_message_t state) 479static int fsa9480_suspend(struct device *dev)
480{ 480{
481 struct i2c_client *client = to_i2c_client(dev);
481 struct fsa9480_usbsw *usbsw = i2c_get_clientdata(client); 482 struct fsa9480_usbsw *usbsw = i2c_get_clientdata(client);
482 struct fsa9480_platform_data *pdata = usbsw->pdata; 483 struct fsa9480_platform_data *pdata = usbsw->pdata;
483 484
@@ -490,8 +491,9 @@ static int fsa9480_suspend(struct i2c_client *client, pm_message_t state)
490 return 0; 491 return 0;
491} 492}
492 493
493static int fsa9480_resume(struct i2c_client *client) 494static int fsa9480_resume(struct device *dev)
494{ 495{
496 struct i2c_client *client = to_i2c_client(dev);
495 struct fsa9480_usbsw *usbsw = i2c_get_clientdata(client); 497 struct fsa9480_usbsw *usbsw = i2c_get_clientdata(client);
496 int dev1, dev2; 498 int dev1, dev2;
497 499
@@ -515,12 +517,14 @@ static int fsa9480_resume(struct i2c_client *client)
515 return 0; 517 return 0;
516} 518}
517 519
520static SIMPLE_DEV_PM_OPS(fsa9480_pm_ops, fsa9480_suspend, fsa9480_resume);
521#define FSA9480_PM_OPS (&fsa9480_pm_ops)
522
518#else 523#else
519 524
520#define fsa9480_suspend NULL 525#define FSA9480_PM_OPS NULL
521#define fsa9480_resume NULL
522 526
523#endif /* CONFIG_PM */ 527#endif /* CONFIG_PM_SLEEP */
524 528
525static const struct i2c_device_id fsa9480_id[] = { 529static const struct i2c_device_id fsa9480_id[] = {
526 {"fsa9480", 0}, 530 {"fsa9480", 0},
@@ -531,11 +535,10 @@ MODULE_DEVICE_TABLE(i2c, fsa9480_id);
531static struct i2c_driver fsa9480_i2c_driver = { 535static struct i2c_driver fsa9480_i2c_driver = {
532 .driver = { 536 .driver = {
533 .name = "fsa9480", 537 .name = "fsa9480",
538 .pm = FSA9480_PM_OPS,
534 }, 539 },
535 .probe = fsa9480_probe, 540 .probe = fsa9480_probe,
536 .remove = fsa9480_remove, 541 .remove = fsa9480_remove,
537 .resume = fsa9480_resume,
538 .suspend = fsa9480_suspend,
539 .id_table = fsa9480_id, 542 .id_table = fsa9480_id,
540}; 543};
541 544
diff --git a/drivers/misc/isl29003.c b/drivers/misc/isl29003.c
index 29b306c6bdb3..c5145b3fcce8 100644
--- a/drivers/misc/isl29003.c
+++ b/drivers/misc/isl29003.c
@@ -409,18 +409,20 @@ static int isl29003_remove(struct i2c_client *client)
409 return 0; 409 return 0;
410} 410}
411 411
412#ifdef CONFIG_PM 412#ifdef CONFIG_PM_SLEEP
413static int isl29003_suspend(struct i2c_client *client, pm_message_t mesg) 413static int isl29003_suspend(struct device *dev)
414{ 414{
415 struct i2c_client *client = to_i2c_client(dev);
415 struct isl29003_data *data = i2c_get_clientdata(client); 416 struct isl29003_data *data = i2c_get_clientdata(client);
416 417
417 data->power_state_before_suspend = isl29003_get_power_state(client); 418 data->power_state_before_suspend = isl29003_get_power_state(client);
418 return isl29003_set_power_state(client, 0); 419 return isl29003_set_power_state(client, 0);
419} 420}
420 421
421static int isl29003_resume(struct i2c_client *client) 422static int isl29003_resume(struct device *dev)
422{ 423{
423 int i; 424 int i;
425 struct i2c_client *client = to_i2c_client(dev);
424 struct isl29003_data *data = i2c_get_clientdata(client); 426 struct isl29003_data *data = i2c_get_clientdata(client);
425 427
426 /* restore registers from cache */ 428 /* restore registers from cache */
@@ -432,10 +434,12 @@ static int isl29003_resume(struct i2c_client *client)
432 data->power_state_before_suspend); 434 data->power_state_before_suspend);
433} 435}
434 436
437static SIMPLE_DEV_PM_OPS(isl29003_pm_ops, isl29003_suspend, isl29003_resume);
438#define ISL29003_PM_OPS (&isl29003_pm_ops)
439
435#else 440#else
436#define isl29003_suspend NULL 441#define ISL29003_PM_OPS NULL
437#define isl29003_resume NULL 442#endif /* CONFIG_PM_SLEEP */
438#endif /* CONFIG_PM */
439 443
440static const struct i2c_device_id isl29003_id[] = { 444static const struct i2c_device_id isl29003_id[] = {
441 { "isl29003", 0 }, 445 { "isl29003", 0 },
@@ -447,9 +451,8 @@ static struct i2c_driver isl29003_driver = {
447 .driver = { 451 .driver = {
448 .name = ISL29003_DRV_NAME, 452 .name = ISL29003_DRV_NAME,
449 .owner = THIS_MODULE, 453 .owner = THIS_MODULE,
454 .pm = ISL29003_PM_OPS,
450 }, 455 },
451 .suspend = isl29003_suspend,
452 .resume = isl29003_resume,
453 .probe = isl29003_probe, 456 .probe = isl29003_probe,
454 .remove = isl29003_remove, 457 .remove = isl29003_remove,
455 .id_table = isl29003_id, 458 .id_table = isl29003_id,
diff --git a/drivers/misc/lattice-ecp3-config.c b/drivers/misc/lattice-ecp3-config.c
index 155700bfd2b6..bb26f086bd8b 100644
--- a/drivers/misc/lattice-ecp3-config.c
+++ b/drivers/misc/lattice-ecp3-config.c
@@ -69,7 +69,7 @@ static const struct ecp3_dev ecp3_dev[] = {
69static void firmware_load(const struct firmware *fw, void *context) 69static void firmware_load(const struct firmware *fw, void *context)
70{ 70{
71 struct spi_device *spi = (struct spi_device *)context; 71 struct spi_device *spi = (struct spi_device *)context;
72 struct fpga_data *data = dev_get_drvdata(&spi->dev); 72 struct fpga_data *data = spi_get_drvdata(spi);
73 u8 *buffer; 73 u8 *buffer;
74 int ret; 74 int ret;
75 u8 txbuf[8]; 75 u8 txbuf[8];
diff --git a/drivers/misc/mei/Kconfig b/drivers/misc/mei/Kconfig
index d21b4d006a55..c76fa31e9bf6 100644
--- a/drivers/misc/mei/Kconfig
+++ b/drivers/misc/mei/Kconfig
@@ -10,10 +10,9 @@ config INTEL_MEI
10 <http://software.intel.com/en-us/manageability/> 10 <http://software.intel.com/en-us/manageability/>
11 11
12config INTEL_MEI_ME 12config INTEL_MEI_ME
13 bool "ME Enabled Intel Chipsets" 13 tristate "ME Enabled Intel Chipsets"
14 depends on INTEL_MEI 14 select INTEL_MEI
15 depends on X86 && PCI && WATCHDOG_CORE 15 depends on X86 && PCI && WATCHDOG_CORE
16 default y
17 help 16 help
18 MEI support for ME Enabled Intel chipsets. 17 MEI support for ME Enabled Intel chipsets.
19 18
diff --git a/drivers/misc/mei/Makefile b/drivers/misc/mei/Makefile
index 040af6c7b147..08698a466268 100644
--- a/drivers/misc/mei/Makefile
+++ b/drivers/misc/mei/Makefile
@@ -10,5 +10,10 @@ mei-objs += client.o
10mei-objs += main.o 10mei-objs += main.o
11mei-objs += amthif.o 11mei-objs += amthif.o
12mei-objs += wd.o 12mei-objs += wd.o
13mei-$(CONFIG_INTEL_MEI_ME) += pci-me.o 13mei-objs += bus.o
14mei-$(CONFIG_INTEL_MEI_ME) += hw-me.o 14mei-objs += nfc.o
15mei-$(CONFIG_DEBUG_FS) += debugfs.o
16
17obj-$(CONFIG_INTEL_MEI_ME) += mei-me.o
18mei-me-objs := pci-me.o
19mei-me-objs += hw-me.o
diff --git a/drivers/misc/mei/amthif.c b/drivers/misc/mei/amthif.c
index c86d7e3839a4..31a6212cb8b1 100644
--- a/drivers/misc/mei/amthif.c
+++ b/drivers/misc/mei/amthif.c
@@ -449,7 +449,7 @@ int mei_amthif_irq_write_complete(struct mei_device *dev, s32 *slots,
449 struct mei_msg_hdr mei_hdr; 449 struct mei_msg_hdr mei_hdr;
450 struct mei_cl *cl = cb->cl; 450 struct mei_cl *cl = cb->cl;
451 size_t len = dev->iamthif_msg_buf_size - dev->iamthif_msg_buf_index; 451 size_t len = dev->iamthif_msg_buf_size - dev->iamthif_msg_buf_index;
452 size_t msg_slots = mei_data2slots(len); 452 u32 msg_slots = mei_data2slots(len);
453 453
454 mei_hdr.host_addr = cl->host_client_id; 454 mei_hdr.host_addr = cl->host_client_id;
455 mei_hdr.me_addr = cl->me_client_id; 455 mei_hdr.me_addr = cl->me_client_id;
@@ -505,14 +505,15 @@ int mei_amthif_irq_write_complete(struct mei_device *dev, s32 *slots,
505 * mei_amthif_irq_read_message - read routine after ISR to 505 * mei_amthif_irq_read_message - read routine after ISR to
506 * handle the read amthif message 506 * handle the read amthif message
507 * 507 *
508 * @complete_list: An instance of our list structure
509 * @dev: the device structure 508 * @dev: the device structure
510 * @mei_hdr: header of amthif message 509 * @mei_hdr: header of amthif message
510 * @complete_list: An instance of our list structure
511 * 511 *
512 * returns 0 on success, <0 on failure. 512 * returns 0 on success, <0 on failure.
513 */ 513 */
514int mei_amthif_irq_read_message(struct mei_cl_cb *complete_list, 514int mei_amthif_irq_read_msg(struct mei_device *dev,
515 struct mei_device *dev, struct mei_msg_hdr *mei_hdr) 515 struct mei_msg_hdr *mei_hdr,
516 struct mei_cl_cb *complete_list)
516{ 517{
517 struct mei_cl_cb *cb; 518 struct mei_cl_cb *cb;
518 unsigned char *buffer; 519 unsigned char *buffer;
@@ -530,8 +531,7 @@ int mei_amthif_irq_read_message(struct mei_cl_cb *complete_list,
530 if (!mei_hdr->msg_complete) 531 if (!mei_hdr->msg_complete)
531 return 0; 532 return 0;
532 533
533 dev_dbg(&dev->pdev->dev, 534 dev_dbg(&dev->pdev->dev, "amthif_message_buffer_index =%d\n",
534 "amthif_message_buffer_index =%d\n",
535 mei_hdr->length); 535 mei_hdr->length);
536 536
537 dev_dbg(&dev->pdev->dev, "completed amthif read.\n "); 537 dev_dbg(&dev->pdev->dev, "completed amthif read.\n ");
@@ -566,12 +566,13 @@ int mei_amthif_irq_read_message(struct mei_cl_cb *complete_list,
566 */ 566 */
567int mei_amthif_irq_read(struct mei_device *dev, s32 *slots) 567int mei_amthif_irq_read(struct mei_device *dev, s32 *slots)
568{ 568{
569 u32 msg_slots = mei_data2slots(sizeof(struct hbm_flow_control));
569 570
570 if (((*slots) * sizeof(u32)) < (sizeof(struct mei_msg_hdr) 571 if (*slots < msg_slots)
571 + sizeof(struct hbm_flow_control))) {
572 return -EMSGSIZE; 572 return -EMSGSIZE;
573 } 573
574 *slots -= mei_data2slots(sizeof(struct hbm_flow_control)); 574 *slots -= msg_slots;
575
575 if (mei_hbm_cl_flow_control_req(dev, &dev->iamthif_cl)) { 576 if (mei_hbm_cl_flow_control_req(dev, &dev->iamthif_cl)) {
576 dev_dbg(&dev->pdev->dev, "iamthif flow control failed\n"); 577 dev_dbg(&dev->pdev->dev, "iamthif flow control failed\n");
577 return -EIO; 578 return -EIO;
diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c
new file mode 100644
index 000000000000..1e935eacaa7f
--- /dev/null
+++ b/drivers/misc/mei/bus.c
@@ -0,0 +1,528 @@
1/*
2 * Intel Management Engine Interface (Intel MEI) Linux driver
3 * Copyright (c) 2012-2013, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 */
15
16#include <linux/module.h>
17#include <linux/device.h>
18#include <linux/kernel.h>
19#include <linux/sched.h>
20#include <linux/init.h>
21#include <linux/errno.h>
22#include <linux/slab.h>
23#include <linux/mutex.h>
24#include <linux/interrupt.h>
25#include <linux/pci.h>
26#include <linux/mei_cl_bus.h>
27
28#include "mei_dev.h"
29#include "hw-me.h"
30#include "client.h"
31
32#define to_mei_cl_driver(d) container_of(d, struct mei_cl_driver, driver)
33#define to_mei_cl_device(d) container_of(d, struct mei_cl_device, dev)
34
35static int mei_cl_device_match(struct device *dev, struct device_driver *drv)
36{
37 struct mei_cl_device *device = to_mei_cl_device(dev);
38 struct mei_cl_driver *driver = to_mei_cl_driver(drv);
39 const struct mei_cl_device_id *id;
40
41 if (!device)
42 return 0;
43
44 if (!driver || !driver->id_table)
45 return 0;
46
47 id = driver->id_table;
48
49 while (id->name[0]) {
50 if (!strcmp(dev_name(dev), id->name))
51 return 1;
52
53 id++;
54 }
55
56 return 0;
57}
58
59static int mei_cl_device_probe(struct device *dev)
60{
61 struct mei_cl_device *device = to_mei_cl_device(dev);
62 struct mei_cl_driver *driver;
63 struct mei_cl_device_id id;
64
65 if (!device)
66 return 0;
67
68 driver = to_mei_cl_driver(dev->driver);
69 if (!driver || !driver->probe)
70 return -ENODEV;
71
72 dev_dbg(dev, "Device probe\n");
73
74 strncpy(id.name, dev_name(dev), MEI_CL_NAME_SIZE);
75
76 return driver->probe(device, &id);
77}
78
79static int mei_cl_device_remove(struct device *dev)
80{
81 struct mei_cl_device *device = to_mei_cl_device(dev);
82 struct mei_cl_driver *driver;
83
84 if (!device || !dev->driver)
85 return 0;
86
87 if (device->event_cb) {
88 device->event_cb = NULL;
89 cancel_work_sync(&device->event_work);
90 }
91
92 driver = to_mei_cl_driver(dev->driver);
93 if (!driver->remove) {
94 dev->driver = NULL;
95
96 return 0;
97 }
98
99 return driver->remove(device);
100}
101
102static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
103 char *buf)
104{
105 int len;
106
107 len = snprintf(buf, PAGE_SIZE, "mei:%s\n", dev_name(dev));
108
109 return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len;
110}
111
112static struct device_attribute mei_cl_dev_attrs[] = {
113 __ATTR_RO(modalias),
114 __ATTR_NULL,
115};
116
117static int mei_cl_uevent(struct device *dev, struct kobj_uevent_env *env)
118{
119 if (add_uevent_var(env, "MODALIAS=mei:%s", dev_name(dev)))
120 return -ENOMEM;
121
122 return 0;
123}
124
125static struct bus_type mei_cl_bus_type = {
126 .name = "mei",
127 .dev_attrs = mei_cl_dev_attrs,
128 .match = mei_cl_device_match,
129 .probe = mei_cl_device_probe,
130 .remove = mei_cl_device_remove,
131 .uevent = mei_cl_uevent,
132};
133
134static void mei_cl_dev_release(struct device *dev)
135{
136 kfree(to_mei_cl_device(dev));
137}
138
139static struct device_type mei_cl_device_type = {
140 .release = mei_cl_dev_release,
141};
142
143static struct mei_cl *mei_bus_find_mei_cl_by_uuid(struct mei_device *dev,
144 uuid_le uuid)
145{
146 struct mei_cl *cl, *next;
147
148 list_for_each_entry_safe(cl, next, &dev->device_list, device_link) {
149 if (!uuid_le_cmp(uuid, cl->device_uuid))
150 return cl;
151 }
152
153 return NULL;
154}
155struct mei_cl_device *mei_cl_add_device(struct mei_device *dev,
156 uuid_le uuid, char *name,
157 struct mei_cl_ops *ops)
158{
159 struct mei_cl_device *device;
160 struct mei_cl *cl;
161 int status;
162
163 cl = mei_bus_find_mei_cl_by_uuid(dev, uuid);
164 if (cl == NULL)
165 return NULL;
166
167 device = kzalloc(sizeof(struct mei_cl_device), GFP_KERNEL);
168 if (!device)
169 return NULL;
170
171 device->cl = cl;
172 device->ops = ops;
173
174 device->dev.parent = &dev->pdev->dev;
175 device->dev.bus = &mei_cl_bus_type;
176 device->dev.type = &mei_cl_device_type;
177
178 dev_set_name(&device->dev, "%s", name);
179
180 status = device_register(&device->dev);
181 if (status) {
182 dev_err(&dev->pdev->dev, "Failed to register MEI device\n");
183 kfree(device);
184 return NULL;
185 }
186
187 cl->device = device;
188
189 dev_dbg(&device->dev, "client %s registered\n", name);
190
191 return device;
192}
193EXPORT_SYMBOL_GPL(mei_cl_add_device);
194
195void mei_cl_remove_device(struct mei_cl_device *device)
196{
197 device_unregister(&device->dev);
198}
199EXPORT_SYMBOL_GPL(mei_cl_remove_device);
200
201int __mei_cl_driver_register(struct mei_cl_driver *driver, struct module *owner)
202{
203 int err;
204
205 driver->driver.name = driver->name;
206 driver->driver.owner = owner;
207 driver->driver.bus = &mei_cl_bus_type;
208
209 err = driver_register(&driver->driver);
210 if (err)
211 return err;
212
213 pr_debug("mei: driver [%s] registered\n", driver->driver.name);
214
215 return 0;
216}
217EXPORT_SYMBOL_GPL(__mei_cl_driver_register);
218
219void mei_cl_driver_unregister(struct mei_cl_driver *driver)
220{
221 driver_unregister(&driver->driver);
222
223 pr_debug("mei: driver [%s] unregistered\n", driver->driver.name);
224}
225EXPORT_SYMBOL_GPL(mei_cl_driver_unregister);
226
227static int ___mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length,
228 bool blocking)
229{
230 struct mei_device *dev;
231 struct mei_cl_cb *cb;
232 int id;
233 int rets;
234
235 if (WARN_ON(!cl || !cl->dev))
236 return -ENODEV;
237
238 dev = cl->dev;
239
240 if (cl->state != MEI_FILE_CONNECTED)
241 return -ENODEV;
242
243 /* Check if we have an ME client device */
244 id = mei_me_cl_by_id(dev, cl->me_client_id);
245 if (id < 0)
246 return -ENODEV;
247
248 if (length > dev->me_clients[id].props.max_msg_length)
249 return -EINVAL;
250
251 cb = mei_io_cb_init(cl, NULL);
252 if (!cb)
253 return -ENOMEM;
254
255 rets = mei_io_cb_alloc_req_buf(cb, length);
256 if (rets < 0) {
257 mei_io_cb_free(cb);
258 return rets;
259 }
260
261 memcpy(cb->request_buffer.data, buf, length);
262
263 mutex_lock(&dev->device_lock);
264
265 rets = mei_cl_write(cl, cb, blocking);
266
267 mutex_unlock(&dev->device_lock);
268 if (rets < 0)
269 mei_io_cb_free(cb);
270
271 return rets;
272}
273
274int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length)
275{
276 struct mei_device *dev;
277 struct mei_cl_cb *cb;
278 size_t r_length;
279 int err;
280
281 if (WARN_ON(!cl || !cl->dev))
282 return -ENODEV;
283
284 dev = cl->dev;
285
286 mutex_lock(&dev->device_lock);
287
288 if (!cl->read_cb) {
289 err = mei_cl_read_start(cl, length);
290 if (err < 0) {
291 mutex_unlock(&dev->device_lock);
292 return err;
293 }
294 }
295
296 if (cl->reading_state != MEI_READ_COMPLETE &&
297 !waitqueue_active(&cl->rx_wait)) {
298 mutex_unlock(&dev->device_lock);
299
300 if (wait_event_interruptible(cl->rx_wait,
301 (MEI_READ_COMPLETE == cl->reading_state))) {
302 if (signal_pending(current))
303 return -EINTR;
304 return -ERESTARTSYS;
305 }
306
307 mutex_lock(&dev->device_lock);
308 }
309
310 cb = cl->read_cb;
311
312 if (cl->reading_state != MEI_READ_COMPLETE) {
313 r_length = 0;
314 goto out;
315 }
316
317 r_length = min_t(size_t, length, cb->buf_idx);
318
319 memcpy(buf, cb->response_buffer.data, r_length);
320
321 mei_io_cb_free(cb);
322 cl->reading_state = MEI_IDLE;
323 cl->read_cb = NULL;
324
325out:
326 mutex_unlock(&dev->device_lock);
327
328 return r_length;
329}
330
331inline int __mei_cl_async_send(struct mei_cl *cl, u8 *buf, size_t length)
332{
333 return ___mei_cl_send(cl, buf, length, 0);
334}
335
336inline int __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length)
337{
338 return ___mei_cl_send(cl, buf, length, 1);
339}
340
341int mei_cl_send(struct mei_cl_device *device, u8 *buf, size_t length)
342{
343 struct mei_cl *cl = device->cl;
344
345 if (cl == NULL)
346 return -ENODEV;
347
348 if (device->ops && device->ops->send)
349 return device->ops->send(device, buf, length);
350
351 return __mei_cl_send(cl, buf, length);
352}
353EXPORT_SYMBOL_GPL(mei_cl_send);
354
355int mei_cl_recv(struct mei_cl_device *device, u8 *buf, size_t length)
356{
357 struct mei_cl *cl = device->cl;
358
359 if (cl == NULL)
360 return -ENODEV;
361
362 if (device->ops && device->ops->recv)
363 return device->ops->recv(device, buf, length);
364
365 return __mei_cl_recv(cl, buf, length);
366}
367EXPORT_SYMBOL_GPL(mei_cl_recv);
368
369static void mei_bus_event_work(struct work_struct *work)
370{
371 struct mei_cl_device *device;
372
373 device = container_of(work, struct mei_cl_device, event_work);
374
375 if (device->event_cb)
376 device->event_cb(device, device->events, device->event_context);
377
378 device->events = 0;
379
380 /* Prepare for the next read */
381 mei_cl_read_start(device->cl, 0);
382}
383
384int mei_cl_register_event_cb(struct mei_cl_device *device,
385 mei_cl_event_cb_t event_cb, void *context)
386{
387 if (device->event_cb)
388 return -EALREADY;
389
390 device->events = 0;
391 device->event_cb = event_cb;
392 device->event_context = context;
393 INIT_WORK(&device->event_work, mei_bus_event_work);
394
395 mei_cl_read_start(device->cl, 0);
396
397 return 0;
398}
399EXPORT_SYMBOL_GPL(mei_cl_register_event_cb);
400
401void *mei_cl_get_drvdata(const struct mei_cl_device *device)
402{
403 return dev_get_drvdata(&device->dev);
404}
405EXPORT_SYMBOL_GPL(mei_cl_get_drvdata);
406
407void mei_cl_set_drvdata(struct mei_cl_device *device, void *data)
408{
409 dev_set_drvdata(&device->dev, data);
410}
411EXPORT_SYMBOL_GPL(mei_cl_set_drvdata);
412
413int mei_cl_enable_device(struct mei_cl_device *device)
414{
415 int err;
416 struct mei_device *dev;
417 struct mei_cl *cl = device->cl;
418
419 if (cl == NULL)
420 return -ENODEV;
421
422 dev = cl->dev;
423
424 mutex_lock(&dev->device_lock);
425
426 cl->state = MEI_FILE_CONNECTING;
427
428 err = mei_cl_connect(cl, NULL);
429 if (err < 0) {
430 mutex_unlock(&dev->device_lock);
431 dev_err(&dev->pdev->dev, "Could not connect to the ME client");
432
433 return err;
434 }
435
436 mutex_unlock(&dev->device_lock);
437
438 if (device->event_cb && !cl->read_cb)
439 mei_cl_read_start(device->cl, 0);
440
441 if (!device->ops || !device->ops->enable)
442 return 0;
443
444 return device->ops->enable(device);
445}
446EXPORT_SYMBOL_GPL(mei_cl_enable_device);
447
448int mei_cl_disable_device(struct mei_cl_device *device)
449{
450 int err;
451 struct mei_device *dev;
452 struct mei_cl *cl = device->cl;
453
454 if (cl == NULL)
455 return -ENODEV;
456
457 dev = cl->dev;
458
459 mutex_lock(&dev->device_lock);
460
461 if (cl->state != MEI_FILE_CONNECTED) {
462 mutex_unlock(&dev->device_lock);
463 dev_err(&dev->pdev->dev, "Already disconnected");
464
465 return 0;
466 }
467
468 cl->state = MEI_FILE_DISCONNECTING;
469
470 err = mei_cl_disconnect(cl);
471 if (err < 0) {
472 mutex_unlock(&dev->device_lock);
473 dev_err(&dev->pdev->dev,
474 "Could not disconnect from the ME client");
475
476 return err;
477 }
478
479 /* Flush queues and remove any pending read */
480 mei_cl_flush_queues(cl);
481
482 if (cl->read_cb) {
483 struct mei_cl_cb *cb = NULL;
484
485 cb = mei_cl_find_read_cb(cl);
486 /* Remove entry from read list */
487 if (cb)
488 list_del(&cb->list);
489
490 cb = cl->read_cb;
491 cl->read_cb = NULL;
492
493 if (cb) {
494 mei_io_cb_free(cb);
495 cb = NULL;
496 }
497 }
498
499 mutex_unlock(&dev->device_lock);
500
501 if (!device->ops || !device->ops->disable)
502 return 0;
503
504 return device->ops->disable(device);
505}
506EXPORT_SYMBOL_GPL(mei_cl_disable_device);
507
508void mei_cl_bus_rx_event(struct mei_cl *cl)
509{
510 struct mei_cl_device *device = cl->device;
511
512 if (!device || !device->event_cb)
513 return;
514
515 set_bit(MEI_CL_EVENT_RX, &device->events);
516
517 schedule_work(&device->event_work);
518}
519
520int __init mei_cl_bus_init(void)
521{
522 return bus_register(&mei_cl_bus_type);
523}
524
525void __exit mei_cl_bus_exit(void)
526{
527 bus_unregister(&mei_cl_bus_type);
528}
diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c
index 1569afe935de..71892745e2e8 100644
--- a/drivers/misc/mei/client.c
+++ b/drivers/misc/mei/client.c
@@ -216,6 +216,7 @@ void mei_cl_init(struct mei_cl *cl, struct mei_device *dev)
216 init_waitqueue_head(&cl->rx_wait); 216 init_waitqueue_head(&cl->rx_wait);
217 init_waitqueue_head(&cl->tx_wait); 217 init_waitqueue_head(&cl->tx_wait);
218 INIT_LIST_HEAD(&cl->link); 218 INIT_LIST_HEAD(&cl->link);
219 INIT_LIST_HEAD(&cl->device_link);
219 cl->reading_state = MEI_IDLE; 220 cl->reading_state = MEI_IDLE;
220 cl->writing_state = MEI_IDLE; 221 cl->writing_state = MEI_IDLE;
221 cl->dev = dev; 222 cl->dev = dev;
@@ -357,6 +358,9 @@ void mei_host_client_init(struct work_struct *work)
357 mei_amthif_host_init(dev); 358 mei_amthif_host_init(dev);
358 else if (!uuid_le_cmp(client_props->protocol_name, mei_wd_guid)) 359 else if (!uuid_le_cmp(client_props->protocol_name, mei_wd_guid))
359 mei_wd_host_init(dev); 360 mei_wd_host_init(dev);
361 else if (!uuid_le_cmp(client_props->protocol_name, mei_nfc_guid))
362 mei_nfc_host_init(dev);
363
360 } 364 }
361 365
362 dev->dev_state = MEI_DEV_ENABLED; 366 dev->dev_state = MEI_DEV_ENABLED;
@@ -620,7 +624,7 @@ int mei_cl_flow_ctrl_reduce(struct mei_cl *cl)
620 * 624 *
621 * returns 0 on success, <0 on failure. 625 * returns 0 on success, <0 on failure.
622 */ 626 */
623int mei_cl_read_start(struct mei_cl *cl) 627int mei_cl_read_start(struct mei_cl *cl, size_t length)
624{ 628{
625 struct mei_device *dev; 629 struct mei_device *dev;
626 struct mei_cl_cb *cb; 630 struct mei_cl_cb *cb;
@@ -653,8 +657,9 @@ int mei_cl_read_start(struct mei_cl *cl)
653 if (!cb) 657 if (!cb)
654 return -ENOMEM; 658 return -ENOMEM;
655 659
656 rets = mei_io_cb_alloc_resp_buf(cb, 660 /* always allocate at least client max message */
657 dev->me_clients[i].props.max_msg_length); 661 length = max_t(size_t, length, dev->me_clients[i].props.max_msg_length);
662 rets = mei_io_cb_alloc_resp_buf(cb, length);
658 if (rets) 663 if (rets)
659 goto err; 664 goto err;
660 665
@@ -677,6 +682,111 @@ err:
677} 682}
678 683
679/** 684/**
685 * mei_cl_write - submit a write cb to mei device
686 assumes device_lock is locked
687 *
688 * @cl: host client
689 * @cl: write callback with filled data
690 *
691 * returns numbe of bytes sent on success, <0 on failure.
692 */
693int mei_cl_write(struct mei_cl *cl, struct mei_cl_cb *cb, bool blocking)
694{
695 struct mei_device *dev;
696 struct mei_msg_data *buf;
697 struct mei_msg_hdr mei_hdr;
698 int rets;
699
700
701 if (WARN_ON(!cl || !cl->dev))
702 return -ENODEV;
703
704 if (WARN_ON(!cb))
705 return -EINVAL;
706
707 dev = cl->dev;
708
709
710 buf = &cb->request_buffer;
711
712 dev_dbg(&dev->pdev->dev, "mei_cl_write %d\n", buf->size);
713
714
715 cb->fop_type = MEI_FOP_WRITE;
716
717 rets = mei_cl_flow_ctrl_creds(cl);
718 if (rets < 0)
719 goto err;
720
721 /* Host buffer is not ready, we queue the request */
722 if (rets == 0 || !dev->hbuf_is_ready) {
723 cb->buf_idx = 0;
724 /* unseting complete will enqueue the cb for write */
725 mei_hdr.msg_complete = 0;
726 cl->writing_state = MEI_WRITING;
727 rets = buf->size;
728 goto out;
729 }
730
731 dev->hbuf_is_ready = false;
732
733 /* Check for a maximum length */
734 if (buf->size > mei_hbuf_max_len(dev)) {
735 mei_hdr.length = mei_hbuf_max_len(dev);
736 mei_hdr.msg_complete = 0;
737 } else {
738 mei_hdr.length = buf->size;
739 mei_hdr.msg_complete = 1;
740 }
741
742 mei_hdr.host_addr = cl->host_client_id;
743 mei_hdr.me_addr = cl->me_client_id;
744 mei_hdr.reserved = 0;
745
746 dev_dbg(&dev->pdev->dev, "write " MEI_HDR_FMT "\n",
747 MEI_HDR_PRM(&mei_hdr));
748
749
750 if (mei_write_message(dev, &mei_hdr, buf->data)) {
751 rets = -EIO;
752 goto err;
753 }
754
755 cl->writing_state = MEI_WRITING;
756 cb->buf_idx = mei_hdr.length;
757
758 rets = buf->size;
759out:
760 if (mei_hdr.msg_complete) {
761 if (mei_cl_flow_ctrl_reduce(cl)) {
762 rets = -ENODEV;
763 goto err;
764 }
765 list_add_tail(&cb->list, &dev->write_waiting_list.list);
766 } else {
767 list_add_tail(&cb->list, &dev->write_list.list);
768 }
769
770
771 if (blocking && cl->writing_state != MEI_WRITE_COMPLETE) {
772
773 mutex_unlock(&dev->device_lock);
774 if (wait_event_interruptible(cl->tx_wait,
775 cl->writing_state == MEI_WRITE_COMPLETE)) {
776 if (signal_pending(current))
777 rets = -EINTR;
778 else
779 rets = -ERESTARTSYS;
780 }
781 mutex_lock(&dev->device_lock);
782 }
783err:
784 return rets;
785}
786
787
788
789/**
680 * mei_cl_all_disconnect - disconnect forcefully all connected clients 790 * mei_cl_all_disconnect - disconnect forcefully all connected clients
681 * 791 *
682 * @dev - mei device 792 * @dev - mei device
diff --git a/drivers/misc/mei/client.h b/drivers/misc/mei/client.h
index 214b2397ec3e..cfdb144526aa 100644
--- a/drivers/misc/mei/client.h
+++ b/drivers/misc/mei/client.h
@@ -86,17 +86,16 @@ int mei_cl_flow_ctrl_reduce(struct mei_cl *cl);
86 */ 86 */
87bool mei_cl_is_other_connecting(struct mei_cl *cl); 87bool mei_cl_is_other_connecting(struct mei_cl *cl);
88int mei_cl_disconnect(struct mei_cl *cl); 88int mei_cl_disconnect(struct mei_cl *cl);
89
90int mei_cl_read_start(struct mei_cl *cl);
91
92int mei_cl_connect(struct mei_cl *cl, struct file *file); 89int mei_cl_connect(struct mei_cl *cl, struct file *file);
90int mei_cl_read_start(struct mei_cl *cl, size_t length);
91int mei_cl_write(struct mei_cl *cl, struct mei_cl_cb *cb, bool blocking);
93 92
94void mei_host_client_init(struct work_struct *work); 93void mei_host_client_init(struct work_struct *work);
95 94
96 95
96
97void mei_cl_all_disconnect(struct mei_device *dev); 97void mei_cl_all_disconnect(struct mei_device *dev);
98void mei_cl_all_read_wakeup(struct mei_device *dev); 98void mei_cl_all_read_wakeup(struct mei_device *dev);
99void mei_cl_all_write_clear(struct mei_device *dev); 99void mei_cl_all_write_clear(struct mei_device *dev);
100 100
101
102#endif /* _MEI_CLIENT_H_ */ 101#endif /* _MEI_CLIENT_H_ */
diff --git a/drivers/misc/mei/debugfs.c b/drivers/misc/mei/debugfs.c
new file mode 100644
index 000000000000..e3870f22d238
--- /dev/null
+++ b/drivers/misc/mei/debugfs.c
@@ -0,0 +1,143 @@
1/*
2 *
3 * Intel Management Engine Interface (Intel MEI) Linux driver
4 * Copyright (c) 2012-2013, Intel Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 */
16#include <linux/slab.h>
17#include <linux/kernel.h>
18#include <linux/device.h>
19#include <linux/debugfs.h>
20#include <linux/pci.h>
21
22#include <linux/mei.h>
23
24#include "mei_dev.h"
25#include "hw.h"
26
27static ssize_t mei_dbgfs_read_meclients(struct file *fp, char __user *ubuf,
28 size_t cnt, loff_t *ppos)
29{
30 struct mei_device *dev = fp->private_data;
31 struct mei_me_client *cl;
32 const size_t bufsz = 1024;
33 char *buf = kzalloc(bufsz, GFP_KERNEL);
34 int i;
35 int pos = 0;
36 int ret;
37
38 if (!buf)
39 return -ENOMEM;
40
41 pos += scnprintf(buf + pos, bufsz - pos,
42 " |id|addr| UUID |con|msg len|\n");
43
44 mutex_lock(&dev->device_lock);
45
46 /* if the driver is not enabled the list won't b consitent */
47 if (dev->dev_state != MEI_DEV_ENABLED)
48 goto out;
49
50 for (i = 0; i < dev->me_clients_num; i++) {
51 cl = &dev->me_clients[i];
52
53 /* skip me clients that cannot be connected */
54 if (cl->props.max_number_of_connections == 0)
55 continue;
56
57 pos += scnprintf(buf + pos, bufsz - pos,
58 "%2d|%2d|%4d|%pUl|%3d|%7d|\n",
59 i, cl->client_id,
60 cl->props.fixed_address,
61 &cl->props.protocol_name,
62 cl->props.max_number_of_connections,
63 cl->props.max_msg_length);
64 }
65out:
66 mutex_unlock(&dev->device_lock);
67 ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, pos);
68 kfree(buf);
69 return ret;
70}
71
72static const struct file_operations mei_dbgfs_fops_meclients = {
73 .open = simple_open,
74 .read = mei_dbgfs_read_meclients,
75 .llseek = generic_file_llseek,
76};
77
78static ssize_t mei_dbgfs_read_devstate(struct file *fp, char __user *ubuf,
79 size_t cnt, loff_t *ppos)
80{
81 struct mei_device *dev = fp->private_data;
82 const size_t bufsz = 1024;
83 char *buf = kzalloc(bufsz, GFP_KERNEL);
84 int pos = 0;
85 int ret;
86
87 if (!buf)
88 return -ENOMEM;
89
90 pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
91 mei_dev_state_str(dev->dev_state));
92 ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, pos);
93 kfree(buf);
94 return ret;
95}
96static const struct file_operations mei_dbgfs_fops_devstate = {
97 .open = simple_open,
98 .read = mei_dbgfs_read_devstate,
99 .llseek = generic_file_llseek,
100};
101
102/**
103 * mei_dbgfs_deregister - Remove the debugfs files and directories
104 * @mei - pointer to mei device private dat
105 */
106void mei_dbgfs_deregister(struct mei_device *dev)
107{
108 if (!dev->dbgfs_dir)
109 return;
110 debugfs_remove_recursive(dev->dbgfs_dir);
111 dev->dbgfs_dir = NULL;
112}
113
114/**
115 * Add the debugfs files
116 *
117 */
118int mei_dbgfs_register(struct mei_device *dev, const char *name)
119{
120 struct dentry *dir, *f;
121 dir = debugfs_create_dir(name, NULL);
122 if (!dir)
123 return -ENOMEM;
124
125 f = debugfs_create_file("meclients", S_IRUSR, dir,
126 dev, &mei_dbgfs_fops_meclients);
127 if (!f) {
128 dev_err(&dev->pdev->dev, "meclients: registration failed\n");
129 goto err;
130 }
131 f = debugfs_create_file("devstate", S_IRUSR, dir,
132 dev, &mei_dbgfs_fops_devstate);
133 if (!f) {
134 dev_err(&dev->pdev->dev, "devstate: registration failed\n");
135 goto err;
136 }
137 dev->dbgfs_dir = dir;
138 return 0;
139err:
140 mei_dbgfs_deregister(dev);
141 return -ENODEV;
142}
143
diff --git a/drivers/misc/mei/hbm.c b/drivers/misc/mei/hbm.c
index fb9e63ba3bb1..db605f5cf187 100644
--- a/drivers/misc/mei/hbm.c
+++ b/drivers/misc/mei/hbm.c
@@ -52,7 +52,7 @@ static void mei_hbm_me_cl_allocate(struct mei_device *dev)
52 sizeof(struct mei_me_client), GFP_KERNEL); 52 sizeof(struct mei_me_client), GFP_KERNEL);
53 if (!clients) { 53 if (!clients) {
54 dev_err(&dev->pdev->dev, "memory allocation for ME clients failed.\n"); 54 dev_err(&dev->pdev->dev, "memory allocation for ME clients failed.\n");
55 dev->dev_state = MEI_DEV_RESETING; 55 dev->dev_state = MEI_DEV_RESETTING;
56 mei_reset(dev, 1); 56 mei_reset(dev, 1);
57 return; 57 return;
58 } 58 }
@@ -123,12 +123,33 @@ static bool is_treat_specially_client(struct mei_cl *cl,
123 return false; 123 return false;
124} 124}
125 125
126int mei_hbm_start_wait(struct mei_device *dev)
127{
128 int ret;
129 if (dev->hbm_state > MEI_HBM_START)
130 return 0;
131
132 mutex_unlock(&dev->device_lock);
133 ret = wait_event_interruptible_timeout(dev->wait_recvd_msg,
134 dev->hbm_state == MEI_HBM_IDLE ||
135 dev->hbm_state > MEI_HBM_START,
136 mei_secs_to_jiffies(MEI_INTEROP_TIMEOUT));
137 mutex_lock(&dev->device_lock);
138
139 if (ret <= 0 && (dev->hbm_state <= MEI_HBM_START)) {
140 dev->hbm_state = MEI_HBM_IDLE;
141 dev_err(&dev->pdev->dev, "wating for mei start failed\n");
142 return -ETIMEDOUT;
143 }
144 return 0;
145}
146
126/** 147/**
127 * mei_hbm_start_req - sends start request message. 148 * mei_hbm_start_req - sends start request message.
128 * 149 *
129 * @dev: the device structure 150 * @dev: the device structure
130 */ 151 */
131void mei_hbm_start_req(struct mei_device *dev) 152int mei_hbm_start_req(struct mei_device *dev)
132{ 153{
133 struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr; 154 struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;
134 struct hbm_host_version_request *start_req; 155 struct hbm_host_version_request *start_req;
@@ -143,18 +164,19 @@ void mei_hbm_start_req(struct mei_device *dev)
143 start_req->host_version.major_version = HBM_MAJOR_VERSION; 164 start_req->host_version.major_version = HBM_MAJOR_VERSION;
144 start_req->host_version.minor_version = HBM_MINOR_VERSION; 165 start_req->host_version.minor_version = HBM_MINOR_VERSION;
145 166
146 dev->recvd_msg = false; 167 dev->hbm_state = MEI_HBM_IDLE;
147 if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) { 168 if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) {
148 dev_dbg(&dev->pdev->dev, "write send version message to FW fail.\n"); 169 dev_err(&dev->pdev->dev, "version message writet failed\n");
149 dev->dev_state = MEI_DEV_RESETING; 170 dev->dev_state = MEI_DEV_RESETTING;
150 mei_reset(dev, 1); 171 mei_reset(dev, 1);
172 return -ENODEV;
151 } 173 }
152 dev->init_clients_state = MEI_START_MESSAGE; 174 dev->hbm_state = MEI_HBM_START;
153 dev->init_clients_timer = MEI_CLIENTS_INIT_TIMEOUT; 175 dev->init_clients_timer = MEI_CLIENTS_INIT_TIMEOUT;
154 return ; 176 return 0;
155} 177}
156 178
157/** 179/*
158 * mei_hbm_enum_clients_req - sends enumeration client request message. 180 * mei_hbm_enum_clients_req - sends enumeration client request message.
159 * 181 *
160 * @dev: the device structure 182 * @dev: the device structure
@@ -174,11 +196,11 @@ static void mei_hbm_enum_clients_req(struct mei_device *dev)
174 enum_req->hbm_cmd = HOST_ENUM_REQ_CMD; 196 enum_req->hbm_cmd = HOST_ENUM_REQ_CMD;
175 197
176 if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) { 198 if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) {
177 dev->dev_state = MEI_DEV_RESETING; 199 dev->dev_state = MEI_DEV_RESETTING;
178 dev_dbg(&dev->pdev->dev, "write send enumeration request message to FW fail.\n"); 200 dev_err(&dev->pdev->dev, "enumeration request write failed.\n");
179 mei_reset(dev, 1); 201 mei_reset(dev, 1);
180 } 202 }
181 dev->init_clients_state = MEI_ENUM_CLIENTS_MESSAGE; 203 dev->hbm_state = MEI_HBM_ENUM_CLIENTS;
182 dev->init_clients_timer = MEI_CLIENTS_INIT_TIMEOUT; 204 dev->init_clients_timer = MEI_CLIENTS_INIT_TIMEOUT;
183 return; 205 return;
184} 206}
@@ -208,6 +230,7 @@ static int mei_hbm_prop_req(struct mei_device *dev)
208 230
209 /* We got all client properties */ 231 /* We got all client properties */
210 if (next_client_index == MEI_CLIENTS_MAX) { 232 if (next_client_index == MEI_CLIENTS_MAX) {
233 dev->hbm_state = MEI_HBM_STARTED;
211 schedule_work(&dev->init_work); 234 schedule_work(&dev->init_work);
212 235
213 return 0; 236 return 0;
@@ -226,8 +249,8 @@ static int mei_hbm_prop_req(struct mei_device *dev)
226 prop_req->address = next_client_index; 249 prop_req->address = next_client_index;
227 250
228 if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) { 251 if (mei_write_message(dev, mei_hdr, dev->wr_msg.data)) {
229 dev->dev_state = MEI_DEV_RESETING; 252 dev->dev_state = MEI_DEV_RESETTING;
230 dev_err(&dev->pdev->dev, "Properties request command failed\n"); 253 dev_err(&dev->pdev->dev, "properties request write failed\n");
231 mei_reset(dev, 1); 254 mei_reset(dev, 1);
232 255
233 return -EIO; 256 return -EIO;
@@ -542,27 +565,28 @@ void mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr)
542 dev->version = version_res->me_max_version; 565 dev->version = version_res->me_max_version;
543 dev_dbg(&dev->pdev->dev, "version mismatch.\n"); 566 dev_dbg(&dev->pdev->dev, "version mismatch.\n");
544 567
568 dev->hbm_state = MEI_HBM_STOP;
545 mei_hbm_stop_req_prepare(dev, &dev->wr_msg.hdr, 569 mei_hbm_stop_req_prepare(dev, &dev->wr_msg.hdr,
546 dev->wr_msg.data); 570 dev->wr_msg.data);
547 mei_write_message(dev, &dev->wr_msg.hdr, 571 mei_write_message(dev, &dev->wr_msg.hdr,
548 dev->wr_msg.data); 572 dev->wr_msg.data);
573
549 return; 574 return;
550 } 575 }
551 576
552 dev->version.major_version = HBM_MAJOR_VERSION; 577 dev->version.major_version = HBM_MAJOR_VERSION;
553 dev->version.minor_version = HBM_MINOR_VERSION; 578 dev->version.minor_version = HBM_MINOR_VERSION;
554 if (dev->dev_state == MEI_DEV_INIT_CLIENTS && 579 if (dev->dev_state == MEI_DEV_INIT_CLIENTS &&
555 dev->init_clients_state == MEI_START_MESSAGE) { 580 dev->hbm_state == MEI_HBM_START) {
556 dev->init_clients_timer = 0; 581 dev->init_clients_timer = 0;
557 mei_hbm_enum_clients_req(dev); 582 mei_hbm_enum_clients_req(dev);
558 } else { 583 } else {
559 dev->recvd_msg = false; 584 dev_err(&dev->pdev->dev, "reset: wrong host start response\n");
560 dev_dbg(&dev->pdev->dev, "reset due to received hbm: host start\n");
561 mei_reset(dev, 1); 585 mei_reset(dev, 1);
562 return; 586 return;
563 } 587 }
564 588
565 dev->recvd_msg = true; 589 wake_up_interruptible(&dev->wait_recvd_msg);
566 dev_dbg(&dev->pdev->dev, "host start response message received.\n"); 590 dev_dbg(&dev->pdev->dev, "host start response message received.\n");
567 break; 591 break;
568 592
@@ -591,23 +615,20 @@ void mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr)
591 me_client = &dev->me_clients[dev->me_client_presentation_num]; 615 me_client = &dev->me_clients[dev->me_client_presentation_num];
592 616
593 if (props_res->status || !dev->me_clients) { 617 if (props_res->status || !dev->me_clients) {
594 dev_dbg(&dev->pdev->dev, "reset due to received host client properties response bus message wrong status.\n"); 618 dev_err(&dev->pdev->dev, "reset: properties response hbm wrong status.\n");
595 mei_reset(dev, 1); 619 mei_reset(dev, 1);
596 return; 620 return;
597 } 621 }
598 622
599 if (me_client->client_id != props_res->address) { 623 if (me_client->client_id != props_res->address) {
600 dev_err(&dev->pdev->dev, 624 dev_err(&dev->pdev->dev, "reset: host properties response address mismatch\n");
601 "Host client properties reply mismatch\n");
602 mei_reset(dev, 1); 625 mei_reset(dev, 1);
603
604 return; 626 return;
605 } 627 }
606 628
607 if (dev->dev_state != MEI_DEV_INIT_CLIENTS || 629 if (dev->dev_state != MEI_DEV_INIT_CLIENTS ||
608 dev->init_clients_state != MEI_CLIENT_PROPERTIES_MESSAGE) { 630 dev->hbm_state != MEI_HBM_CLIENT_PROPERTIES) {
609 dev_err(&dev->pdev->dev, 631 dev_err(&dev->pdev->dev, "reset: unexpected properties response\n");
610 "Unexpected client properties reply\n");
611 mei_reset(dev, 1); 632 mei_reset(dev, 1);
612 633
613 return; 634 return;
@@ -626,26 +647,28 @@ void mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr)
626 enum_res = (struct hbm_host_enum_response *) mei_msg; 647 enum_res = (struct hbm_host_enum_response *) mei_msg;
627 memcpy(dev->me_clients_map, enum_res->valid_addresses, 32); 648 memcpy(dev->me_clients_map, enum_res->valid_addresses, 32);
628 if (dev->dev_state == MEI_DEV_INIT_CLIENTS && 649 if (dev->dev_state == MEI_DEV_INIT_CLIENTS &&
629 dev->init_clients_state == MEI_ENUM_CLIENTS_MESSAGE) { 650 dev->hbm_state == MEI_HBM_ENUM_CLIENTS) {
630 dev->init_clients_timer = 0; 651 dev->init_clients_timer = 0;
631 dev->me_client_presentation_num = 0; 652 dev->me_client_presentation_num = 0;
632 dev->me_client_index = 0; 653 dev->me_client_index = 0;
633 mei_hbm_me_cl_allocate(dev); 654 mei_hbm_me_cl_allocate(dev);
634 dev->init_clients_state = 655 dev->hbm_state = MEI_HBM_CLIENT_PROPERTIES;
635 MEI_CLIENT_PROPERTIES_MESSAGE;
636 656
637 /* first property reqeust */ 657 /* first property reqeust */
638 mei_hbm_prop_req(dev); 658 mei_hbm_prop_req(dev);
639 } else { 659 } else {
640 dev_dbg(&dev->pdev->dev, "reset due to received host enumeration clients response bus message.\n"); 660 dev_err(&dev->pdev->dev, "reset: unexpected enumeration response hbm.\n");
641 mei_reset(dev, 1); 661 mei_reset(dev, 1);
642 return; 662 return;
643 } 663 }
644 break; 664 break;
645 665
646 case HOST_STOP_RES_CMD: 666 case HOST_STOP_RES_CMD:
667
668 if (dev->hbm_state != MEI_HBM_STOP)
669 dev_err(&dev->pdev->dev, "unexpected stop response hbm.\n");
647 dev->dev_state = MEI_DEV_DISABLED; 670 dev->dev_state = MEI_DEV_DISABLED;
648 dev_dbg(&dev->pdev->dev, "resetting because of FW stop response.\n"); 671 dev_info(&dev->pdev->dev, "reset: FW stop response.\n");
649 mei_reset(dev, 1); 672 mei_reset(dev, 1);
650 break; 673 break;
651 674
@@ -657,6 +680,7 @@ void mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr)
657 680
658 case ME_STOP_REQ_CMD: 681 case ME_STOP_REQ_CMD:
659 682
683 dev->hbm_state = MEI_HBM_STOP;
660 mei_hbm_stop_req_prepare(dev, &dev->wr_ext_msg.hdr, 684 mei_hbm_stop_req_prepare(dev, &dev->wr_ext_msg.hdr,
661 dev->wr_ext_msg.data); 685 dev->wr_ext_msg.data);
662 break; 686 break;
diff --git a/drivers/misc/mei/hbm.h b/drivers/misc/mei/hbm.h
index b552afbaf85c..e80dc24ef3e2 100644
--- a/drivers/misc/mei/hbm.h
+++ b/drivers/misc/mei/hbm.h
@@ -17,6 +17,27 @@
17#ifndef _MEI_HBM_H_ 17#ifndef _MEI_HBM_H_
18#define _MEI_HBM_H_ 18#define _MEI_HBM_H_
19 19
20struct mei_device;
21struct mei_msg_hdr;
22struct mei_cl;
23
24/**
25 * enum mei_hbm_state - host bus message protocol state
26 *
27 * @MEI_HBM_IDLE : protocol not started
28 * @MEI_HBM_START : start request message was sent
29 * @MEI_HBM_ENUM_CLIENTS : enumeration request was sent
30 * @MEI_HBM_CLIENT_PROPERTIES : acquiring clients properties
31 */
32enum mei_hbm_state {
33 MEI_HBM_IDLE = 0,
34 MEI_HBM_START,
35 MEI_HBM_ENUM_CLIENTS,
36 MEI_HBM_CLIENT_PROPERTIES,
37 MEI_HBM_STARTED,
38 MEI_HBM_STOP,
39};
40
20void mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr); 41void mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr);
21 42
22static inline void mei_hbm_hdr(struct mei_msg_hdr *hdr, size_t length) 43static inline void mei_hbm_hdr(struct mei_msg_hdr *hdr, size_t length)
@@ -28,8 +49,8 @@ static inline void mei_hbm_hdr(struct mei_msg_hdr *hdr, size_t length)
28 hdr->reserved = 0; 49 hdr->reserved = 0;
29} 50}
30 51
31void mei_hbm_start_req(struct mei_device *dev); 52int mei_hbm_start_req(struct mei_device *dev);
32 53int mei_hbm_start_wait(struct mei_device *dev);
33int mei_hbm_cl_flow_control_req(struct mei_device *dev, struct mei_cl *cl); 54int mei_hbm_cl_flow_control_req(struct mei_device *dev, struct mei_cl *cl);
34int mei_hbm_cl_disconnect_req(struct mei_device *dev, struct mei_cl *cl); 55int mei_hbm_cl_disconnect_req(struct mei_device *dev, struct mei_cl *cl);
35int mei_hbm_cl_connect_req(struct mei_device *dev, struct mei_cl *cl); 56int mei_hbm_cl_connect_req(struct mei_device *dev, struct mei_cl *cl);
diff --git a/drivers/misc/mei/hw-me.c b/drivers/misc/mei/hw-me.c
index 642c6223fa6c..fc032270916a 100644
--- a/drivers/misc/mei/hw-me.c
+++ b/drivers/misc/mei/hw-me.c
@@ -26,14 +26,14 @@
26 26
27 27
28/** 28/**
29 * mei_reg_read - Reads 32bit data from the mei device 29 * mei_me_reg_read - Reads 32bit data from the mei device
30 * 30 *
31 * @dev: the device structure 31 * @dev: the device structure
32 * @offset: offset from which to read the data 32 * @offset: offset from which to read the data
33 * 33 *
34 * returns register value (u32) 34 * returns register value (u32)
35 */ 35 */
36static inline u32 mei_reg_read(const struct mei_me_hw *hw, 36static inline u32 mei_me_reg_read(const struct mei_me_hw *hw,
37 unsigned long offset) 37 unsigned long offset)
38{ 38{
39 return ioread32(hw->mem_addr + offset); 39 return ioread32(hw->mem_addr + offset);
@@ -41,20 +41,20 @@ static inline u32 mei_reg_read(const struct mei_me_hw *hw,
41 41
42 42
43/** 43/**
44 * mei_reg_write - Writes 32bit data to the mei device 44 * mei_me_reg_write - Writes 32bit data to the mei device
45 * 45 *
46 * @dev: the device structure 46 * @dev: the device structure
47 * @offset: offset from which to write the data 47 * @offset: offset from which to write the data
48 * @value: register value to write (u32) 48 * @value: register value to write (u32)
49 */ 49 */
50static inline void mei_reg_write(const struct mei_me_hw *hw, 50static inline void mei_me_reg_write(const struct mei_me_hw *hw,
51 unsigned long offset, u32 value) 51 unsigned long offset, u32 value)
52{ 52{
53 iowrite32(value, hw->mem_addr + offset); 53 iowrite32(value, hw->mem_addr + offset);
54} 54}
55 55
56/** 56/**
57 * mei_mecbrw_read - Reads 32bit data from ME circular buffer 57 * mei_me_mecbrw_read - Reads 32bit data from ME circular buffer
58 * read window register 58 * read window register
59 * 59 *
60 * @dev: the device structure 60 * @dev: the device structure
@@ -63,18 +63,18 @@ static inline void mei_reg_write(const struct mei_me_hw *hw,
63 */ 63 */
64static u32 mei_me_mecbrw_read(const struct mei_device *dev) 64static u32 mei_me_mecbrw_read(const struct mei_device *dev)
65{ 65{
66 return mei_reg_read(to_me_hw(dev), ME_CB_RW); 66 return mei_me_reg_read(to_me_hw(dev), ME_CB_RW);
67} 67}
68/** 68/**
69 * mei_mecsr_read - Reads 32bit data from the ME CSR 69 * mei_me_mecsr_read - Reads 32bit data from the ME CSR
70 * 70 *
71 * @dev: the device structure 71 * @dev: the device structure
72 * 72 *
73 * returns ME_CSR_HA register value (u32) 73 * returns ME_CSR_HA register value (u32)
74 */ 74 */
75static inline u32 mei_mecsr_read(const struct mei_me_hw *hw) 75static inline u32 mei_me_mecsr_read(const struct mei_me_hw *hw)
76{ 76{
77 return mei_reg_read(hw, ME_CSR_HA); 77 return mei_me_reg_read(hw, ME_CSR_HA);
78} 78}
79 79
80/** 80/**
@@ -86,7 +86,7 @@ static inline u32 mei_mecsr_read(const struct mei_me_hw *hw)
86 */ 86 */
87static inline u32 mei_hcsr_read(const struct mei_me_hw *hw) 87static inline u32 mei_hcsr_read(const struct mei_me_hw *hw)
88{ 88{
89 return mei_reg_read(hw, H_CSR); 89 return mei_me_reg_read(hw, H_CSR);
90} 90}
91 91
92/** 92/**
@@ -98,7 +98,7 @@ static inline u32 mei_hcsr_read(const struct mei_me_hw *hw)
98static inline void mei_hcsr_set(struct mei_me_hw *hw, u32 hcsr) 98static inline void mei_hcsr_set(struct mei_me_hw *hw, u32 hcsr)
99{ 99{
100 hcsr &= ~H_IS; 100 hcsr &= ~H_IS;
101 mei_reg_write(hw, H_CSR, hcsr); 101 mei_me_reg_write(hw, H_CSR, hcsr);
102} 102}
103 103
104 104
@@ -123,7 +123,7 @@ static void mei_me_intr_clear(struct mei_device *dev)
123 struct mei_me_hw *hw = to_me_hw(dev); 123 struct mei_me_hw *hw = to_me_hw(dev);
124 u32 hcsr = mei_hcsr_read(hw); 124 u32 hcsr = mei_hcsr_read(hw);
125 if ((hcsr & H_IS) == H_IS) 125 if ((hcsr & H_IS) == H_IS)
126 mei_reg_write(hw, H_CSR, hcsr); 126 mei_me_reg_write(hw, H_CSR, hcsr);
127} 127}
128/** 128/**
129 * mei_me_intr_enable - enables mei device interrupts 129 * mei_me_intr_enable - enables mei device interrupts
@@ -228,10 +228,42 @@ static bool mei_me_host_is_ready(struct mei_device *dev)
228static bool mei_me_hw_is_ready(struct mei_device *dev) 228static bool mei_me_hw_is_ready(struct mei_device *dev)
229{ 229{
230 struct mei_me_hw *hw = to_me_hw(dev); 230 struct mei_me_hw *hw = to_me_hw(dev);
231 hw->me_hw_state = mei_mecsr_read(hw); 231 hw->me_hw_state = mei_me_mecsr_read(hw);
232 return (hw->me_hw_state & ME_RDY_HRA) == ME_RDY_HRA; 232 return (hw->me_hw_state & ME_RDY_HRA) == ME_RDY_HRA;
233} 233}
234 234
235static int mei_me_hw_ready_wait(struct mei_device *dev)
236{
237 int err;
238 if (mei_me_hw_is_ready(dev))
239 return 0;
240
241 mutex_unlock(&dev->device_lock);
242 err = wait_event_interruptible_timeout(dev->wait_hw_ready,
243 dev->recvd_hw_ready, MEI_INTEROP_TIMEOUT);
244 mutex_lock(&dev->device_lock);
245 if (!err && !dev->recvd_hw_ready) {
246 dev_err(&dev->pdev->dev,
247 "wait hw ready failed. status = 0x%x\n", err);
248 return -ETIMEDOUT;
249 }
250
251 dev->recvd_hw_ready = false;
252 return 0;
253}
254
255static int mei_me_hw_start(struct mei_device *dev)
256{
257 int ret = mei_me_hw_ready_wait(dev);
258 if (ret)
259 return ret;
260 dev_dbg(&dev->pdev->dev, "hw is ready\n");
261
262 mei_me_host_set_ready(dev);
263 return ret;
264}
265
266
235/** 267/**
236 * mei_hbuf_filled_slots - gets number of device filled buffer slots 268 * mei_hbuf_filled_slots - gets number of device filled buffer slots
237 * 269 *
@@ -305,10 +337,11 @@ static int mei_me_write_message(struct mei_device *dev,
305 unsigned char *buf) 337 unsigned char *buf)
306{ 338{
307 struct mei_me_hw *hw = to_me_hw(dev); 339 struct mei_me_hw *hw = to_me_hw(dev);
308 unsigned long rem, dw_cnt; 340 unsigned long rem;
309 unsigned long length = header->length; 341 unsigned long length = header->length;
310 u32 *reg_buf = (u32 *)buf; 342 u32 *reg_buf = (u32 *)buf;
311 u32 hcsr; 343 u32 hcsr;
344 u32 dw_cnt;
312 int i; 345 int i;
313 int empty_slots; 346 int empty_slots;
314 347
@@ -321,16 +354,16 @@ static int mei_me_write_message(struct mei_device *dev,
321 if (empty_slots < 0 || dw_cnt > empty_slots) 354 if (empty_slots < 0 || dw_cnt > empty_slots)
322 return -EIO; 355 return -EIO;
323 356
324 mei_reg_write(hw, H_CB_WW, *((u32 *) header)); 357 mei_me_reg_write(hw, H_CB_WW, *((u32 *) header));
325 358
326 for (i = 0; i < length / 4; i++) 359 for (i = 0; i < length / 4; i++)
327 mei_reg_write(hw, H_CB_WW, reg_buf[i]); 360 mei_me_reg_write(hw, H_CB_WW, reg_buf[i]);
328 361
329 rem = length & 0x3; 362 rem = length & 0x3;
330 if (rem > 0) { 363 if (rem > 0) {
331 u32 reg = 0; 364 u32 reg = 0;
332 memcpy(&reg, &buf[length - rem], rem); 365 memcpy(&reg, &buf[length - rem], rem);
333 mei_reg_write(hw, H_CB_WW, reg); 366 mei_me_reg_write(hw, H_CB_WW, reg);
334 } 367 }
335 368
336 hcsr = mei_hcsr_read(hw) | H_IG; 369 hcsr = mei_hcsr_read(hw) | H_IG;
@@ -354,7 +387,7 @@ static int mei_me_count_full_read_slots(struct mei_device *dev)
354 char read_ptr, write_ptr; 387 char read_ptr, write_ptr;
355 unsigned char buffer_depth, filled_slots; 388 unsigned char buffer_depth, filled_slots;
356 389
357 hw->me_hw_state = mei_mecsr_read(hw); 390 hw->me_hw_state = mei_me_mecsr_read(hw);
358 buffer_depth = (unsigned char)((hw->me_hw_state & ME_CBD_HRA) >> 24); 391 buffer_depth = (unsigned char)((hw->me_hw_state & ME_CBD_HRA) >> 24);
359 read_ptr = (char) ((hw->me_hw_state & ME_CBRP_HRA) >> 8); 392 read_ptr = (char) ((hw->me_hw_state & ME_CBRP_HRA) >> 8);
360 write_ptr = (char) ((hw->me_hw_state & ME_CBWP_HRA) >> 16); 393 write_ptr = (char) ((hw->me_hw_state & ME_CBWP_HRA) >> 16);
@@ -414,7 +447,7 @@ irqreturn_t mei_me_irq_quick_handler(int irq, void *dev_id)
414 return IRQ_NONE; 447 return IRQ_NONE;
415 448
416 /* clear H_IS bit in H_CSR */ 449 /* clear H_IS bit in H_CSR */
417 mei_reg_write(hw, H_CSR, csr_reg); 450 mei_me_reg_write(hw, H_CSR, csr_reg);
418 451
419 return IRQ_WAKE_THREAD; 452 return IRQ_WAKE_THREAD;
420} 453}
@@ -433,12 +466,8 @@ irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id)
433{ 466{
434 struct mei_device *dev = (struct mei_device *) dev_id; 467 struct mei_device *dev = (struct mei_device *) dev_id;
435 struct mei_cl_cb complete_list; 468 struct mei_cl_cb complete_list;
436 struct mei_cl_cb *cb_pos = NULL, *cb_next = NULL;
437 struct mei_cl *cl;
438 s32 slots; 469 s32 slots;
439 int rets; 470 int rets;
440 bool bus_message_received;
441
442 471
443 dev_dbg(&dev->pdev->dev, "function called after ISR to handle the interrupt processing.\n"); 472 dev_dbg(&dev->pdev->dev, "function called after ISR to handle the interrupt processing.\n");
444 /* initialize our complete list */ 473 /* initialize our complete list */
@@ -452,7 +481,7 @@ irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id)
452 481
453 /* check if ME wants a reset */ 482 /* check if ME wants a reset */
454 if (!mei_hw_is_ready(dev) && 483 if (!mei_hw_is_ready(dev) &&
455 dev->dev_state != MEI_DEV_RESETING && 484 dev->dev_state != MEI_DEV_RESETTING &&
456 dev->dev_state != MEI_DEV_INITIALIZING) { 485 dev->dev_state != MEI_DEV_INITIALIZING) {
457 dev_dbg(&dev->pdev->dev, "FW not ready.\n"); 486 dev_dbg(&dev->pdev->dev, "FW not ready.\n");
458 mei_reset(dev, 1); 487 mei_reset(dev, 1);
@@ -465,14 +494,9 @@ irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id)
465 if (mei_hw_is_ready(dev)) { 494 if (mei_hw_is_ready(dev)) {
466 dev_dbg(&dev->pdev->dev, "we need to start the dev.\n"); 495 dev_dbg(&dev->pdev->dev, "we need to start the dev.\n");
467 496
468 mei_host_set_ready(dev); 497 dev->recvd_hw_ready = true;
498 wake_up_interruptible(&dev->wait_hw_ready);
469 499
470 dev_dbg(&dev->pdev->dev, "link is established start sending messages.\n");
471 /* link is established * start sending messages. */
472
473 dev->dev_state = MEI_DEV_INIT_CLIENTS;
474
475 mei_hbm_start_req(dev);
476 mutex_unlock(&dev->device_lock); 500 mutex_unlock(&dev->device_lock);
477 return IRQ_HANDLED; 501 return IRQ_HANDLED;
478 } else { 502 } else {
@@ -499,44 +523,20 @@ end:
499 dev_dbg(&dev->pdev->dev, "end of bottom half function.\n"); 523 dev_dbg(&dev->pdev->dev, "end of bottom half function.\n");
500 dev->hbuf_is_ready = mei_hbuf_is_ready(dev); 524 dev->hbuf_is_ready = mei_hbuf_is_ready(dev);
501 525
502 bus_message_received = false;
503 if (dev->recvd_msg && waitqueue_active(&dev->wait_recvd_msg)) {
504 dev_dbg(&dev->pdev->dev, "received waiting bus message\n");
505 bus_message_received = true;
506 }
507 mutex_unlock(&dev->device_lock); 526 mutex_unlock(&dev->device_lock);
508 if (bus_message_received) {
509 dev_dbg(&dev->pdev->dev, "wake up dev->wait_recvd_msg\n");
510 wake_up_interruptible(&dev->wait_recvd_msg);
511 bus_message_received = false;
512 }
513 if (list_empty(&complete_list.list))
514 return IRQ_HANDLED;
515 527
528 mei_irq_compl_handler(dev, &complete_list);
516 529
517 list_for_each_entry_safe(cb_pos, cb_next, &complete_list.list, list) {
518 cl = cb_pos->cl;
519 list_del(&cb_pos->list);
520 if (cl) {
521 if (cl != &dev->iamthif_cl) {
522 dev_dbg(&dev->pdev->dev, "completing call back.\n");
523 mei_irq_complete_handler(cl, cb_pos);
524 cb_pos = NULL;
525 } else if (cl == &dev->iamthif_cl) {
526 mei_amthif_complete(dev, cb_pos);
527 }
528 }
529 }
530 return IRQ_HANDLED; 530 return IRQ_HANDLED;
531} 531}
532static const struct mei_hw_ops mei_me_hw_ops = { 532static const struct mei_hw_ops mei_me_hw_ops = {
533 533
534 .host_set_ready = mei_me_host_set_ready,
535 .host_is_ready = mei_me_host_is_ready, 534 .host_is_ready = mei_me_host_is_ready,
536 535
537 .hw_is_ready = mei_me_hw_is_ready, 536 .hw_is_ready = mei_me_hw_is_ready,
538 .hw_reset = mei_me_hw_reset, 537 .hw_reset = mei_me_hw_reset,
539 .hw_config = mei_me_hw_config, 538 .hw_config = mei_me_hw_config,
539 .hw_start = mei_me_hw_start,
540 540
541 .intr_clear = mei_me_intr_clear, 541 .intr_clear = mei_me_intr_clear,
542 .intr_enable = mei_me_intr_enable, 542 .intr_enable = mei_me_intr_enable,
@@ -571,14 +571,6 @@ struct mei_device *mei_me_dev_init(struct pci_dev *pdev)
571 571
572 mei_device_init(dev); 572 mei_device_init(dev);
573 573
574 INIT_LIST_HEAD(&dev->wd_cl.link);
575 INIT_LIST_HEAD(&dev->iamthif_cl.link);
576 mei_io_list_init(&dev->amthif_cmd_list);
577 mei_io_list_init(&dev->amthif_rd_complete_list);
578
579 INIT_DELAYED_WORK(&dev->timer_work, mei_timer);
580 INIT_WORK(&dev->init_work, mei_host_client_init);
581
582 dev->ops = &mei_me_hw_ops; 574 dev->ops = &mei_me_hw_ops;
583 575
584 dev->pdev = pdev; 576 dev->pdev = pdev;
diff --git a/drivers/misc/mei/hw-me.h b/drivers/misc/mei/hw-me.h
index 8518d3eeb838..80bd829fbd9a 100644
--- a/drivers/misc/mei/hw-me.h
+++ b/drivers/misc/mei/hw-me.h
@@ -36,12 +36,6 @@ struct mei_me_hw {
36 36
37struct mei_device *mei_me_dev_init(struct pci_dev *pdev); 37struct mei_device *mei_me_dev_init(struct pci_dev *pdev);
38 38
39/* get slots (dwords) from a message length + header (bytes) */
40static inline unsigned char mei_data2slots(size_t length)
41{
42 return DIV_ROUND_UP(sizeof(struct mei_msg_hdr) + length, 4);
43}
44
45irqreturn_t mei_me_irq_quick_handler(int irq, void *dev_id); 39irqreturn_t mei_me_irq_quick_handler(int irq, void *dev_id);
46irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id); 40irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id);
47 41
diff --git a/drivers/misc/mei/init.c b/drivers/misc/mei/init.c
index 356179991a2e..713d89fedc46 100644
--- a/drivers/misc/mei/init.c
+++ b/drivers/misc/mei/init.c
@@ -14,6 +14,7 @@
14 * 14 *
15 */ 15 */
16 16
17#include <linux/export.h>
17#include <linux/pci.h> 18#include <linux/pci.h>
18#include <linux/sched.h> 19#include <linux/sched.h>
19#include <linux/wait.h> 20#include <linux/wait.h>
@@ -22,6 +23,7 @@
22#include <linux/mei.h> 23#include <linux/mei.h>
23 24
24#include "mei_dev.h" 25#include "mei_dev.h"
26#include "hbm.h"
25#include "client.h" 27#include "client.h"
26 28
27const char *mei_dev_state_str(int state) 29const char *mei_dev_state_str(int state)
@@ -31,9 +33,8 @@ const char *mei_dev_state_str(int state)
31 MEI_DEV_STATE(INITIALIZING); 33 MEI_DEV_STATE(INITIALIZING);
32 MEI_DEV_STATE(INIT_CLIENTS); 34 MEI_DEV_STATE(INIT_CLIENTS);
33 MEI_DEV_STATE(ENABLED); 35 MEI_DEV_STATE(ENABLED);
34 MEI_DEV_STATE(RESETING); 36 MEI_DEV_STATE(RESETTING);
35 MEI_DEV_STATE(DISABLED); 37 MEI_DEV_STATE(DISABLED);
36 MEI_DEV_STATE(RECOVERING_FROM_RESET);
37 MEI_DEV_STATE(POWER_DOWN); 38 MEI_DEV_STATE(POWER_DOWN);
38 MEI_DEV_STATE(POWER_UP); 39 MEI_DEV_STATE(POWER_UP);
39 default: 40 default:
@@ -46,7 +47,9 @@ void mei_device_init(struct mei_device *dev)
46{ 47{
47 /* setup our list array */ 48 /* setup our list array */
48 INIT_LIST_HEAD(&dev->file_list); 49 INIT_LIST_HEAD(&dev->file_list);
50 INIT_LIST_HEAD(&dev->device_list);
49 mutex_init(&dev->device_lock); 51 mutex_init(&dev->device_lock);
52 init_waitqueue_head(&dev->wait_hw_ready);
50 init_waitqueue_head(&dev->wait_recvd_msg); 53 init_waitqueue_head(&dev->wait_recvd_msg);
51 init_waitqueue_head(&dev->wait_stop_wd); 54 init_waitqueue_head(&dev->wait_stop_wd);
52 dev->dev_state = MEI_DEV_INITIALIZING; 55 dev->dev_state = MEI_DEV_INITIALIZING;
@@ -56,19 +59,27 @@ void mei_device_init(struct mei_device *dev)
56 mei_io_list_init(&dev->write_waiting_list); 59 mei_io_list_init(&dev->write_waiting_list);
57 mei_io_list_init(&dev->ctrl_wr_list); 60 mei_io_list_init(&dev->ctrl_wr_list);
58 mei_io_list_init(&dev->ctrl_rd_list); 61 mei_io_list_init(&dev->ctrl_rd_list);
62
63 INIT_DELAYED_WORK(&dev->timer_work, mei_timer);
64 INIT_WORK(&dev->init_work, mei_host_client_init);
65
66 INIT_LIST_HEAD(&dev->wd_cl.link);
67 INIT_LIST_HEAD(&dev->iamthif_cl.link);
68 mei_io_list_init(&dev->amthif_cmd_list);
69 mei_io_list_init(&dev->amthif_rd_complete_list);
70
59} 71}
72EXPORT_SYMBOL_GPL(mei_device_init);
60 73
61/** 74/**
62 * mei_hw_init - initializes host and fw to start work. 75 * mei_start - initializes host and fw to start work.
63 * 76 *
64 * @dev: the device structure 77 * @dev: the device structure
65 * 78 *
66 * returns 0 on success, <0 on failure. 79 * returns 0 on success, <0 on failure.
67 */ 80 */
68int mei_hw_init(struct mei_device *dev) 81int mei_start(struct mei_device *dev)
69{ 82{
70 int ret = 0;
71
72 mutex_lock(&dev->device_lock); 83 mutex_lock(&dev->device_lock);
73 84
74 /* acknowledge interrupt and stop interupts */ 85 /* acknowledge interrupt and stop interupts */
@@ -76,29 +87,15 @@ int mei_hw_init(struct mei_device *dev)
76 87
77 mei_hw_config(dev); 88 mei_hw_config(dev);
78 89
79 dev->recvd_msg = false;
80 dev_dbg(&dev->pdev->dev, "reset in start the mei device.\n"); 90 dev_dbg(&dev->pdev->dev, "reset in start the mei device.\n");
81 91
82 mei_reset(dev, 1); 92 mei_reset(dev, 1);
83 93
84 /* wait for ME to turn on ME_RDY */ 94 if (mei_hbm_start_wait(dev)) {
85 if (!dev->recvd_msg) { 95 dev_err(&dev->pdev->dev, "HBM haven't started");
86 mutex_unlock(&dev->device_lock);
87 ret = wait_event_interruptible_timeout(dev->wait_recvd_msg,
88 dev->recvd_msg,
89 mei_secs_to_jiffies(MEI_INTEROP_TIMEOUT));
90 mutex_lock(&dev->device_lock);
91 }
92
93 if (ret <= 0 && !dev->recvd_msg) {
94 dev->dev_state = MEI_DEV_DISABLED;
95 dev_dbg(&dev->pdev->dev,
96 "wait_event_interruptible_timeout failed"
97 "on wait for ME to turn on ME_RDY.\n");
98 goto err; 96 goto err;
99 } 97 }
100 98
101
102 if (!mei_host_is_ready(dev)) { 99 if (!mei_host_is_ready(dev)) {
103 dev_err(&dev->pdev->dev, "host is not ready.\n"); 100 dev_err(&dev->pdev->dev, "host is not ready.\n");
104 goto err; 101 goto err;
@@ -115,7 +112,6 @@ int mei_hw_init(struct mei_device *dev)
115 goto err; 112 goto err;
116 } 113 }
117 114
118 dev->recvd_msg = false;
119 dev_dbg(&dev->pdev->dev, "link layer has been established.\n"); 115 dev_dbg(&dev->pdev->dev, "link layer has been established.\n");
120 116
121 mutex_unlock(&dev->device_lock); 117 mutex_unlock(&dev->device_lock);
@@ -126,6 +122,7 @@ err:
126 mutex_unlock(&dev->device_lock); 122 mutex_unlock(&dev->device_lock);
127 return -ENODEV; 123 return -ENODEV;
128} 124}
125EXPORT_SYMBOL_GPL(mei_start);
129 126
130/** 127/**
131 * mei_reset - resets host and fw. 128 * mei_reset - resets host and fw.
@@ -137,9 +134,6 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled)
137{ 134{
138 bool unexpected; 135 bool unexpected;
139 136
140 if (dev->dev_state == MEI_DEV_RECOVERING_FROM_RESET)
141 return;
142
143 unexpected = (dev->dev_state != MEI_DEV_INITIALIZING && 137 unexpected = (dev->dev_state != MEI_DEV_INITIALIZING &&
144 dev->dev_state != MEI_DEV_DISABLED && 138 dev->dev_state != MEI_DEV_DISABLED &&
145 dev->dev_state != MEI_DEV_POWER_DOWN && 139 dev->dev_state != MEI_DEV_POWER_DOWN &&
@@ -147,11 +141,12 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled)
147 141
148 mei_hw_reset(dev, interrupts_enabled); 142 mei_hw_reset(dev, interrupts_enabled);
149 143
144 dev->hbm_state = MEI_HBM_IDLE;
150 145
151 if (dev->dev_state != MEI_DEV_INITIALIZING) { 146 if (dev->dev_state != MEI_DEV_INITIALIZING) {
152 if (dev->dev_state != MEI_DEV_DISABLED && 147 if (dev->dev_state != MEI_DEV_DISABLED &&
153 dev->dev_state != MEI_DEV_POWER_DOWN) 148 dev->dev_state != MEI_DEV_POWER_DOWN)
154 dev->dev_state = MEI_DEV_RESETING; 149 dev->dev_state = MEI_DEV_RESETTING;
155 150
156 mei_cl_all_disconnect(dev); 151 mei_cl_all_disconnect(dev);
157 152
@@ -176,12 +171,27 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled)
176 dev_warn(&dev->pdev->dev, "unexpected reset: dev_state = %s\n", 171 dev_warn(&dev->pdev->dev, "unexpected reset: dev_state = %s\n",
177 mei_dev_state_str(dev->dev_state)); 172 mei_dev_state_str(dev->dev_state));
178 173
174 if (!interrupts_enabled) {
175 dev_dbg(&dev->pdev->dev, "intr not enabled end of reset\n");
176 return;
177 }
178
179 mei_hw_start(dev);
180
181 dev_dbg(&dev->pdev->dev, "link is established start sending messages.\n");
182 /* link is established * start sending messages. */
183
184 dev->dev_state = MEI_DEV_INIT_CLIENTS;
185
186 mei_hbm_start_req(dev);
187
179 /* wake up all readings so they can be interrupted */ 188 /* wake up all readings so they can be interrupted */
180 mei_cl_all_read_wakeup(dev); 189 mei_cl_all_read_wakeup(dev);
181 190
182 /* remove all waiting requests */ 191 /* remove all waiting requests */
183 mei_cl_all_write_clear(dev); 192 mei_cl_all_write_clear(dev);
184} 193}
194EXPORT_SYMBOL_GPL(mei_reset);
185 195
186void mei_stop(struct mei_device *dev) 196void mei_stop(struct mei_device *dev)
187{ 197{
@@ -193,14 +203,18 @@ void mei_stop(struct mei_device *dev)
193 203
194 mei_wd_stop(dev); 204 mei_wd_stop(dev);
195 205
206 mei_nfc_host_exit();
207
196 dev->dev_state = MEI_DEV_POWER_DOWN; 208 dev->dev_state = MEI_DEV_POWER_DOWN;
197 mei_reset(dev, 0); 209 mei_reset(dev, 0);
198 210
199 mutex_unlock(&dev->device_lock); 211 mutex_unlock(&dev->device_lock);
200 212
201 flush_scheduled_work(); 213 flush_scheduled_work();
202}
203 214
215 mei_watchdog_unregister(dev);
216}
217EXPORT_SYMBOL_GPL(mei_stop);
204 218
205 219
206 220
diff --git a/drivers/misc/mei/interrupt.c b/drivers/misc/mei/interrupt.c
index 3535b2676c97..1473cfdbc426 100644
--- a/drivers/misc/mei/interrupt.c
+++ b/drivers/misc/mei/interrupt.c
@@ -15,6 +15,7 @@
15 */ 15 */
16 16
17 17
18#include <linux/export.h>
18#include <linux/pci.h> 19#include <linux/pci.h>
19#include <linux/kthread.h> 20#include <linux/kthread.h>
20#include <linux/interrupt.h> 21#include <linux/interrupt.h>
@@ -30,103 +31,153 @@
30 31
31 32
32/** 33/**
33 * mei_complete_handler - processes completed operation. 34 * mei_cl_complete_handler - processes completed operation for a client
34 * 35 *
35 * @cl: private data of the file object. 36 * @cl: private data of the file object.
36 * @cb_pos: callback block. 37 * @cb: callback block.
37 */ 38 */
38void mei_irq_complete_handler(struct mei_cl *cl, struct mei_cl_cb *cb_pos) 39static void mei_cl_complete_handler(struct mei_cl *cl, struct mei_cl_cb *cb)
39{ 40{
40 if (cb_pos->fop_type == MEI_FOP_WRITE) { 41 if (cb->fop_type == MEI_FOP_WRITE) {
41 mei_io_cb_free(cb_pos); 42 mei_io_cb_free(cb);
42 cb_pos = NULL; 43 cb = NULL;
43 cl->writing_state = MEI_WRITE_COMPLETE; 44 cl->writing_state = MEI_WRITE_COMPLETE;
44 if (waitqueue_active(&cl->tx_wait)) 45 if (waitqueue_active(&cl->tx_wait))
45 wake_up_interruptible(&cl->tx_wait); 46 wake_up_interruptible(&cl->tx_wait);
46 47
47 } else if (cb_pos->fop_type == MEI_FOP_READ && 48 } else if (cb->fop_type == MEI_FOP_READ &&
48 MEI_READING == cl->reading_state) { 49 MEI_READING == cl->reading_state) {
49 cl->reading_state = MEI_READ_COMPLETE; 50 cl->reading_state = MEI_READ_COMPLETE;
50 if (waitqueue_active(&cl->rx_wait)) 51 if (waitqueue_active(&cl->rx_wait))
51 wake_up_interruptible(&cl->rx_wait); 52 wake_up_interruptible(&cl->rx_wait);
53 else
54 mei_cl_bus_rx_event(cl);
55
56 }
57}
58
59/**
60 * mei_irq_compl_handler - dispatch complete handelers
61 * for the completed callbacks
62 *
63 * @dev - mei device
64 * @compl_list - list of completed cbs
65 */
66void mei_irq_compl_handler(struct mei_device *dev, struct mei_cl_cb *compl_list)
67{
68 struct mei_cl_cb *cb, *next;
69 struct mei_cl *cl;
70
71 list_for_each_entry_safe(cb, next, &compl_list->list, list) {
72 cl = cb->cl;
73 list_del(&cb->list);
74 if (!cl)
75 continue;
52 76
77 dev_dbg(&dev->pdev->dev, "completing call back.\n");
78 if (cl == &dev->iamthif_cl)
79 mei_amthif_complete(dev, cb);
80 else
81 mei_cl_complete_handler(cl, cb);
53 } 82 }
54} 83}
84EXPORT_SYMBOL_GPL(mei_irq_compl_handler);
55 85
56/** 86/**
57 * _mei_irq_thread_state_ok - checks if mei header matches file private data 87 * mei_cl_hbm_equal - check if hbm is addressed to the client
58 * 88 *
59 * @cl: private data of the file object 89 * @cl: host client
60 * @mei_hdr: header of mei client message 90 * @mei_hdr: header of mei client message
61 * 91 *
62 * returns !=0 if matches, 0 if no match. 92 * returns true if matches, false otherwise
93 */
94static inline int mei_cl_hbm_equal(struct mei_cl *cl,
95 struct mei_msg_hdr *mei_hdr)
96{
97 return cl->host_client_id == mei_hdr->host_addr &&
98 cl->me_client_id == mei_hdr->me_addr;
99}
100/**
101 * mei_cl_is_reading - checks if the client
102 is the one to read this message
103 *
104 * @cl: mei client
105 * @mei_hdr: header of mei message
106 *
107 * returns true on match and false otherwise
63 */ 108 */
64static int _mei_irq_thread_state_ok(struct mei_cl *cl, 109static bool mei_cl_is_reading(struct mei_cl *cl, struct mei_msg_hdr *mei_hdr)
65 struct mei_msg_hdr *mei_hdr)
66{ 110{
67 return (cl->host_client_id == mei_hdr->host_addr && 111 return mei_cl_hbm_equal(cl, mei_hdr) &&
68 cl->me_client_id == mei_hdr->me_addr &&
69 cl->state == MEI_FILE_CONNECTED && 112 cl->state == MEI_FILE_CONNECTED &&
70 MEI_READ_COMPLETE != cl->reading_state); 113 cl->reading_state != MEI_READ_COMPLETE;
71} 114}
72 115
73/** 116/**
74 * mei_irq_thread_read_client_message - bottom half read routine after ISR to 117 * mei_irq_read_client_message - process client message
75 * handle the read mei client message data processing.
76 * 118 *
77 * @complete_list: An instance of our list structure
78 * @dev: the device structure 119 * @dev: the device structure
79 * @mei_hdr: header of mei client message 120 * @mei_hdr: header of mei client message
121 * @complete_list: An instance of our list structure
80 * 122 *
81 * returns 0 on success, <0 on failure. 123 * returns 0 on success, <0 on failure.
82 */ 124 */
83static int mei_irq_thread_read_client_message(struct mei_cl_cb *complete_list, 125static int mei_cl_irq_read_msg(struct mei_device *dev,
84 struct mei_device *dev, 126 struct mei_msg_hdr *mei_hdr,
85 struct mei_msg_hdr *mei_hdr) 127 struct mei_cl_cb *complete_list)
86{ 128{
87 struct mei_cl *cl; 129 struct mei_cl *cl;
88 struct mei_cl_cb *cb_pos = NULL, *cb_next = NULL; 130 struct mei_cl_cb *cb, *next;
89 unsigned char *buffer = NULL; 131 unsigned char *buffer = NULL;
90 132
91 dev_dbg(&dev->pdev->dev, "start client msg\n"); 133 list_for_each_entry_safe(cb, next, &dev->read_list.list, list) {
92 if (list_empty(&dev->read_list.list)) 134 cl = cb->cl;
93 goto quit; 135 if (!cl || !mei_cl_is_reading(cl, mei_hdr))
136 continue;
94 137
95 list_for_each_entry_safe(cb_pos, cb_next, &dev->read_list.list, list) { 138 cl->reading_state = MEI_READING;
96 cl = cb_pos->cl;
97 if (cl && _mei_irq_thread_state_ok(cl, mei_hdr)) {
98 cl->reading_state = MEI_READING;
99 buffer = cb_pos->response_buffer.data + cb_pos->buf_idx;
100 139
101 if (cb_pos->response_buffer.size < 140 if (cb->response_buffer.size == 0 ||
102 mei_hdr->length + cb_pos->buf_idx) { 141 cb->response_buffer.data == NULL) {
103 dev_dbg(&dev->pdev->dev, "message overflow.\n"); 142 dev_err(&dev->pdev->dev, "response buffer is not allocated.\n");
104 list_del(&cb_pos->list); 143 list_del(&cb->list);
144 return -ENOMEM;
145 }
146
147 if (cb->response_buffer.size < mei_hdr->length + cb->buf_idx) {
148 dev_dbg(&dev->pdev->dev, "message overflow. size %d len %d idx %ld\n",
149 cb->response_buffer.size,
150 mei_hdr->length, cb->buf_idx);
151 buffer = krealloc(cb->response_buffer.data,
152 mei_hdr->length + cb->buf_idx,
153 GFP_KERNEL);
154
155 if (!buffer) {
156 dev_err(&dev->pdev->dev, "allocation failed.\n");
157 list_del(&cb->list);
105 return -ENOMEM; 158 return -ENOMEM;
106 } 159 }
107 if (buffer) 160 cb->response_buffer.data = buffer;
108 mei_read_slots(dev, buffer, mei_hdr->length); 161 cb->response_buffer.size =
109 162 mei_hdr->length + cb->buf_idx;
110 cb_pos->buf_idx += mei_hdr->length;
111 if (mei_hdr->msg_complete) {
112 cl->status = 0;
113 list_del(&cb_pos->list);
114 dev_dbg(&dev->pdev->dev,
115 "completed read H cl = %d, ME cl = %d, length = %lu\n",
116 cl->host_client_id,
117 cl->me_client_id,
118 cb_pos->buf_idx);
119
120 list_add_tail(&cb_pos->list,
121 &complete_list->list);
122 }
123
124 break;
125 } 163 }
126 164
165 buffer = cb->response_buffer.data + cb->buf_idx;
166 mei_read_slots(dev, buffer, mei_hdr->length);
167
168 cb->buf_idx += mei_hdr->length;
169 if (mei_hdr->msg_complete) {
170 cl->status = 0;
171 list_del(&cb->list);
172 dev_dbg(&dev->pdev->dev, "completed read H cl = %d, ME cl = %d, length = %lu\n",
173 cl->host_client_id,
174 cl->me_client_id,
175 cb->buf_idx);
176 list_add_tail(&cb->list, &complete_list->list);
177 }
178 break;
127 } 179 }
128 180
129quit:
130 dev_dbg(&dev->pdev->dev, "message read\n"); 181 dev_dbg(&dev->pdev->dev, "message read\n");
131 if (!buffer) { 182 if (!buffer) {
132 mei_read_slots(dev, dev->rd_msg_buf, mei_hdr->length); 183 mei_read_slots(dev, dev->rd_msg_buf, mei_hdr->length);
@@ -153,25 +204,27 @@ static int _mei_irq_thread_close(struct mei_device *dev, s32 *slots,
153 struct mei_cl *cl, 204 struct mei_cl *cl,
154 struct mei_cl_cb *cmpl_list) 205 struct mei_cl_cb *cmpl_list)
155{ 206{
156 if ((*slots * sizeof(u32)) < (sizeof(struct mei_msg_hdr) + 207 u32 msg_slots =
157 sizeof(struct hbm_client_connect_request))) 208 mei_data2slots(sizeof(struct hbm_client_connect_request));
158 return -EBADMSG;
159 209
160 *slots -= mei_data2slots(sizeof(struct hbm_client_connect_request)); 210 if (*slots < msg_slots)
211 return -EMSGSIZE;
212
213 *slots -= msg_slots;
161 214
162 if (mei_hbm_cl_disconnect_req(dev, cl)) { 215 if (mei_hbm_cl_disconnect_req(dev, cl)) {
163 cl->status = 0; 216 cl->status = 0;
164 cb_pos->buf_idx = 0; 217 cb_pos->buf_idx = 0;
165 list_move_tail(&cb_pos->list, &cmpl_list->list); 218 list_move_tail(&cb_pos->list, &cmpl_list->list);
166 return -EMSGSIZE; 219 return -EIO;
167 } else {
168 cl->state = MEI_FILE_DISCONNECTING;
169 cl->status = 0;
170 cb_pos->buf_idx = 0;
171 list_move_tail(&cb_pos->list, &dev->ctrl_rd_list.list);
172 cl->timer_count = MEI_CONNECT_TIMEOUT;
173 } 220 }
174 221
222 cl->state = MEI_FILE_DISCONNECTING;
223 cl->status = 0;
224 cb_pos->buf_idx = 0;
225 list_move_tail(&cb_pos->list, &dev->ctrl_rd_list.list);
226 cl->timer_count = MEI_CONNECT_TIMEOUT;
227
175 return 0; 228 return 0;
176} 229}
177 230
@@ -192,14 +245,15 @@ static int _mei_irq_thread_read(struct mei_device *dev, s32 *slots,
192 struct mei_cl *cl, 245 struct mei_cl *cl,
193 struct mei_cl_cb *cmpl_list) 246 struct mei_cl_cb *cmpl_list)
194{ 247{
195 if ((*slots * sizeof(u32)) < (sizeof(struct mei_msg_hdr) + 248 u32 msg_slots = mei_data2slots(sizeof(struct hbm_flow_control));
196 sizeof(struct hbm_flow_control))) { 249
250 if (*slots < msg_slots) {
197 /* return the cancel routine */ 251 /* return the cancel routine */
198 list_del(&cb_pos->list); 252 list_del(&cb_pos->list);
199 return -EBADMSG; 253 return -EMSGSIZE;
200 } 254 }
201 255
202 *slots -= mei_data2slots(sizeof(struct hbm_flow_control)); 256 *slots -= msg_slots;
203 257
204 if (mei_hbm_cl_flow_control_req(dev, cl)) { 258 if (mei_hbm_cl_flow_control_req(dev, cl)) {
205 cl->status = -ENODEV; 259 cl->status = -ENODEV;
@@ -229,15 +283,19 @@ static int _mei_irq_thread_ioctl(struct mei_device *dev, s32 *slots,
229 struct mei_cl *cl, 283 struct mei_cl *cl,
230 struct mei_cl_cb *cmpl_list) 284 struct mei_cl_cb *cmpl_list)
231{ 285{
232 if ((*slots * sizeof(u32)) < (sizeof(struct mei_msg_hdr) + 286 u32 msg_slots =
233 sizeof(struct hbm_client_connect_request))) { 287 mei_data2slots(sizeof(struct hbm_client_connect_request));
288
289 if (*slots < msg_slots) {
234 /* return the cancel routine */ 290 /* return the cancel routine */
235 list_del(&cb_pos->list); 291 list_del(&cb_pos->list);
236 return -EBADMSG; 292 return -EMSGSIZE;
237 } 293 }
238 294
295 *slots -= msg_slots;
296
239 cl->state = MEI_FILE_CONNECTING; 297 cl->state = MEI_FILE_CONNECTING;
240 *slots -= mei_data2slots(sizeof(struct hbm_client_connect_request)); 298
241 if (mei_hbm_cl_connect_req(dev, cl)) { 299 if (mei_hbm_cl_connect_req(dev, cl)) {
242 cl->status = -ENODEV; 300 cl->status = -ENODEV;
243 cb_pos->buf_idx = 0; 301 cb_pos->buf_idx = 0;
@@ -266,7 +324,7 @@ static int mei_irq_thread_write_complete(struct mei_device *dev, s32 *slots,
266 struct mei_msg_hdr mei_hdr; 324 struct mei_msg_hdr mei_hdr;
267 struct mei_cl *cl = cb->cl; 325 struct mei_cl *cl = cb->cl;
268 size_t len = cb->request_buffer.size - cb->buf_idx; 326 size_t len = cb->request_buffer.size - cb->buf_idx;
269 size_t msg_slots = mei_data2slots(len); 327 u32 msg_slots = mei_data2slots(len);
270 328
271 mei_hdr.host_addr = cl->host_client_id; 329 mei_hdr.host_addr = cl->host_client_id;
272 mei_hdr.me_addr = cl->me_client_id; 330 mei_hdr.me_addr = cl->me_client_id;
@@ -298,13 +356,14 @@ static int mei_irq_thread_write_complete(struct mei_device *dev, s32 *slots,
298 return -ENODEV; 356 return -ENODEV;
299 } 357 }
300 358
301 if (mei_cl_flow_ctrl_reduce(cl))
302 return -ENODEV;
303 359
304 cl->status = 0; 360 cl->status = 0;
305 cb->buf_idx += mei_hdr.length; 361 cb->buf_idx += mei_hdr.length;
306 if (mei_hdr.msg_complete) 362 if (mei_hdr.msg_complete) {
363 if (mei_cl_flow_ctrl_reduce(cl))
364 return -ENODEV;
307 list_move_tail(&cb->list, &dev->write_waiting_list.list); 365 list_move_tail(&cb->list, &dev->write_waiting_list.list);
366 }
308 367
309 return 0; 368 return 0;
310} 369}
@@ -350,8 +409,7 @@ int mei_irq_read_handler(struct mei_device *dev,
350 " client = %d, ME client = %d\n", 409 " client = %d, ME client = %d\n",
351 cl_pos->host_client_id, 410 cl_pos->host_client_id,
352 cl_pos->me_client_id); 411 cl_pos->me_client_id);
353 if (cl_pos->host_client_id == mei_hdr->host_addr && 412 if (mei_cl_hbm_equal(cl_pos, mei_hdr))
354 cl_pos->me_client_id == mei_hdr->me_addr)
355 break; 413 break;
356 } 414 }
357 415
@@ -362,7 +420,7 @@ int mei_irq_read_handler(struct mei_device *dev,
362 } 420 }
363 } 421 }
364 if (((*slots) * sizeof(u32)) < mei_hdr->length) { 422 if (((*slots) * sizeof(u32)) < mei_hdr->length) {
365 dev_dbg(&dev->pdev->dev, 423 dev_err(&dev->pdev->dev,
366 "we can't read the message slots =%08x.\n", 424 "we can't read the message slots =%08x.\n",
367 *slots); 425 *slots);
368 /* we can't read the message */ 426 /* we can't read the message */
@@ -378,20 +436,19 @@ int mei_irq_read_handler(struct mei_device *dev,
378 } else if (mei_hdr->host_addr == dev->iamthif_cl.host_client_id && 436 } else if (mei_hdr->host_addr == dev->iamthif_cl.host_client_id &&
379 (MEI_FILE_CONNECTED == dev->iamthif_cl.state) && 437 (MEI_FILE_CONNECTED == dev->iamthif_cl.state) &&
380 (dev->iamthif_state == MEI_IAMTHIF_READING)) { 438 (dev->iamthif_state == MEI_IAMTHIF_READING)) {
381 dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_iamthif_message.\n");
382 439
440 dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_iamthif_message.\n");
383 dev_dbg(&dev->pdev->dev, MEI_HDR_FMT, MEI_HDR_PRM(mei_hdr)); 441 dev_dbg(&dev->pdev->dev, MEI_HDR_FMT, MEI_HDR_PRM(mei_hdr));
384 442
385 ret = mei_amthif_irq_read_message(cmpl_list, dev, mei_hdr); 443 ret = mei_amthif_irq_read_msg(dev, mei_hdr, cmpl_list);
386 if (ret) 444 if (ret)
387 goto end; 445 goto end;
388 } else { 446 } else {
389 dev_dbg(&dev->pdev->dev, "call mei_irq_thread_read_client_message.\n"); 447 dev_dbg(&dev->pdev->dev, "call mei_cl_irq_read_msg.\n");
390 ret = mei_irq_thread_read_client_message(cmpl_list, 448 dev_dbg(&dev->pdev->dev, MEI_HDR_FMT, MEI_HDR_PRM(mei_hdr));
391 dev, mei_hdr); 449 ret = mei_cl_irq_read_msg(dev, mei_hdr, cmpl_list);
392 if (ret) 450 if (ret)
393 goto end; 451 goto end;
394
395 } 452 }
396 453
397 /* reset the number of slots and header */ 454 /* reset the number of slots and header */
@@ -400,7 +457,7 @@ int mei_irq_read_handler(struct mei_device *dev,
400 457
401 if (*slots == -EOVERFLOW) { 458 if (*slots == -EOVERFLOW) {
402 /* overflow - reset */ 459 /* overflow - reset */
403 dev_dbg(&dev->pdev->dev, "resetting due to slots overflow.\n"); 460 dev_err(&dev->pdev->dev, "resetting due to slots overflow.\n");
404 /* set the event since message has been read */ 461 /* set the event since message has been read */
405 ret = -ERANGE; 462 ret = -ERANGE;
406 goto end; 463 goto end;
@@ -408,6 +465,7 @@ int mei_irq_read_handler(struct mei_device *dev,
408end: 465end:
409 return ret; 466 return ret;
410} 467}
468EXPORT_SYMBOL_GPL(mei_irq_read_handler);
411 469
412 470
413/** 471/**
@@ -419,8 +477,7 @@ end:
419 * 477 *
420 * returns 0 on success, <0 on failure. 478 * returns 0 on success, <0 on failure.
421 */ 479 */
422int mei_irq_write_handler(struct mei_device *dev, 480int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list)
423 struct mei_cl_cb *cmpl_list)
424{ 481{
425 482
426 struct mei_cl *cl; 483 struct mei_cl *cl;
@@ -559,6 +616,7 @@ int mei_irq_write_handler(struct mei_device *dev,
559 } 616 }
560 return 0; 617 return 0;
561} 618}
619EXPORT_SYMBOL_GPL(mei_irq_write_handler);
562 620
563 621
564 622
@@ -586,8 +644,8 @@ void mei_timer(struct work_struct *work)
586 if (dev->dev_state == MEI_DEV_INIT_CLIENTS) { 644 if (dev->dev_state == MEI_DEV_INIT_CLIENTS) {
587 if (dev->init_clients_timer) { 645 if (dev->init_clients_timer) {
588 if (--dev->init_clients_timer == 0) { 646 if (--dev->init_clients_timer == 0) {
589 dev_dbg(&dev->pdev->dev, "IMEI reset due to init clients timeout ,init clients state = %d.\n", 647 dev_err(&dev->pdev->dev, "reset: init clients timeout hbm_state = %d.\n",
590 dev->init_clients_state); 648 dev->hbm_state);
591 mei_reset(dev, 1); 649 mei_reset(dev, 1);
592 } 650 }
593 } 651 }
@@ -598,7 +656,7 @@ void mei_timer(struct work_struct *work)
598 list_for_each_entry_safe(cl_pos, cl_next, &dev->file_list, link) { 656 list_for_each_entry_safe(cl_pos, cl_next, &dev->file_list, link) {
599 if (cl_pos->timer_count) { 657 if (cl_pos->timer_count) {
600 if (--cl_pos->timer_count == 0) { 658 if (--cl_pos->timer_count == 0) {
601 dev_dbg(&dev->pdev->dev, "HECI reset due to connect/disconnect timeout.\n"); 659 dev_err(&dev->pdev->dev, "reset: connect/disconnect timeout.\n");
602 mei_reset(dev, 1); 660 mei_reset(dev, 1);
603 goto out; 661 goto out;
604 } 662 }
@@ -607,7 +665,7 @@ void mei_timer(struct work_struct *work)
607 665
608 if (dev->iamthif_stall_timer) { 666 if (dev->iamthif_stall_timer) {
609 if (--dev->iamthif_stall_timer == 0) { 667 if (--dev->iamthif_stall_timer == 0) {
610 dev_dbg(&dev->pdev->dev, "resetting because of hang to amthi.\n"); 668 dev_err(&dev->pdev->dev, "reset: amthif hanged.\n");
611 mei_reset(dev, 1); 669 mei_reset(dev, 1);
612 dev->iamthif_msg_buf_size = 0; 670 dev->iamthif_msg_buf_size = 0;
613 dev->iamthif_msg_buf_index = 0; 671 dev->iamthif_msg_buf_index = 0;
diff --git a/drivers/misc/mei/main.c b/drivers/misc/mei/main.c
index 903f809b21f7..7c44c8dbae42 100644
--- a/drivers/misc/mei/main.c
+++ b/drivers/misc/mei/main.c
@@ -48,7 +48,7 @@
48 * 48 *
49 * @inode: pointer to inode structure 49 * @inode: pointer to inode structure
50 * @file: pointer to file structure 50 * @file: pointer to file structure
51 * 51 e
52 * returns 0 on success, <0 on error 52 * returns 0 on success, <0 on error
53 */ 53 */
54static int mei_open(struct inode *inode, struct file *file) 54static int mei_open(struct inode *inode, struct file *file)
@@ -244,7 +244,7 @@ static ssize_t mei_read(struct file *file, char __user *ubuf,
244 goto out; 244 goto out;
245 } 245 }
246 246
247 err = mei_cl_read_start(cl); 247 err = mei_cl_read_start(cl, length);
248 if (err && err != -EBUSY) { 248 if (err && err != -EBUSY) {
249 dev_dbg(&dev->pdev->dev, 249 dev_dbg(&dev->pdev->dev,
250 "mei start read failure with status = %d\n", err); 250 "mei start read failure with status = %d\n", err);
@@ -292,9 +292,8 @@ static ssize_t mei_read(struct file *file, char __user *ubuf,
292 } 292 }
293 /* now copy the data to user space */ 293 /* now copy the data to user space */
294copy_buffer: 294copy_buffer:
295 dev_dbg(&dev->pdev->dev, "cb->response_buffer size - %d\n", 295 dev_dbg(&dev->pdev->dev, "buf.size = %d buf.idx= %ld\n",
296 cb->response_buffer.size); 296 cb->response_buffer.size, cb->buf_idx);
297 dev_dbg(&dev->pdev->dev, "cb->buf_idx - %lu\n", cb->buf_idx);
298 if (length == 0 || ubuf == NULL || *offset > cb->buf_idx) { 297 if (length == 0 || ubuf == NULL || *offset > cb->buf_idx) {
299 rets = -EMSGSIZE; 298 rets = -EMSGSIZE;
300 goto free; 299 goto free;
@@ -342,11 +341,10 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
342{ 341{
343 struct mei_cl *cl = file->private_data; 342 struct mei_cl *cl = file->private_data;
344 struct mei_cl_cb *write_cb = NULL; 343 struct mei_cl_cb *write_cb = NULL;
345 struct mei_msg_hdr mei_hdr;
346 struct mei_device *dev; 344 struct mei_device *dev;
347 unsigned long timeout = 0; 345 unsigned long timeout = 0;
348 int rets; 346 int rets;
349 int i; 347 int id;
350 348
351 if (WARN_ON(!cl || !cl->dev)) 349 if (WARN_ON(!cl || !cl->dev))
352 return -ENODEV; 350 return -ENODEV;
@@ -357,24 +355,24 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
357 355
358 if (dev->dev_state != MEI_DEV_ENABLED) { 356 if (dev->dev_state != MEI_DEV_ENABLED) {
359 rets = -ENODEV; 357 rets = -ENODEV;
360 goto err; 358 goto out;
361 } 359 }
362 360
363 i = mei_me_cl_by_id(dev, cl->me_client_id); 361 id = mei_me_cl_by_id(dev, cl->me_client_id);
364 if (i < 0) { 362 if (id < 0) {
365 rets = -ENODEV; 363 rets = -ENODEV;
366 goto err; 364 goto out;
367 } 365 }
368 if (length > dev->me_clients[i].props.max_msg_length || length <= 0) { 366 if (length > dev->me_clients[id].props.max_msg_length || length <= 0) {
369 rets = -EMSGSIZE; 367 rets = -EMSGSIZE;
370 goto err; 368 goto out;
371 } 369 }
372 370
373 if (cl->state != MEI_FILE_CONNECTED) { 371 if (cl->state != MEI_FILE_CONNECTED) {
374 rets = -ENODEV;
375 dev_err(&dev->pdev->dev, "host client = %d, is not connected to ME client = %d", 372 dev_err(&dev->pdev->dev, "host client = %d, is not connected to ME client = %d",
376 cl->host_client_id, cl->me_client_id); 373 cl->host_client_id, cl->me_client_id);
377 goto err; 374 rets = -ENODEV;
375 goto out;
378 } 376 }
379 if (cl == &dev->iamthif_cl) { 377 if (cl == &dev->iamthif_cl) {
380 write_cb = mei_amthif_find_read_list_entry(dev, file); 378 write_cb = mei_amthif_find_read_list_entry(dev, file);
@@ -412,17 +410,15 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
412 if (!write_cb) { 410 if (!write_cb) {
413 dev_err(&dev->pdev->dev, "write cb allocation failed\n"); 411 dev_err(&dev->pdev->dev, "write cb allocation failed\n");
414 rets = -ENOMEM; 412 rets = -ENOMEM;
415 goto err; 413 goto out;
416 } 414 }
417 rets = mei_io_cb_alloc_req_buf(write_cb, length); 415 rets = mei_io_cb_alloc_req_buf(write_cb, length);
418 if (rets) 416 if (rets)
419 goto err; 417 goto out;
420
421 dev_dbg(&dev->pdev->dev, "cb request size = %zd\n", length);
422 418
423 rets = copy_from_user(write_cb->request_buffer.data, ubuf, length); 419 rets = copy_from_user(write_cb->request_buffer.data, ubuf, length);
424 if (rets) 420 if (rets)
425 goto err; 421 goto out;
426 422
427 cl->sm_state = 0; 423 cl->sm_state = 0;
428 if (length == 4 && 424 if (length == 4 &&
@@ -440,65 +436,17 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
440 if (rets) { 436 if (rets) {
441 dev_err(&dev->pdev->dev, 437 dev_err(&dev->pdev->dev,
442 "amthif write failed with status = %d\n", rets); 438 "amthif write failed with status = %d\n", rets);
443 goto err; 439 goto out;
444 } 440 }
445 mutex_unlock(&dev->device_lock); 441 mutex_unlock(&dev->device_lock);
446 return length; 442 return length;
447 } 443 }
448 444
449 write_cb->fop_type = MEI_FOP_WRITE; 445 rets = mei_cl_write(cl, write_cb, false);
450
451 dev_dbg(&dev->pdev->dev, "host client = %d, ME client = %d\n",
452 cl->host_client_id, cl->me_client_id);
453 rets = mei_cl_flow_ctrl_creds(cl);
454 if (rets < 0)
455 goto err;
456
457 if (rets == 0 || !dev->hbuf_is_ready) {
458 write_cb->buf_idx = 0;
459 mei_hdr.msg_complete = 0;
460 cl->writing_state = MEI_WRITING;
461 goto out;
462 }
463
464 dev->hbuf_is_ready = false;
465 if (length > mei_hbuf_max_len(dev)) {
466 mei_hdr.length = mei_hbuf_max_len(dev);
467 mei_hdr.msg_complete = 0;
468 } else {
469 mei_hdr.length = length;
470 mei_hdr.msg_complete = 1;
471 }
472 mei_hdr.host_addr = cl->host_client_id;
473 mei_hdr.me_addr = cl->me_client_id;
474 mei_hdr.reserved = 0;
475
476 dev_dbg(&dev->pdev->dev, "write " MEI_HDR_FMT "\n",
477 MEI_HDR_PRM(&mei_hdr));
478 if (mei_write_message(dev, &mei_hdr, write_cb->request_buffer.data)) {
479 rets = -ENODEV;
480 goto err;
481 }
482 cl->writing_state = MEI_WRITING;
483 write_cb->buf_idx = mei_hdr.length;
484
485out: 446out:
486 if (mei_hdr.msg_complete) {
487 if (mei_cl_flow_ctrl_reduce(cl)) {
488 rets = -ENODEV;
489 goto err;
490 }
491 list_add_tail(&write_cb->list, &dev->write_waiting_list.list);
492 } else {
493 list_add_tail(&write_cb->list, &dev->write_list.list);
494 }
495
496 mutex_unlock(&dev->device_lock); 447 mutex_unlock(&dev->device_lock);
497 return length; 448 if (rets < 0)
498 449 mei_io_cb_free(write_cb);
499err:
500 mutex_unlock(&dev->device_lock);
501 mei_io_cb_free(write_cb);
502 return rets; 450 return rets;
503} 451}
504 452
@@ -753,17 +701,44 @@ static struct miscdevice mei_misc_device = {
753 .minor = MISC_DYNAMIC_MINOR, 701 .minor = MISC_DYNAMIC_MINOR,
754}; 702};
755 703
756int mei_register(struct device *dev) 704
705int mei_register(struct mei_device *dev)
757{ 706{
758 mei_misc_device.parent = dev; 707 int ret;
759 return misc_register(&mei_misc_device); 708 mei_misc_device.parent = &dev->pdev->dev;
709 ret = misc_register(&mei_misc_device);
710 if (ret)
711 return ret;
712
713 if (mei_dbgfs_register(dev, mei_misc_device.name))
714 dev_err(&dev->pdev->dev, "cannot register debugfs\n");
715
716 return 0;
760} 717}
718EXPORT_SYMBOL_GPL(mei_register);
761 719
762void mei_deregister(void) 720void mei_deregister(struct mei_device *dev)
763{ 721{
722 mei_dbgfs_deregister(dev);
764 misc_deregister(&mei_misc_device); 723 misc_deregister(&mei_misc_device);
765 mei_misc_device.parent = NULL; 724 mei_misc_device.parent = NULL;
766} 725}
726EXPORT_SYMBOL_GPL(mei_deregister);
727
728static int __init mei_init(void)
729{
730 return mei_cl_bus_init();
731}
732
733static void __exit mei_exit(void)
734{
735 mei_cl_bus_exit();
736}
737
738module_init(mei_init);
739module_exit(mei_exit);
767 740
741MODULE_AUTHOR("Intel Corporation");
742MODULE_DESCRIPTION("Intel(R) Management Engine Interface");
768MODULE_LICENSE("GPL v2"); 743MODULE_LICENSE("GPL v2");
769 744
diff --git a/drivers/misc/mei/mei_dev.h b/drivers/misc/mei/mei_dev.h
index 97873812e33b..4de5140e7379 100644
--- a/drivers/misc/mei/mei_dev.h
+++ b/drivers/misc/mei/mei_dev.h
@@ -21,9 +21,11 @@
21#include <linux/watchdog.h> 21#include <linux/watchdog.h>
22#include <linux/poll.h> 22#include <linux/poll.h>
23#include <linux/mei.h> 23#include <linux/mei.h>
24#include <linux/mei_cl_bus.h>
24 25
25#include "hw.h" 26#include "hw.h"
26#include "hw-me-regs.h" 27#include "hw-me-regs.h"
28#include "hbm.h"
27 29
28/* 30/*
29 * watch dog definition 31 * watch dog definition
@@ -95,22 +97,14 @@ enum mei_dev_state {
95 MEI_DEV_INITIALIZING = 0, 97 MEI_DEV_INITIALIZING = 0,
96 MEI_DEV_INIT_CLIENTS, 98 MEI_DEV_INIT_CLIENTS,
97 MEI_DEV_ENABLED, 99 MEI_DEV_ENABLED,
98 MEI_DEV_RESETING, 100 MEI_DEV_RESETTING,
99 MEI_DEV_DISABLED, 101 MEI_DEV_DISABLED,
100 MEI_DEV_RECOVERING_FROM_RESET,
101 MEI_DEV_POWER_DOWN, 102 MEI_DEV_POWER_DOWN,
102 MEI_DEV_POWER_UP 103 MEI_DEV_POWER_UP
103}; 104};
104 105
105const char *mei_dev_state_str(int state); 106const char *mei_dev_state_str(int state);
106 107
107/* init clients states*/
108enum mei_init_clients_states {
109 MEI_START_MESSAGE = 0,
110 MEI_ENUM_CLIENTS_MESSAGE,
111 MEI_CLIENT_PROPERTIES_MESSAGE
112};
113
114enum iamthif_states { 108enum iamthif_states {
115 MEI_IAMTHIF_IDLE, 109 MEI_IAMTHIF_IDLE,
116 MEI_IAMTHIF_WRITING, 110 MEI_IAMTHIF_WRITING,
@@ -153,7 +147,7 @@ enum mei_cb_file_ops {
153/* 147/*
154 * Intel MEI message data struct 148 * Intel MEI message data struct
155 */ 149 */
156struct mei_message_data { 150struct mei_msg_data {
157 u32 size; 151 u32 size;
158 unsigned char *data; 152 unsigned char *data;
159}; 153};
@@ -184,8 +178,8 @@ struct mei_cl_cb {
184 struct list_head list; 178 struct list_head list;
185 struct mei_cl *cl; 179 struct mei_cl *cl;
186 enum mei_cb_file_ops fop_type; 180 enum mei_cb_file_ops fop_type;
187 struct mei_message_data request_buffer; 181 struct mei_msg_data request_buffer;
188 struct mei_message_data response_buffer; 182 struct mei_msg_data response_buffer;
189 unsigned long buf_idx; 183 unsigned long buf_idx;
190 unsigned long read_time; 184 unsigned long read_time;
191 struct file *file_object; 185 struct file *file_object;
@@ -209,15 +203,20 @@ struct mei_cl {
209 enum mei_file_transaction_states writing_state; 203 enum mei_file_transaction_states writing_state;
210 int sm_state; 204 int sm_state;
211 struct mei_cl_cb *read_cb; 205 struct mei_cl_cb *read_cb;
206
207 /* MEI CL bus data */
208 struct mei_cl_device *device;
209 struct list_head device_link;
210 uuid_le device_uuid;
212}; 211};
213 212
214/** struct mei_hw_ops 213/** struct mei_hw_ops
215 * 214 *
216 * @host_set_ready - notify FW that host side is ready
217 * @host_is_ready - query for host readiness 215 * @host_is_ready - query for host readiness
218 216
219 * @hw_is_ready - query if hw is ready 217 * @hw_is_ready - query if hw is ready
220 * @hw_reset - reset hw 218 * @hw_reset - reset hw
219 * @hw_start - start hw after reset
221 * @hw_config - configure hw 220 * @hw_config - configure hw
222 221
223 * @intr_clear - clear pending interrupts 222 * @intr_clear - clear pending interrupts
@@ -237,11 +236,11 @@ struct mei_cl {
237 */ 236 */
238struct mei_hw_ops { 237struct mei_hw_ops {
239 238
240 void (*host_set_ready) (struct mei_device *dev);
241 bool (*host_is_ready) (struct mei_device *dev); 239 bool (*host_is_ready) (struct mei_device *dev);
242 240
243 bool (*hw_is_ready) (struct mei_device *dev); 241 bool (*hw_is_ready) (struct mei_device *dev);
244 void (*hw_reset) (struct mei_device *dev, bool enable); 242 void (*hw_reset) (struct mei_device *dev, bool enable);
243 int (*hw_start) (struct mei_device *dev);
245 void (*hw_config) (struct mei_device *dev); 244 void (*hw_config) (struct mei_device *dev);
246 245
247 void (*intr_clear) (struct mei_device *dev); 246 void (*intr_clear) (struct mei_device *dev);
@@ -263,9 +262,77 @@ struct mei_hw_ops {
263 unsigned char *buf, unsigned long len); 262 unsigned char *buf, unsigned long len);
264}; 263};
265 264
265/* MEI bus API*/
266
267/**
268 * struct mei_cl_ops - MEI CL device ops
269 * This structure allows ME host clients to implement technology
270 * specific operations.
271 *
272 * @enable: Enable an MEI CL device. Some devices require specific
273 * HECI commands to initialize completely.
274 * @disable: Disable an MEI CL device.
275 * @send: Tx hook for the device. This allows ME host clients to trap
276 * the device driver buffers before actually physically
277 * pushing it to the ME.
278 * @recv: Rx hook for the device. This allows ME host clients to trap the
279 * ME buffers before forwarding them to the device driver.
280 */
281struct mei_cl_ops {
282 int (*enable)(struct mei_cl_device *device);
283 int (*disable)(struct mei_cl_device *device);
284 int (*send)(struct mei_cl_device *device, u8 *buf, size_t length);
285 int (*recv)(struct mei_cl_device *device, u8 *buf, size_t length);
286};
287
288struct mei_cl_device *mei_cl_add_device(struct mei_device *dev,
289 uuid_le uuid, char *name,
290 struct mei_cl_ops *ops);
291void mei_cl_remove_device(struct mei_cl_device *device);
292
293int __mei_cl_async_send(struct mei_cl *cl, u8 *buf, size_t length);
294int __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length);
295int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length);
296void mei_cl_bus_rx_event(struct mei_cl *cl);
297int mei_cl_bus_init(void);
298void mei_cl_bus_exit(void);
299
300
301/**
302 * struct mei_cl_device - MEI device handle
303 * An mei_cl_device pointer is returned from mei_add_device()
304 * and links MEI bus clients to their actual ME host client pointer.
305 * Drivers for MEI devices will get an mei_cl_device pointer
306 * when being probed and shall use it for doing ME bus I/O.
307 *
308 * @dev: linux driver model device pointer
309 * @uuid: me client uuid
310 * @cl: mei client
311 * @ops: ME transport ops
312 * @event_cb: Drivers register this callback to get asynchronous ME
313 * events (e.g. Rx buffer pending) notifications.
314 * @events: Events bitmask sent to the driver.
315 * @priv_data: client private data
316 */
317struct mei_cl_device {
318 struct device dev;
319
320 struct mei_cl *cl;
321
322 const struct mei_cl_ops *ops;
323
324 struct work_struct event_work;
325 mei_cl_event_cb_t event_cb;
326 void *event_context;
327 unsigned long events;
328
329 void *priv_data;
330};
331
266/** 332/**
267 * struct mei_device - MEI private device struct 333 * struct mei_device - MEI private device struct
268 334
335 * @hbm_state - state of host bus message protocol
269 * @mem_addr - mem mapped base register address 336 * @mem_addr - mem mapped base register address
270 337
271 * @hbuf_depth - depth of hardware host/write buffer is slots 338 * @hbuf_depth - depth of hardware host/write buffer is slots
@@ -296,11 +363,12 @@ struct mei_device {
296 */ 363 */
297 struct mutex device_lock; /* device lock */ 364 struct mutex device_lock; /* device lock */
298 struct delayed_work timer_work; /* MEI timer delayed work (timeouts) */ 365 struct delayed_work timer_work; /* MEI timer delayed work (timeouts) */
299 bool recvd_msg;
300 366
367 bool recvd_hw_ready;
301 /* 368 /*
302 * waiting queue for receive message from FW 369 * waiting queue for receive message from FW
303 */ 370 */
371 wait_queue_head_t wait_hw_ready;
304 wait_queue_head_t wait_recvd_msg; 372 wait_queue_head_t wait_recvd_msg;
305 wait_queue_head_t wait_stop_wd; 373 wait_queue_head_t wait_stop_wd;
306 374
@@ -308,7 +376,7 @@ struct mei_device {
308 * mei device states 376 * mei device states
309 */ 377 */
310 enum mei_dev_state dev_state; 378 enum mei_dev_state dev_state;
311 enum mei_init_clients_states init_clients_state; 379 enum mei_hbm_state hbm_state;
312 u16 init_clients_timer; 380 u16 init_clients_timer;
313 381
314 unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE]; /* control messages */ 382 unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE]; /* control messages */
@@ -365,6 +433,14 @@ struct mei_device {
365 433
366 struct work_struct init_work; 434 struct work_struct init_work;
367 435
436 /* List of bus devices */
437 struct list_head device_list;
438
439#if IS_ENABLED(CONFIG_DEBUG_FS)
440 struct dentry *dbgfs_dir;
441#endif /* CONFIG_DEBUG_FS */
442
443
368 const struct mei_hw_ops *ops; 444 const struct mei_hw_ops *ops;
369 char hw[0] __aligned(sizeof(void *)); 445 char hw[0] __aligned(sizeof(void *));
370}; 446};
@@ -374,13 +450,23 @@ static inline unsigned long mei_secs_to_jiffies(unsigned long sec)
374 return msecs_to_jiffies(sec * MSEC_PER_SEC); 450 return msecs_to_jiffies(sec * MSEC_PER_SEC);
375} 451}
376 452
453/**
454 * mei_data2slots - get slots - number of (dwords) from a message length
455 * + size of the mei header
456 * @length - size of the messages in bytes
457 * returns - number of slots
458 */
459static inline u32 mei_data2slots(size_t length)
460{
461 return DIV_ROUND_UP(sizeof(struct mei_msg_hdr) + length, 4);
462}
377 463
378/* 464/*
379 * mei init function prototypes 465 * mei init function prototypes
380 */ 466 */
381void mei_device_init(struct mei_device *dev); 467void mei_device_init(struct mei_device *dev);
382void mei_reset(struct mei_device *dev, int interrupts); 468void mei_reset(struct mei_device *dev, int interrupts);
383int mei_hw_init(struct mei_device *dev); 469int mei_start(struct mei_device *dev);
384void mei_stop(struct mei_device *dev); 470void mei_stop(struct mei_device *dev);
385 471
386/* 472/*
@@ -392,8 +478,7 @@ int mei_irq_read_handler(struct mei_device *dev,
392 struct mei_cl_cb *cmpl_list, s32 *slots); 478 struct mei_cl_cb *cmpl_list, s32 *slots);
393 479
394int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list); 480int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list);
395 481void mei_irq_compl_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list);
396void mei_irq_complete_handler(struct mei_cl *cl, struct mei_cl_cb *cb_pos);
397 482
398/* 483/*
399 * AMTHIF - AMT Host Interface Functions 484 * AMTHIF - AMT Host Interface Functions
@@ -417,6 +502,25 @@ struct mei_cl_cb *mei_amthif_find_read_list_entry(struct mei_device *dev,
417 502
418void mei_amthif_run_next_cmd(struct mei_device *dev); 503void mei_amthif_run_next_cmd(struct mei_device *dev);
419 504
505int mei_amthif_irq_write_complete(struct mei_device *dev, s32 *slots,
506 struct mei_cl_cb *cb, struct mei_cl_cb *cmpl_list);
507
508void mei_amthif_complete(struct mei_device *dev, struct mei_cl_cb *cb);
509int mei_amthif_irq_read_msg(struct mei_device *dev,
510 struct mei_msg_hdr *mei_hdr,
511 struct mei_cl_cb *complete_list);
512int mei_amthif_irq_read(struct mei_device *dev, s32 *slots);
513
514/*
515 * NFC functions
516 */
517int mei_nfc_host_init(struct mei_device *dev);
518void mei_nfc_host_exit(void);
519
520/*
521 * NFC Client UUID
522 */
523extern const uuid_le mei_nfc_guid;
420 524
421int mei_amthif_irq_write_complete(struct mei_device *dev, s32 *slots, 525int mei_amthif_irq_write_complete(struct mei_device *dev, s32 *slots,
422 struct mei_cl_cb *cb, struct mei_cl_cb *cmpl_list); 526 struct mei_cl_cb *cb, struct mei_cl_cb *cmpl_list);
@@ -455,6 +559,11 @@ static inline void mei_hw_reset(struct mei_device *dev, bool enable)
455 dev->ops->hw_reset(dev, enable); 559 dev->ops->hw_reset(dev, enable);
456} 560}
457 561
562static inline void mei_hw_start(struct mei_device *dev)
563{
564 dev->ops->hw_start(dev);
565}
566
458static inline void mei_clear_interrupts(struct mei_device *dev) 567static inline void mei_clear_interrupts(struct mei_device *dev)
459{ 568{
460 dev->ops->intr_clear(dev); 569 dev->ops->intr_clear(dev);
@@ -470,10 +579,6 @@ static inline void mei_disable_interrupts(struct mei_device *dev)
470 dev->ops->intr_disable(dev); 579 dev->ops->intr_disable(dev);
471} 580}
472 581
473static inline void mei_host_set_ready(struct mei_device *dev)
474{
475 dev->ops->host_set_ready(dev);
476}
477static inline bool mei_host_is_ready(struct mei_device *dev) 582static inline bool mei_host_is_ready(struct mei_device *dev)
478{ 583{
479 return dev->ops->host_is_ready(dev); 584 return dev->ops->host_is_ready(dev);
@@ -521,8 +626,19 @@ static inline int mei_count_full_read_slots(struct mei_device *dev)
521 return dev->ops->rdbuf_full_slots(dev); 626 return dev->ops->rdbuf_full_slots(dev);
522} 627}
523 628
524int mei_register(struct device *dev); 629#if IS_ENABLED(CONFIG_DEBUG_FS)
525void mei_deregister(void); 630int mei_dbgfs_register(struct mei_device *dev, const char *name);
631void mei_dbgfs_deregister(struct mei_device *dev);
632#else
633static inline int mei_dbgfs_register(struct mei_device *dev, const char *name)
634{
635 return 0;
636}
637static inline void mei_dbgfs_deregister(struct mei_device *dev) {}
638#endif /* CONFIG_DEBUG_FS */
639
640int mei_register(struct mei_device *dev);
641void mei_deregister(struct mei_device *dev);
526 642
527#define MEI_HDR_FMT "hdr:host=%02d me=%02d len=%d comp=%1d" 643#define MEI_HDR_FMT "hdr:host=%02d me=%02d len=%d comp=%1d"
528#define MEI_HDR_PRM(hdr) \ 644#define MEI_HDR_PRM(hdr) \
diff --git a/drivers/misc/mei/nfc.c b/drivers/misc/mei/nfc.c
new file mode 100644
index 000000000000..3adf8a70f26e
--- /dev/null
+++ b/drivers/misc/mei/nfc.c
@@ -0,0 +1,554 @@
1/*
2 *
3 * Intel Management Engine Interface (Intel MEI) Linux driver
4 * Copyright (c) 2003-2013, Intel Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 */
16
17#include <linux/kernel.h>
18#include <linux/sched.h>
19#include <linux/module.h>
20#include <linux/moduleparam.h>
21#include <linux/device.h>
22#include <linux/pci.h>
23#include <linux/mei_cl_bus.h>
24
25#include "mei_dev.h"
26#include "client.h"
27
28struct mei_nfc_cmd {
29 u8 command;
30 u8 status;
31 u16 req_id;
32 u32 reserved;
33 u16 data_size;
34 u8 sub_command;
35 u8 data[];
36} __packed;
37
38struct mei_nfc_reply {
39 u8 command;
40 u8 status;
41 u16 req_id;
42 u32 reserved;
43 u16 data_size;
44 u8 sub_command;
45 u8 reply_status;
46 u8 data[];
47} __packed;
48
49struct mei_nfc_if_version {
50 u8 radio_version_sw[3];
51 u8 reserved[3];
52 u8 radio_version_hw[3];
53 u8 i2c_addr;
54 u8 fw_ivn;
55 u8 vendor_id;
56 u8 radio_type;
57} __packed;
58
59struct mei_nfc_connect {
60 u8 fw_ivn;
61 u8 vendor_id;
62} __packed;
63
64struct mei_nfc_connect_resp {
65 u8 fw_ivn;
66 u8 vendor_id;
67 u16 me_major;
68 u16 me_minor;
69 u16 me_hotfix;
70 u16 me_build;
71} __packed;
72
73struct mei_nfc_hci_hdr {
74 u8 cmd;
75 u8 status;
76 u16 req_id;
77 u32 reserved;
78 u16 data_size;
79} __packed;
80
81#define MEI_NFC_CMD_MAINTENANCE 0x00
82#define MEI_NFC_CMD_HCI_SEND 0x01
83#define MEI_NFC_CMD_HCI_RECV 0x02
84
85#define MEI_NFC_SUBCMD_CONNECT 0x00
86#define MEI_NFC_SUBCMD_IF_VERSION 0x01
87
88#define MEI_NFC_HEADER_SIZE 10
89
90/** mei_nfc_dev - NFC mei device
91 *
92 * @cl: NFC host client
93 * @cl_info: NFC info host client
94 * @init_work: perform connection to the info client
95 * @fw_ivn: NFC Intervace Version Number
96 * @vendor_id: NFC manufacturer ID
97 * @radio_type: NFC radio type
98 */
99struct mei_nfc_dev {
100 struct mei_cl *cl;
101 struct mei_cl *cl_info;
102 struct work_struct init_work;
103 wait_queue_head_t send_wq;
104 u8 fw_ivn;
105 u8 vendor_id;
106 u8 radio_type;
107 char *bus_name;
108
109 u16 req_id;
110 u16 recv_req_id;
111};
112
113static struct mei_nfc_dev nfc_dev;
114
115/* UUIDs for NFC F/W clients */
116const uuid_le mei_nfc_guid = UUID_LE(0x0bb17a78, 0x2a8e, 0x4c50,
117 0x94, 0xd4, 0x50, 0x26,
118 0x67, 0x23, 0x77, 0x5c);
119
120static const uuid_le mei_nfc_info_guid = UUID_LE(0xd2de1625, 0x382d, 0x417d,
121 0x48, 0xa4, 0xef, 0xab,
122 0xba, 0x8a, 0x12, 0x06);
123
124/* Vendors */
125#define MEI_NFC_VENDOR_INSIDE 0x00
126#define MEI_NFC_VENDOR_NXP 0x01
127
128/* Radio types */
129#define MEI_NFC_VENDOR_INSIDE_UREAD 0x00
130#define MEI_NFC_VENDOR_NXP_PN544 0x01
131
132static void mei_nfc_free(struct mei_nfc_dev *ndev)
133{
134 if (ndev->cl) {
135 list_del(&ndev->cl->device_link);
136 mei_cl_unlink(ndev->cl);
137 kfree(ndev->cl);
138 }
139
140 if (ndev->cl_info) {
141 list_del(&ndev->cl_info->device_link);
142 mei_cl_unlink(ndev->cl_info);
143 kfree(ndev->cl_info);
144 }
145}
146
147static int mei_nfc_build_bus_name(struct mei_nfc_dev *ndev)
148{
149 struct mei_device *dev;
150
151 if (!ndev->cl)
152 return -ENODEV;
153
154 dev = ndev->cl->dev;
155
156 switch (ndev->vendor_id) {
157 case MEI_NFC_VENDOR_INSIDE:
158 switch (ndev->radio_type) {
159 case MEI_NFC_VENDOR_INSIDE_UREAD:
160 ndev->bus_name = "microread";
161 return 0;
162
163 default:
164 dev_err(&dev->pdev->dev, "Unknow radio type 0x%x\n",
165 ndev->radio_type);
166
167 return -EINVAL;
168 }
169
170 case MEI_NFC_VENDOR_NXP:
171 switch (ndev->radio_type) {
172 case MEI_NFC_VENDOR_NXP_PN544:
173 ndev->bus_name = "pn544";
174 return 0;
175 default:
176 dev_err(&dev->pdev->dev, "Unknow radio type 0x%x\n",
177 ndev->radio_type);
178
179 return -EINVAL;
180 }
181
182 default:
183 dev_err(&dev->pdev->dev, "Unknow vendor ID 0x%x\n",
184 ndev->vendor_id);
185
186 return -EINVAL;
187 }
188
189 return 0;
190}
191
192static int mei_nfc_connect(struct mei_nfc_dev *ndev)
193{
194 struct mei_device *dev;
195 struct mei_cl *cl;
196 struct mei_nfc_cmd *cmd, *reply;
197 struct mei_nfc_connect *connect;
198 struct mei_nfc_connect_resp *connect_resp;
199 size_t connect_length, connect_resp_length;
200 int bytes_recv, ret;
201
202 cl = ndev->cl;
203 dev = cl->dev;
204
205 connect_length = sizeof(struct mei_nfc_cmd) +
206 sizeof(struct mei_nfc_connect);
207
208 connect_resp_length = sizeof(struct mei_nfc_cmd) +
209 sizeof(struct mei_nfc_connect_resp);
210
211 cmd = kzalloc(connect_length, GFP_KERNEL);
212 if (!cmd)
213 return -ENOMEM;
214 connect = (struct mei_nfc_connect *)cmd->data;
215
216 reply = kzalloc(connect_resp_length, GFP_KERNEL);
217 if (!reply) {
218 kfree(cmd);
219 return -ENOMEM;
220 }
221
222 connect_resp = (struct mei_nfc_connect_resp *)reply->data;
223
224 cmd->command = MEI_NFC_CMD_MAINTENANCE;
225 cmd->data_size = 3;
226 cmd->sub_command = MEI_NFC_SUBCMD_CONNECT;
227 connect->fw_ivn = ndev->fw_ivn;
228 connect->vendor_id = ndev->vendor_id;
229
230 ret = __mei_cl_send(cl, (u8 *)cmd, connect_length);
231 if (ret < 0) {
232 dev_err(&dev->pdev->dev, "Could not send connect cmd\n");
233 goto err;
234 }
235
236 bytes_recv = __mei_cl_recv(cl, (u8 *)reply, connect_resp_length);
237 if (bytes_recv < 0) {
238 dev_err(&dev->pdev->dev, "Could not read connect response\n");
239 ret = bytes_recv;
240 goto err;
241 }
242
243 dev_info(&dev->pdev->dev, "IVN 0x%x Vendor ID 0x%x\n",
244 connect_resp->fw_ivn, connect_resp->vendor_id);
245
246 dev_info(&dev->pdev->dev, "ME FW %d.%d.%d.%d\n",
247 connect_resp->me_major, connect_resp->me_minor,
248 connect_resp->me_hotfix, connect_resp->me_build);
249
250 ret = 0;
251
252err:
253 kfree(reply);
254 kfree(cmd);
255
256 return ret;
257}
258
259static int mei_nfc_if_version(struct mei_nfc_dev *ndev)
260{
261 struct mei_device *dev;
262 struct mei_cl *cl;
263
264 struct mei_nfc_cmd cmd;
265 struct mei_nfc_reply *reply = NULL;
266 struct mei_nfc_if_version *version;
267 size_t if_version_length;
268 int bytes_recv, ret;
269
270 cl = ndev->cl_info;
271 dev = cl->dev;
272
273 memset(&cmd, 0, sizeof(struct mei_nfc_cmd));
274 cmd.command = MEI_NFC_CMD_MAINTENANCE;
275 cmd.data_size = 1;
276 cmd.sub_command = MEI_NFC_SUBCMD_IF_VERSION;
277
278 ret = __mei_cl_send(cl, (u8 *)&cmd, sizeof(struct mei_nfc_cmd));
279 if (ret < 0) {
280 dev_err(&dev->pdev->dev, "Could not send IF version cmd\n");
281 return ret;
282 }
283
284 /* to be sure on the stack we alloc memory */
285 if_version_length = sizeof(struct mei_nfc_reply) +
286 sizeof(struct mei_nfc_if_version);
287
288 reply = kzalloc(if_version_length, GFP_KERNEL);
289 if (!reply)
290 return -ENOMEM;
291
292 bytes_recv = __mei_cl_recv(cl, (u8 *)reply, if_version_length);
293 if (bytes_recv < 0 || bytes_recv < sizeof(struct mei_nfc_reply)) {
294 dev_err(&dev->pdev->dev, "Could not read IF version\n");
295 ret = -EIO;
296 goto err;
297 }
298
299 version = (struct mei_nfc_if_version *)reply->data;
300
301 ndev->fw_ivn = version->fw_ivn;
302 ndev->vendor_id = version->vendor_id;
303 ndev->radio_type = version->radio_type;
304
305err:
306 kfree(reply);
307 return ret;
308}
309
310static int mei_nfc_enable(struct mei_cl_device *cldev)
311{
312 struct mei_device *dev;
313 struct mei_nfc_dev *ndev = &nfc_dev;
314 int ret;
315
316 dev = ndev->cl->dev;
317
318 ret = mei_nfc_connect(ndev);
319 if (ret < 0) {
320 dev_err(&dev->pdev->dev, "Could not connect to NFC");
321 return ret;
322 }
323
324 return 0;
325}
326
327static int mei_nfc_disable(struct mei_cl_device *cldev)
328{
329 return 0;
330}
331
332static int mei_nfc_send(struct mei_cl_device *cldev, u8 *buf, size_t length)
333{
334 struct mei_device *dev;
335 struct mei_nfc_dev *ndev;
336 struct mei_nfc_hci_hdr *hdr;
337 u8 *mei_buf;
338 int err;
339
340 ndev = (struct mei_nfc_dev *) cldev->priv_data;
341 dev = ndev->cl->dev;
342
343 mei_buf = kzalloc(length + MEI_NFC_HEADER_SIZE, GFP_KERNEL);
344 if (!mei_buf)
345 return -ENOMEM;
346
347 hdr = (struct mei_nfc_hci_hdr *) mei_buf;
348 hdr->cmd = MEI_NFC_CMD_HCI_SEND;
349 hdr->status = 0;
350 hdr->req_id = ndev->req_id;
351 hdr->reserved = 0;
352 hdr->data_size = length;
353
354 memcpy(mei_buf + MEI_NFC_HEADER_SIZE, buf, length);
355
356 err = __mei_cl_send(ndev->cl, mei_buf, length + MEI_NFC_HEADER_SIZE);
357 if (err < 0)
358 return err;
359
360 kfree(mei_buf);
361
362 if (!wait_event_interruptible_timeout(ndev->send_wq,
363 ndev->recv_req_id == ndev->req_id, HZ)) {
364 dev_err(&dev->pdev->dev, "NFC MEI command timeout\n");
365 err = -ETIMEDOUT;
366 } else {
367 ndev->req_id++;
368 }
369
370 return err;
371}
372
373static int mei_nfc_recv(struct mei_cl_device *cldev, u8 *buf, size_t length)
374{
375 struct mei_nfc_dev *ndev;
376 struct mei_nfc_hci_hdr *hci_hdr;
377 int received_length;
378
379 ndev = (struct mei_nfc_dev *)cldev->priv_data;
380
381 received_length = __mei_cl_recv(ndev->cl, buf, length);
382 if (received_length < 0)
383 return received_length;
384
385 hci_hdr = (struct mei_nfc_hci_hdr *) buf;
386
387 if (hci_hdr->cmd == MEI_NFC_CMD_HCI_SEND) {
388 ndev->recv_req_id = hci_hdr->req_id;
389 wake_up(&ndev->send_wq);
390
391 return 0;
392 }
393
394 return received_length;
395}
396
397static struct mei_cl_ops nfc_ops = {
398 .enable = mei_nfc_enable,
399 .disable = mei_nfc_disable,
400 .send = mei_nfc_send,
401 .recv = mei_nfc_recv,
402};
403
404static void mei_nfc_init(struct work_struct *work)
405{
406 struct mei_device *dev;
407 struct mei_cl_device *cldev;
408 struct mei_nfc_dev *ndev;
409 struct mei_cl *cl_info;
410
411 ndev = container_of(work, struct mei_nfc_dev, init_work);
412
413 cl_info = ndev->cl_info;
414 dev = cl_info->dev;
415
416 mutex_lock(&dev->device_lock);
417
418 if (mei_cl_connect(cl_info, NULL) < 0) {
419 mutex_unlock(&dev->device_lock);
420 dev_err(&dev->pdev->dev,
421 "Could not connect to the NFC INFO ME client");
422
423 goto err;
424 }
425
426 mutex_unlock(&dev->device_lock);
427
428 if (mei_nfc_if_version(ndev) < 0) {
429 dev_err(&dev->pdev->dev, "Could not get the NFC interfave version");
430
431 goto err;
432 }
433
434 dev_info(&dev->pdev->dev,
435 "NFC MEI VERSION: IVN 0x%x Vendor ID 0x%x Type 0x%x\n",
436 ndev->fw_ivn, ndev->vendor_id, ndev->radio_type);
437
438 mutex_lock(&dev->device_lock);
439
440 if (mei_cl_disconnect(cl_info) < 0) {
441 mutex_unlock(&dev->device_lock);
442 dev_err(&dev->pdev->dev,
443 "Could not disconnect the NFC INFO ME client");
444
445 goto err;
446 }
447
448 mutex_unlock(&dev->device_lock);
449
450 if (mei_nfc_build_bus_name(ndev) < 0) {
451 dev_err(&dev->pdev->dev,
452 "Could not build the bus ID name\n");
453 return;
454 }
455
456 cldev = mei_cl_add_device(dev, mei_nfc_guid, ndev->bus_name, &nfc_ops);
457 if (!cldev) {
458 dev_err(&dev->pdev->dev,
459 "Could not add the NFC device to the MEI bus\n");
460
461 goto err;
462 }
463
464 cldev->priv_data = ndev;
465
466
467 return;
468
469err:
470 mei_nfc_free(ndev);
471
472 return;
473}
474
475
476int mei_nfc_host_init(struct mei_device *dev)
477{
478 struct mei_nfc_dev *ndev = &nfc_dev;
479 struct mei_cl *cl_info, *cl = NULL;
480 int i, ret;
481
482 /* already initialzed */
483 if (ndev->cl_info)
484 return 0;
485
486 cl_info = mei_cl_allocate(dev);
487 cl = mei_cl_allocate(dev);
488
489 if (!cl || !cl_info) {
490 ret = -ENOMEM;
491 goto err;
492 }
493
494 /* check for valid client id */
495 i = mei_me_cl_by_uuid(dev, &mei_nfc_info_guid);
496 if (i < 0) {
497 dev_info(&dev->pdev->dev, "nfc: failed to find the client\n");
498 ret = -ENOENT;
499 goto err;
500 }
501
502 cl_info->me_client_id = dev->me_clients[i].client_id;
503
504 ret = mei_cl_link(cl_info, MEI_HOST_CLIENT_ID_ANY);
505 if (ret)
506 goto err;
507
508 cl_info->device_uuid = mei_nfc_info_guid;
509
510 list_add_tail(&cl_info->device_link, &dev->device_list);
511
512 /* check for valid client id */
513 i = mei_me_cl_by_uuid(dev, &mei_nfc_guid);
514 if (i < 0) {
515 dev_info(&dev->pdev->dev, "nfc: failed to find the client\n");
516 ret = -ENOENT;
517 goto err;
518 }
519
520 cl->me_client_id = dev->me_clients[i].client_id;
521
522 ret = mei_cl_link(cl, MEI_HOST_CLIENT_ID_ANY);
523 if (ret)
524 goto err;
525
526 cl->device_uuid = mei_nfc_guid;
527
528 list_add_tail(&cl->device_link, &dev->device_list);
529
530 ndev->cl_info = cl_info;
531 ndev->cl = cl;
532 ndev->req_id = 1;
533
534 INIT_WORK(&ndev->init_work, mei_nfc_init);
535 init_waitqueue_head(&ndev->send_wq);
536 schedule_work(&ndev->init_work);
537
538 return 0;
539
540err:
541 mei_nfc_free(ndev);
542
543 return ret;
544}
545
546void mei_nfc_host_exit(void)
547{
548 struct mei_nfc_dev *ndev = &nfc_dev;
549
550 if (ndev->cl && ndev->cl->device)
551 mei_cl_remove_device(ndev->cl->device);
552
553 mei_nfc_free(ndev);
554}
diff --git a/drivers/misc/mei/pci-me.c b/drivers/misc/mei/pci-me.c
index b8b5c9c3ad03..88aec6a90ff4 100644
--- a/drivers/misc/mei/pci-me.c
+++ b/drivers/misc/mei/pci-me.c
@@ -47,7 +47,7 @@
47static struct pci_dev *mei_pdev; 47static struct pci_dev *mei_pdev;
48 48
49/* mei_pci_tbl - PCI Device ID Table */ 49/* mei_pci_tbl - PCI Device ID Table */
50static DEFINE_PCI_DEVICE_TABLE(mei_pci_tbl) = { 50static DEFINE_PCI_DEVICE_TABLE(mei_me_pci_tbl) = {
51 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82946GZ)}, 51 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82946GZ)},
52 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82G35)}, 52 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82G35)},
53 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82Q965)}, 53 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82Q965)},
@@ -86,7 +86,7 @@ static DEFINE_PCI_DEVICE_TABLE(mei_pci_tbl) = {
86 {0, } 86 {0, }
87}; 87};
88 88
89MODULE_DEVICE_TABLE(pci, mei_pci_tbl); 89MODULE_DEVICE_TABLE(pci, mei_me_pci_tbl);
90 90
91static DEFINE_MUTEX(mei_mutex); 91static DEFINE_MUTEX(mei_mutex);
92 92
@@ -97,7 +97,7 @@ static DEFINE_MUTEX(mei_mutex);
97 * 97 *
98 * returns true if ME Interface is valid, false otherwise 98 * returns true if ME Interface is valid, false otherwise
99 */ 99 */
100static bool mei_quirk_probe(struct pci_dev *pdev, 100static bool mei_me_quirk_probe(struct pci_dev *pdev,
101 const struct pci_device_id *ent) 101 const struct pci_device_id *ent)
102{ 102{
103 u32 reg; 103 u32 reg;
@@ -119,7 +119,7 @@ static bool mei_quirk_probe(struct pci_dev *pdev,
119 * 119 *
120 * returns 0 on success, <0 on failure. 120 * returns 0 on success, <0 on failure.
121 */ 121 */
122static int mei_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 122static int mei_me_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
123{ 123{
124 struct mei_device *dev; 124 struct mei_device *dev;
125 struct mei_me_hw *hw; 125 struct mei_me_hw *hw;
@@ -127,7 +127,7 @@ static int mei_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
127 127
128 mutex_lock(&mei_mutex); 128 mutex_lock(&mei_mutex);
129 129
130 if (!mei_quirk_probe(pdev, ent)) { 130 if (!mei_me_quirk_probe(pdev, ent)) {
131 err = -ENODEV; 131 err = -ENODEV;
132 goto end; 132 goto end;
133 } 133 }
@@ -184,20 +184,19 @@ static int mei_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
184 goto disable_msi; 184 goto disable_msi;
185 } 185 }
186 186
187 if (mei_hw_init(dev)) { 187 if (mei_start(dev)) {
188 dev_err(&pdev->dev, "init hw failure.\n"); 188 dev_err(&pdev->dev, "init hw failure.\n");
189 err = -ENODEV; 189 err = -ENODEV;
190 goto release_irq; 190 goto release_irq;
191 } 191 }
192 192
193 err = mei_register(&pdev->dev); 193 err = mei_register(dev);
194 if (err) 194 if (err)
195 goto release_irq; 195 goto release_irq;
196 196
197 mei_pdev = pdev; 197 mei_pdev = pdev;
198 pci_set_drvdata(pdev, dev); 198 pci_set_drvdata(pdev, dev);
199 199
200
201 schedule_delayed_work(&dev->timer_work, HZ); 200 schedule_delayed_work(&dev->timer_work, HZ);
202 201
203 mutex_unlock(&mei_mutex); 202 mutex_unlock(&mei_mutex);
@@ -233,7 +232,7 @@ end:
233 * mei_remove is called by the PCI subsystem to alert the driver 232 * mei_remove is called by the PCI subsystem to alert the driver
234 * that it should release a PCI device. 233 * that it should release a PCI device.
235 */ 234 */
236static void mei_remove(struct pci_dev *pdev) 235static void mei_me_remove(struct pci_dev *pdev)
237{ 236{
238 struct mei_device *dev; 237 struct mei_device *dev;
239 struct mei_me_hw *hw; 238 struct mei_me_hw *hw;
@@ -253,8 +252,6 @@ static void mei_remove(struct pci_dev *pdev)
253 252
254 mei_pdev = NULL; 253 mei_pdev = NULL;
255 254
256 mei_watchdog_unregister(dev);
257
258 /* disable interrupts */ 255 /* disable interrupts */
259 mei_disable_interrupts(dev); 256 mei_disable_interrupts(dev);
260 257
@@ -265,16 +262,17 @@ static void mei_remove(struct pci_dev *pdev)
265 if (hw->mem_addr) 262 if (hw->mem_addr)
266 pci_iounmap(pdev, hw->mem_addr); 263 pci_iounmap(pdev, hw->mem_addr);
267 264
265 mei_deregister(dev);
266
268 kfree(dev); 267 kfree(dev);
269 268
270 pci_release_regions(pdev); 269 pci_release_regions(pdev);
271 pci_disable_device(pdev); 270 pci_disable_device(pdev);
272 271
273 mei_deregister();
274 272
275} 273}
276#ifdef CONFIG_PM 274#ifdef CONFIG_PM
277static int mei_pci_suspend(struct device *device) 275static int mei_me_pci_suspend(struct device *device)
278{ 276{
279 struct pci_dev *pdev = to_pci_dev(device); 277 struct pci_dev *pdev = to_pci_dev(device);
280 struct mei_device *dev = pci_get_drvdata(pdev); 278 struct mei_device *dev = pci_get_drvdata(pdev);
@@ -294,7 +292,7 @@ static int mei_pci_suspend(struct device *device)
294 return 0; 292 return 0;
295} 293}
296 294
297static int mei_pci_resume(struct device *device) 295static int mei_me_pci_resume(struct device *device)
298{ 296{
299 struct pci_dev *pdev = to_pci_dev(device); 297 struct pci_dev *pdev = to_pci_dev(device);
300 struct mei_device *dev; 298 struct mei_device *dev;
@@ -334,24 +332,24 @@ static int mei_pci_resume(struct device *device)
334 332
335 return err; 333 return err;
336} 334}
337static SIMPLE_DEV_PM_OPS(mei_pm_ops, mei_pci_suspend, mei_pci_resume); 335static SIMPLE_DEV_PM_OPS(mei_me_pm_ops, mei_me_pci_suspend, mei_me_pci_resume);
338#define MEI_PM_OPS (&mei_pm_ops) 336#define MEI_ME_PM_OPS (&mei_me_pm_ops)
339#else 337#else
340#define MEI_PM_OPS NULL 338#define MEI_ME_PM_OPS NULL
341#endif /* CONFIG_PM */ 339#endif /* CONFIG_PM */
342/* 340/*
343 * PCI driver structure 341 * PCI driver structure
344 */ 342 */
345static struct pci_driver mei_driver = { 343static struct pci_driver mei_me_driver = {
346 .name = KBUILD_MODNAME, 344 .name = KBUILD_MODNAME,
347 .id_table = mei_pci_tbl, 345 .id_table = mei_me_pci_tbl,
348 .probe = mei_probe, 346 .probe = mei_me_probe,
349 .remove = mei_remove, 347 .remove = mei_me_remove,
350 .shutdown = mei_remove, 348 .shutdown = mei_me_remove,
351 .driver.pm = MEI_PM_OPS, 349 .driver.pm = MEI_ME_PM_OPS,
352}; 350};
353 351
354module_pci_driver(mei_driver); 352module_pci_driver(mei_me_driver);
355 353
356MODULE_AUTHOR("Intel Corporation"); 354MODULE_AUTHOR("Intel Corporation");
357MODULE_DESCRIPTION("Intel(R) Management Engine Interface"); 355MODULE_DESCRIPTION("Intel(R) Management Engine Interface");
diff --git a/drivers/misc/mei/wd.c b/drivers/misc/mei/wd.c
index 2413247fc392..eb3f05c8d7d0 100644
--- a/drivers/misc/mei/wd.c
+++ b/drivers/misc/mei/wd.c
@@ -317,7 +317,8 @@ end:
317 * 317 *
318 * returns 0 if success, negative errno code for failure 318 * returns 0 if success, negative errno code for failure
319 */ 319 */
320static int mei_wd_ops_set_timeout(struct watchdog_device *wd_dev, unsigned int timeout) 320static int mei_wd_ops_set_timeout(struct watchdog_device *wd_dev,
321 unsigned int timeout)
321{ 322{
322 struct mei_device *dev; 323 struct mei_device *dev;
323 324
diff --git a/drivers/misc/tsl2550.c b/drivers/misc/tsl2550.c
index 1e7bc0eb081e..1dfde4d543db 100644
--- a/drivers/misc/tsl2550.c
+++ b/drivers/misc/tsl2550.c
@@ -417,24 +417,26 @@ static int tsl2550_remove(struct i2c_client *client)
417 return 0; 417 return 0;
418} 418}
419 419
420#ifdef CONFIG_PM 420#ifdef CONFIG_PM_SLEEP
421 421
422static int tsl2550_suspend(struct i2c_client *client, pm_message_t mesg) 422static int tsl2550_suspend(struct device *dev)
423{ 423{
424 return tsl2550_set_power_state(client, 0); 424 return tsl2550_set_power_state(to_i2c_client(dev), 0);
425} 425}
426 426
427static int tsl2550_resume(struct i2c_client *client) 427static int tsl2550_resume(struct device *dev)
428{ 428{
429 return tsl2550_set_power_state(client, 1); 429 return tsl2550_set_power_state(to_i2c_client(dev), 1);
430} 430}
431 431
432static SIMPLE_DEV_PM_OPS(tsl2550_pm_ops, tsl2550_suspend, tsl2550_resume);
433#define TSL2550_PM_OPS (&tsl2550_pm_ops)
434
432#else 435#else
433 436
434#define tsl2550_suspend NULL 437#define TSL2550_PM_OPS NULL
435#define tsl2550_resume NULL
436 438
437#endif /* CONFIG_PM */ 439#endif /* CONFIG_PM_SLEEP */
438 440
439static const struct i2c_device_id tsl2550_id[] = { 441static const struct i2c_device_id tsl2550_id[] = {
440 { "tsl2550", 0 }, 442 { "tsl2550", 0 },
@@ -446,9 +448,8 @@ static struct i2c_driver tsl2550_driver = {
446 .driver = { 448 .driver = {
447 .name = TSL2550_DRV_NAME, 449 .name = TSL2550_DRV_NAME,
448 .owner = THIS_MODULE, 450 .owner = THIS_MODULE,
451 .pm = TSL2550_PM_OPS,
449 }, 452 },
450 .suspend = tsl2550_suspend,
451 .resume = tsl2550_resume,
452 .probe = tsl2550_probe, 453 .probe = tsl2550_probe,
453 .remove = tsl2550_remove, 454 .remove = tsl2550_remove,
454 .id_table = tsl2550_id, 455 .id_table = tsl2550_id,
diff --git a/drivers/mmc/host/sdricoh_cs.c b/drivers/mmc/host/sdricoh_cs.c
index 7009f17ad6cd..50adbd155f35 100644
--- a/drivers/mmc/host/sdricoh_cs.c
+++ b/drivers/mmc/host/sdricoh_cs.c
@@ -543,25 +543,7 @@ static struct pcmcia_driver sdricoh_driver = {
543 .suspend = sdricoh_pcmcia_suspend, 543 .suspend = sdricoh_pcmcia_suspend,
544 .resume = sdricoh_pcmcia_resume, 544 .resume = sdricoh_pcmcia_resume,
545}; 545};
546 546module_pcmcia_driver(sdricoh_driver);
547/*****************************************************************************\
548 * *
549 * Driver init/exit *
550 * *
551\*****************************************************************************/
552
553static int __init sdricoh_drv_init(void)
554{
555 return pcmcia_register_driver(&sdricoh_driver);
556}
557
558static void __exit sdricoh_drv_exit(void)
559{
560 pcmcia_unregister_driver(&sdricoh_driver);
561}
562
563module_init(sdricoh_drv_init);
564module_exit(sdricoh_drv_exit);
565 547
566module_param(switchlocked, uint, 0444); 548module_param(switchlocked, uint, 0444);
567 549
diff --git a/drivers/net/arcnet/com20020_cs.c b/drivers/net/arcnet/com20020_cs.c
index 5bed4c4e2508..74dc1875f9cd 100644
--- a/drivers/net/arcnet/com20020_cs.c
+++ b/drivers/net/arcnet/com20020_cs.c
@@ -333,16 +333,4 @@ static struct pcmcia_driver com20020_cs_driver = {
333 .suspend = com20020_suspend, 333 .suspend = com20020_suspend,
334 .resume = com20020_resume, 334 .resume = com20020_resume,
335}; 335};
336 336module_pcmcia_driver(com20020_cs_driver);
337static int __init init_com20020_cs(void)
338{
339 return pcmcia_register_driver(&com20020_cs_driver);
340}
341
342static void __exit exit_com20020_cs(void)
343{
344 pcmcia_unregister_driver(&com20020_cs_driver);
345}
346
347module_init(init_com20020_cs);
348module_exit(exit_com20020_cs);
diff --git a/drivers/net/can/sja1000/ems_pcmcia.c b/drivers/net/can/sja1000/ems_pcmcia.c
index 5c2f3fbbf5ae..321c27e1c7fc 100644
--- a/drivers/net/can/sja1000/ems_pcmcia.c
+++ b/drivers/net/can/sja1000/ems_pcmcia.c
@@ -316,15 +316,4 @@ static struct pcmcia_driver ems_pcmcia_driver = {
316 .remove = ems_pcmcia_remove, 316 .remove = ems_pcmcia_remove,
317 .id_table = ems_pcmcia_tbl, 317 .id_table = ems_pcmcia_tbl,
318}; 318};
319 319module_pcmcia_driver(ems_pcmcia_driver);
320static int __init ems_pcmcia_init(void)
321{
322 return pcmcia_register_driver(&ems_pcmcia_driver);
323}
324module_init(ems_pcmcia_init);
325
326static void __exit ems_pcmcia_exit(void)
327{
328 pcmcia_unregister_driver(&ems_pcmcia_driver);
329}
330module_exit(ems_pcmcia_exit);
diff --git a/drivers/net/can/sja1000/peak_pcmcia.c b/drivers/net/can/sja1000/peak_pcmcia.c
index 1a7020ba37f5..0a707f70661c 100644
--- a/drivers/net/can/sja1000/peak_pcmcia.c
+++ b/drivers/net/can/sja1000/peak_pcmcia.c
@@ -740,15 +740,4 @@ static struct pcmcia_driver pcan_driver = {
740 .remove = pcan_remove, 740 .remove = pcan_remove,
741 .id_table = pcan_table, 741 .id_table = pcan_table,
742}; 742};
743 743module_pcmcia_driver(pcan_driver);
744static int __init pcan_init(void)
745{
746 return pcmcia_register_driver(&pcan_driver);
747}
748module_init(pcan_init);
749
750static void __exit pcan_exit(void)
751{
752 pcmcia_unregister_driver(&pcan_driver);
753}
754module_exit(pcan_exit);
diff --git a/drivers/net/can/softing/softing_cs.c b/drivers/net/can/softing/softing_cs.c
index c2c0a5bb0b21..498605f833dd 100644
--- a/drivers/net/can/softing/softing_cs.c
+++ b/drivers/net/can/softing/softing_cs.c
@@ -27,7 +27,7 @@
27#include "softing_platform.h" 27#include "softing_platform.h"
28 28
29static int softingcs_index; 29static int softingcs_index;
30static spinlock_t softingcs_index_lock; 30static DEFINE_SPINLOCK(softingcs_index_lock);
31 31
32static int softingcs_reset(struct platform_device *pdev, int v); 32static int softingcs_reset(struct platform_device *pdev, int v);
33static int softingcs_enable_irq(struct platform_device *pdev, int v); 33static int softingcs_enable_irq(struct platform_device *pdev, int v);
@@ -340,19 +340,7 @@ static struct pcmcia_driver softingcs_driver = {
340 .remove = softingcs_remove, 340 .remove = softingcs_remove,
341}; 341};
342 342
343static int __init softingcs_start(void) 343module_pcmcia_driver(softingcs_driver);
344{
345 spin_lock_init(&softingcs_index_lock);
346 return pcmcia_register_driver(&softingcs_driver);
347}
348
349static void __exit softingcs_stop(void)
350{
351 pcmcia_unregister_driver(&softingcs_driver);
352}
353
354module_init(softingcs_start);
355module_exit(softingcs_stop);
356 344
357MODULE_DESCRIPTION("softing CANcard driver" 345MODULE_DESCRIPTION("softing CANcard driver"
358 ", links PCMCIA card to softing driver"); 346 ", links PCMCIA card to softing driver");
diff --git a/drivers/net/ethernet/3com/3c574_cs.c b/drivers/net/ethernet/3com/3c574_cs.c
index ffd8de28a76a..6fc994fa4abe 100644
--- a/drivers/net/ethernet/3com/3c574_cs.c
+++ b/drivers/net/ethernet/3com/3c574_cs.c
@@ -1165,16 +1165,4 @@ static struct pcmcia_driver tc574_driver = {
1165 .suspend = tc574_suspend, 1165 .suspend = tc574_suspend,
1166 .resume = tc574_resume, 1166 .resume = tc574_resume,
1167}; 1167};
1168 1168module_pcmcia_driver(tc574_driver);
1169static int __init init_tc574(void)
1170{
1171 return pcmcia_register_driver(&tc574_driver);
1172}
1173
1174static void __exit exit_tc574(void)
1175{
1176 pcmcia_unregister_driver(&tc574_driver);
1177}
1178
1179module_init(init_tc574);
1180module_exit(exit_tc574);
diff --git a/drivers/net/ethernet/3com/3c589_cs.c b/drivers/net/ethernet/3com/3c589_cs.c
index a556c01e011b..078480aaa168 100644
--- a/drivers/net/ethernet/3com/3c589_cs.c
+++ b/drivers/net/ethernet/3com/3c589_cs.c
@@ -928,16 +928,4 @@ static struct pcmcia_driver tc589_driver = {
928 .suspend = tc589_suspend, 928 .suspend = tc589_suspend,
929 .resume = tc589_resume, 929 .resume = tc589_resume,
930}; 930};
931 931module_pcmcia_driver(tc589_driver);
932static int __init init_tc589(void)
933{
934 return pcmcia_register_driver(&tc589_driver);
935}
936
937static void __exit exit_tc589(void)
938{
939 pcmcia_unregister_driver(&tc589_driver);
940}
941
942module_init(init_tc589);
943module_exit(exit_tc589);
diff --git a/drivers/net/ethernet/8390/axnet_cs.c b/drivers/net/ethernet/8390/axnet_cs.c
index e1b3941bd149..d801c1410fb0 100644
--- a/drivers/net/ethernet/8390/axnet_cs.c
+++ b/drivers/net/ethernet/8390/axnet_cs.c
@@ -728,19 +728,7 @@ static struct pcmcia_driver axnet_cs_driver = {
728 .suspend = axnet_suspend, 728 .suspend = axnet_suspend,
729 .resume = axnet_resume, 729 .resume = axnet_resume,
730}; 730};
731 731module_pcmcia_driver(axnet_cs_driver);
732static int __init init_axnet_cs(void)
733{
734 return pcmcia_register_driver(&axnet_cs_driver);
735}
736
737static void __exit exit_axnet_cs(void)
738{
739 pcmcia_unregister_driver(&axnet_cs_driver);
740}
741
742module_init(init_axnet_cs);
743module_exit(exit_axnet_cs);
744 732
745/*====================================================================*/ 733/*====================================================================*/
746 734
diff --git a/drivers/net/ethernet/8390/pcnet_cs.c b/drivers/net/ethernet/8390/pcnet_cs.c
index de1af0bfed4c..46c5aadaca8e 100644
--- a/drivers/net/ethernet/8390/pcnet_cs.c
+++ b/drivers/net/ethernet/8390/pcnet_cs.c
@@ -1694,16 +1694,4 @@ static struct pcmcia_driver pcnet_driver = {
1694 .suspend = pcnet_suspend, 1694 .suspend = pcnet_suspend,
1695 .resume = pcnet_resume, 1695 .resume = pcnet_resume,
1696}; 1696};
1697 1697module_pcmcia_driver(pcnet_driver);
1698static int __init init_pcnet_cs(void)
1699{
1700 return pcmcia_register_driver(&pcnet_driver);
1701}
1702
1703static void __exit exit_pcnet_cs(void)
1704{
1705 pcmcia_unregister_driver(&pcnet_driver);
1706}
1707
1708module_init(init_pcnet_cs);
1709module_exit(exit_pcnet_cs);
diff --git a/drivers/net/ethernet/amd/nmclan_cs.c b/drivers/net/ethernet/amd/nmclan_cs.c
index 9f59bf63514b..d4ed89130c52 100644
--- a/drivers/net/ethernet/amd/nmclan_cs.c
+++ b/drivers/net/ethernet/amd/nmclan_cs.c
@@ -1508,16 +1508,4 @@ static struct pcmcia_driver nmclan_cs_driver = {
1508 .suspend = nmclan_suspend, 1508 .suspend = nmclan_suspend,
1509 .resume = nmclan_resume, 1509 .resume = nmclan_resume,
1510}; 1510};
1511 1511module_pcmcia_driver(nmclan_cs_driver);
1512static int __init init_nmclan_cs(void)
1513{
1514 return pcmcia_register_driver(&nmclan_cs_driver);
1515}
1516
1517static void __exit exit_nmclan_cs(void)
1518{
1519 pcmcia_unregister_driver(&nmclan_cs_driver);
1520}
1521
1522module_init(init_nmclan_cs);
1523module_exit(exit_nmclan_cs);
diff --git a/drivers/net/ethernet/fujitsu/fmvj18x_cs.c b/drivers/net/ethernet/fujitsu/fmvj18x_cs.c
index 2418faf2251a..ab98b77df309 100644
--- a/drivers/net/ethernet/fujitsu/fmvj18x_cs.c
+++ b/drivers/net/ethernet/fujitsu/fmvj18x_cs.c
@@ -705,19 +705,7 @@ static struct pcmcia_driver fmvj18x_cs_driver = {
705 .suspend = fmvj18x_suspend, 705 .suspend = fmvj18x_suspend,
706 .resume = fmvj18x_resume, 706 .resume = fmvj18x_resume,
707}; 707};
708 708module_pcmcia_driver(fmvj18x_cs_driver);
709static int __init init_fmvj18x_cs(void)
710{
711 return pcmcia_register_driver(&fmvj18x_cs_driver);
712}
713
714static void __exit exit_fmvj18x_cs(void)
715{
716 pcmcia_unregister_driver(&fmvj18x_cs_driver);
717}
718
719module_init(init_fmvj18x_cs);
720module_exit(exit_fmvj18x_cs);
721 709
722/*====================================================================*/ 710/*====================================================================*/
723 711
diff --git a/drivers/net/ethernet/smsc/smc91c92_cs.c b/drivers/net/ethernet/smsc/smc91c92_cs.c
index 04393b5fef71..656d2e2ebfc9 100644
--- a/drivers/net/ethernet/smsc/smc91c92_cs.c
+++ b/drivers/net/ethernet/smsc/smc91c92_cs.c
@@ -2054,16 +2054,4 @@ static struct pcmcia_driver smc91c92_cs_driver = {
2054 .suspend = smc91c92_suspend, 2054 .suspend = smc91c92_suspend,
2055 .resume = smc91c92_resume, 2055 .resume = smc91c92_resume,
2056}; 2056};
2057 2057module_pcmcia_driver(smc91c92_cs_driver);
2058static int __init init_smc91c92_cs(void)
2059{
2060 return pcmcia_register_driver(&smc91c92_cs_driver);
2061}
2062
2063static void __exit exit_smc91c92_cs(void)
2064{
2065 pcmcia_unregister_driver(&smc91c92_cs_driver);
2066}
2067
2068module_init(init_smc91c92_cs);
2069module_exit(exit_smc91c92_cs);
diff --git a/drivers/net/ethernet/xircom/xirc2ps_cs.c b/drivers/net/ethernet/xircom/xirc2ps_cs.c
index 98e09d0d3ce2..1025b4e937d2 100644
--- a/drivers/net/ethernet/xircom/xirc2ps_cs.c
+++ b/drivers/net/ethernet/xircom/xirc2ps_cs.c
@@ -1775,21 +1775,7 @@ static struct pcmcia_driver xirc2ps_cs_driver = {
1775 .suspend = xirc2ps_suspend, 1775 .suspend = xirc2ps_suspend,
1776 .resume = xirc2ps_resume, 1776 .resume = xirc2ps_resume,
1777}; 1777};
1778 1778module_pcmcia_driver(xirc2ps_cs_driver);
1779static int __init
1780init_xirc2ps_cs(void)
1781{
1782 return pcmcia_register_driver(&xirc2ps_cs_driver);
1783}
1784
1785static void __exit
1786exit_xirc2ps_cs(void)
1787{
1788 pcmcia_unregister_driver(&xirc2ps_cs_driver);
1789}
1790
1791module_init(init_xirc2ps_cs);
1792module_exit(exit_xirc2ps_cs);
1793 1779
1794#ifndef MODULE 1780#ifndef MODULE
1795static int __init setup_xirc2ps_cs(char *str) 1781static int __init setup_xirc2ps_cs(char *str)
diff --git a/drivers/net/wireless/airo_cs.c b/drivers/net/wireless/airo_cs.c
index 956024a636e6..14128fd265ac 100644
--- a/drivers/net/wireless/airo_cs.c
+++ b/drivers/net/wireless/airo_cs.c
@@ -180,16 +180,7 @@ static struct pcmcia_driver airo_driver = {
180 .suspend = airo_suspend, 180 .suspend = airo_suspend,
181 .resume = airo_resume, 181 .resume = airo_resume,
182}; 182};
183 183module_pcmcia_driver(airo_driver);
184static int __init airo_cs_init(void)
185{
186 return pcmcia_register_driver(&airo_driver);
187}
188
189static void __exit airo_cs_cleanup(void)
190{
191 pcmcia_unregister_driver(&airo_driver);
192}
193 184
194/* 185/*
195 This program is free software; you can redistribute it and/or 186 This program is free software; you can redistribute it and/or
@@ -229,6 +220,3 @@ static void __exit airo_cs_cleanup(void)
229 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 220 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
230 POSSIBILITY OF SUCH DAMAGE. 221 POSSIBILITY OF SUCH DAMAGE.
231*/ 222*/
232
233module_init(airo_cs_init);
234module_exit(airo_cs_cleanup);
diff --git a/drivers/net/wireless/atmel_cs.c b/drivers/net/wireless/atmel_cs.c
index b42930f457c2..522572219217 100644
--- a/drivers/net/wireless/atmel_cs.c
+++ b/drivers/net/wireless/atmel_cs.c
@@ -245,16 +245,7 @@ static struct pcmcia_driver atmel_driver = {
245 .suspend = atmel_suspend, 245 .suspend = atmel_suspend,
246 .resume = atmel_resume, 246 .resume = atmel_resume,
247}; 247};
248 248module_pcmcia_driver(atmel_driver);
249static int __init atmel_cs_init(void)
250{
251 return pcmcia_register_driver(&atmel_driver);
252}
253
254static void __exit atmel_cs_cleanup(void)
255{
256 pcmcia_unregister_driver(&atmel_driver);
257}
258 249
259/* 250/*
260 This program is free software; you can redistribute it and/or 251 This program is free software; you can redistribute it and/or
@@ -294,6 +285,3 @@ static void __exit atmel_cs_cleanup(void)
294 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 285 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
295 POSSIBILITY OF SUCH DAMAGE. 286 POSSIBILITY OF SUCH DAMAGE.
296*/ 287*/
297
298module_init(atmel_cs_init);
299module_exit(atmel_cs_cleanup);
diff --git a/drivers/net/wireless/b43/pcmcia.c b/drivers/net/wireless/b43/pcmcia.c
index f2ea2ceec8a9..55f2bd7f8f74 100644
--- a/drivers/net/wireless/b43/pcmcia.c
+++ b/drivers/net/wireless/b43/pcmcia.c
@@ -130,6 +130,10 @@ static struct pcmcia_driver b43_pcmcia_driver = {
130 .resume = b43_pcmcia_resume, 130 .resume = b43_pcmcia_resume,
131}; 131};
132 132
133/*
134 * These are not module init/exit functions!
135 * The module_pcmcia_driver() helper cannot be used here.
136 */
133int b43_pcmcia_init(void) 137int b43_pcmcia_init(void)
134{ 138{
135 return pcmcia_register_driver(&b43_pcmcia_driver); 139 return pcmcia_register_driver(&b43_pcmcia_driver);
diff --git a/drivers/net/wireless/hostap/hostap_cs.c b/drivers/net/wireless/hostap/hostap_cs.c
index 89e9d3a78c3c..56cd01ca8ad0 100644
--- a/drivers/net/wireless/hostap/hostap_cs.c
+++ b/drivers/net/wireless/hostap/hostap_cs.c
@@ -709,17 +709,4 @@ static struct pcmcia_driver hostap_driver = {
709 .suspend = hostap_cs_suspend, 709 .suspend = hostap_cs_suspend,
710 .resume = hostap_cs_resume, 710 .resume = hostap_cs_resume,
711}; 711};
712 712module_pcmcia_driver(hostap_driver);
713static int __init init_prism2_pccard(void)
714{
715 return pcmcia_register_driver(&hostap_driver);
716}
717
718static void __exit exit_prism2_pccard(void)
719{
720 pcmcia_unregister_driver(&hostap_driver);
721}
722
723
724module_init(init_prism2_pccard);
725module_exit(exit_prism2_pccard);
diff --git a/drivers/net/wireless/libertas/if_cs.c b/drivers/net/wireless/libertas/if_cs.c
index 16beaf39dc53..c94dd6802672 100644
--- a/drivers/net/wireless/libertas/if_cs.c
+++ b/drivers/net/wireless/libertas/if_cs.c
@@ -999,7 +999,6 @@ static const struct pcmcia_device_id if_cs_ids[] = {
999}; 999};
1000MODULE_DEVICE_TABLE(pcmcia, if_cs_ids); 1000MODULE_DEVICE_TABLE(pcmcia, if_cs_ids);
1001 1001
1002
1003static struct pcmcia_driver lbs_driver = { 1002static struct pcmcia_driver lbs_driver = {
1004 .owner = THIS_MODULE, 1003 .owner = THIS_MODULE,
1005 .name = DRV_NAME, 1004 .name = DRV_NAME,
@@ -1007,26 +1006,4 @@ static struct pcmcia_driver lbs_driver = {
1007 .remove = if_cs_detach, 1006 .remove = if_cs_detach,
1008 .id_table = if_cs_ids, 1007 .id_table = if_cs_ids,
1009}; 1008};
1010 1009module_pcmcia_driver(lbs_driver);
1011
1012static int __init if_cs_init(void)
1013{
1014 int ret;
1015
1016 lbs_deb_enter(LBS_DEB_CS);
1017 ret = pcmcia_register_driver(&lbs_driver);
1018 lbs_deb_leave(LBS_DEB_CS);
1019 return ret;
1020}
1021
1022
1023static void __exit if_cs_exit(void)
1024{
1025 lbs_deb_enter(LBS_DEB_CS);
1026 pcmcia_unregister_driver(&lbs_driver);
1027 lbs_deb_leave(LBS_DEB_CS);
1028}
1029
1030
1031module_init(if_cs_init);
1032module_exit(if_cs_exit);
diff --git a/drivers/net/wireless/orinoco/orinoco_cs.c b/drivers/net/wireless/orinoco/orinoco_cs.c
index d7dbc00bcfbe..d21d95939316 100644
--- a/drivers/net/wireless/orinoco/orinoco_cs.c
+++ b/drivers/net/wireless/orinoco/orinoco_cs.c
@@ -338,18 +338,4 @@ static struct pcmcia_driver orinoco_driver = {
338 .suspend = orinoco_cs_suspend, 338 .suspend = orinoco_cs_suspend,
339 .resume = orinoco_cs_resume, 339 .resume = orinoco_cs_resume,
340}; 340};
341 341module_pcmcia_driver(orinoco_driver);
342static int __init
343init_orinoco_cs(void)
344{
345 return pcmcia_register_driver(&orinoco_driver);
346}
347
348static void __exit
349exit_orinoco_cs(void)
350{
351 pcmcia_unregister_driver(&orinoco_driver);
352}
353
354module_init(init_orinoco_cs);
355module_exit(exit_orinoco_cs);
diff --git a/drivers/net/wireless/orinoco/spectrum_cs.c b/drivers/net/wireless/orinoco/spectrum_cs.c
index 6e28ee4e9c52..e2264bc12ebf 100644
--- a/drivers/net/wireless/orinoco/spectrum_cs.c
+++ b/drivers/net/wireless/orinoco/spectrum_cs.c
@@ -318,18 +318,4 @@ static struct pcmcia_driver orinoco_driver = {
318 .resume = spectrum_cs_resume, 318 .resume = spectrum_cs_resume,
319 .id_table = spectrum_cs_ids, 319 .id_table = spectrum_cs_ids,
320}; 320};
321 321module_pcmcia_driver(orinoco_driver);
322static int __init
323init_spectrum_cs(void)
324{
325 return pcmcia_register_driver(&orinoco_driver);
326}
327
328static void __exit
329exit_spectrum_cs(void)
330{
331 pcmcia_unregister_driver(&orinoco_driver);
332}
333
334module_init(init_spectrum_cs);
335module_exit(exit_spectrum_cs);
diff --git a/drivers/net/wireless/wl3501_cs.c b/drivers/net/wireless/wl3501_cs.c
index 730186d0449b..38d2089f338a 100644
--- a/drivers/net/wireless/wl3501_cs.c
+++ b/drivers/net/wireless/wl3501_cs.c
@@ -2013,19 +2013,7 @@ static struct pcmcia_driver wl3501_driver = {
2013 .suspend = wl3501_suspend, 2013 .suspend = wl3501_suspend,
2014 .resume = wl3501_resume, 2014 .resume = wl3501_resume,
2015}; 2015};
2016 2016module_pcmcia_driver(wl3501_driver);
2017static int __init wl3501_init_module(void)
2018{
2019 return pcmcia_register_driver(&wl3501_driver);
2020}
2021
2022static void __exit wl3501_exit_module(void)
2023{
2024 pcmcia_unregister_driver(&wl3501_driver);
2025}
2026
2027module_init(wl3501_init_module);
2028module_exit(wl3501_exit_module);
2029 2017
2030MODULE_AUTHOR("Fox Chen <mhchen@golf.ccl.itri.org.tw>, " 2018MODULE_AUTHOR("Fox Chen <mhchen@golf.ccl.itri.org.tw>, "
2031 "Arnaldo Carvalho de Melo <acme@conectiva.com.br>," 2019 "Arnaldo Carvalho de Melo <acme@conectiva.com.br>,"
diff --git a/drivers/parport/parport_amiga.c b/drivers/parport/parport_amiga.c
index ee78e0ee6e05..09503b8d12e6 100644
--- a/drivers/parport/parport_amiga.c
+++ b/drivers/parport/parport_amiga.c
@@ -244,20 +244,7 @@ static struct platform_driver amiga_parallel_driver = {
244 }, 244 },
245}; 245};
246 246
247static int __init amiga_parallel_init(void) 247module_platform_driver_probe(amiga_parallel_driver, amiga_parallel_probe);
248{
249 return platform_driver_probe(&amiga_parallel_driver,
250 amiga_parallel_probe);
251}
252
253module_init(amiga_parallel_init);
254
255static void __exit amiga_parallel_exit(void)
256{
257 platform_driver_unregister(&amiga_parallel_driver);
258}
259
260module_exit(amiga_parallel_exit);
261 248
262MODULE_AUTHOR("Joerg Dorchain <joerg@dorchain.net>"); 249MODULE_AUTHOR("Joerg Dorchain <joerg@dorchain.net>");
263MODULE_DESCRIPTION("Parport Driver for Amiga builtin Port"); 250MODULE_DESCRIPTION("Parport Driver for Amiga builtin Port");
diff --git a/drivers/parport/parport_cs.c b/drivers/parport/parport_cs.c
index 067ad517c1f5..e9b52e4a4648 100644
--- a/drivers/parport/parport_cs.c
+++ b/drivers/parport/parport_cs.c
@@ -193,16 +193,4 @@ static struct pcmcia_driver parport_cs_driver = {
193 .remove = parport_detach, 193 .remove = parport_detach,
194 .id_table = parport_ids, 194 .id_table = parport_ids,
195}; 195};
196 196module_pcmcia_driver(parport_cs_driver);
197static int __init init_parport_cs(void)
198{
199 return pcmcia_register_driver(&parport_cs_driver);
200}
201
202static void __exit exit_parport_cs(void)
203{
204 pcmcia_unregister_driver(&parport_cs_driver);
205}
206
207module_init(init_parport_cs);
208module_exit(exit_parport_cs);
diff --git a/drivers/parport/parport_gsc.c b/drivers/parport/parport_gsc.c
index 050773c36823..a5251cb5fb0c 100644
--- a/drivers/parport/parport_gsc.c
+++ b/drivers/parport/parport_gsc.c
@@ -246,14 +246,14 @@ struct parport *parport_gsc_probe_port(unsigned long base,
246 printk (KERN_DEBUG "parport (0x%lx): no memory!\n", base); 246 printk (KERN_DEBUG "parport (0x%lx): no memory!\n", base);
247 return NULL; 247 return NULL;
248 } 248 }
249 ops = kmalloc (sizeof (struct parport_operations), GFP_KERNEL); 249 ops = kmemdup(&parport_gsc_ops, sizeof(struct parport_operations),
250 GFP_KERNEL);
250 if (!ops) { 251 if (!ops) {
251 printk (KERN_DEBUG "parport (0x%lx): no memory for ops!\n", 252 printk (KERN_DEBUG "parport (0x%lx): no memory for ops!\n",
252 base); 253 base);
253 kfree (priv); 254 kfree (priv);
254 return NULL; 255 return NULL;
255 } 256 }
256 memcpy (ops, &parport_gsc_ops, sizeof (struct parport_operations));
257 priv->ctr = 0xc; 257 priv->ctr = 0xc;
258 priv->ctr_writable = 0xff; 258 priv->ctr_writable = 0xff;
259 priv->dma_buf = 0; 259 priv->dma_buf = 0;
diff --git a/drivers/parport/parport_sunbpp.c b/drivers/parport/parport_sunbpp.c
index 5c4b6a1db6ca..dffd6d0bd15b 100644
--- a/drivers/parport/parport_sunbpp.c
+++ b/drivers/parport/parport_sunbpp.c
@@ -284,12 +284,11 @@ static int bpp_probe(struct platform_device *op)
284 size = resource_size(&op->resource[0]); 284 size = resource_size(&op->resource[0]);
285 dma = PARPORT_DMA_NONE; 285 dma = PARPORT_DMA_NONE;
286 286
287 ops = kmalloc(sizeof(struct parport_operations), GFP_KERNEL); 287 ops = kmemdup(&parport_sunbpp_ops, sizeof(struct parport_operations),
288 GFP_KERNEL);
288 if (!ops) 289 if (!ops)
289 goto out_unmap; 290 goto out_unmap;
290 291
291 memcpy (ops, &parport_sunbpp_ops, sizeof(struct parport_operations));
292
293 dprintk(("register_port\n")); 292 dprintk(("register_port\n"));
294 if (!(p = parport_register_port((unsigned long)base, irq, dma, ops))) 293 if (!(p = parport_register_port((unsigned long)base, irq, dma, ops)))
295 goto out_free_ops; 294 goto out_free_ops;
diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
index 3f56bc086cb5..92ed045a5f93 100644
--- a/drivers/parport/procfs.c
+++ b/drivers/parport/procfs.c
@@ -476,10 +476,9 @@ int parport_proc_register(struct parport *port)
476 struct parport_sysctl_table *t; 476 struct parport_sysctl_table *t;
477 int i; 477 int i;
478 478
479 t = kmalloc(sizeof(*t), GFP_KERNEL); 479 t = kmemdup(&parport_sysctl_template, sizeof(*t), GFP_KERNEL);
480 if (t == NULL) 480 if (t == NULL)
481 return -ENOMEM; 481 return -ENOMEM;
482 memcpy(t, &parport_sysctl_template, sizeof(*t));
483 482
484 t->device_dir[0].extra1 = port; 483 t->device_dir[0].extra1 = port;
485 484
@@ -523,10 +522,9 @@ int parport_device_proc_register(struct pardevice *device)
523 struct parport_device_sysctl_table *t; 522 struct parport_device_sysctl_table *t;
524 struct parport * port = device->port; 523 struct parport * port = device->port;
525 524
526 t = kmalloc(sizeof(*t), GFP_KERNEL); 525 t = kmemdup(&parport_device_sysctl_template, sizeof(*t), GFP_KERNEL);
527 if (t == NULL) 526 if (t == NULL)
528 return -ENOMEM; 527 return -ENOMEM;
529 memcpy(t, &parport_device_sysctl_template, sizeof(*t));
530 528
531 t->dev_dir[0].child = t->parport_dir; 529 t->dev_dir[0].child = t->parport_dir;
532 t->parport_dir[0].child = t->port_dir; 530 t->parport_dir[0].child = t->port_dir;
diff --git a/drivers/ssbi/Kconfig b/drivers/ssbi/Kconfig
new file mode 100644
index 000000000000..1ae4040afedd
--- /dev/null
+++ b/drivers/ssbi/Kconfig
@@ -0,0 +1,16 @@
1#
2# SSBI bus support
3#
4
5menu "Qualcomm MSM SSBI bus support"
6
7config SSBI
8 tristate "Qualcomm Single-wire Serial Bus Interface (SSBI)"
9 help
10 If you say yes to this option, support will be included for the
11 built-in SSBI interface on Qualcomm MSM family processors.
12
13 This is required for communicating with Qualcomm PMICs and
14 other devices that have the SSBI interface.
15
16endmenu
diff --git a/drivers/ssbi/Makefile b/drivers/ssbi/Makefile
new file mode 100644
index 000000000000..38fb70c31caf
--- /dev/null
+++ b/drivers/ssbi/Makefile
@@ -0,0 +1 @@
obj-$(CONFIG_SSBI) += ssbi.o
diff --git a/drivers/ssbi/ssbi.c b/drivers/ssbi/ssbi.c
new file mode 100644
index 000000000000..f32da0258a8e
--- /dev/null
+++ b/drivers/ssbi/ssbi.c
@@ -0,0 +1,379 @@
1/* Copyright (c) 2009-2013, The Linux Foundation. All rights reserved.
2 * Copyright (c) 2010, Google Inc.
3 *
4 * Original authors: Code Aurora Forum
5 *
6 * Author: Dima Zavin <dima@android.com>
7 * - Largely rewritten from original to not be an i2c driver.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 and
11 * only version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */
18
19#define pr_fmt(fmt) "%s: " fmt, __func__
20
21#include <linux/delay.h>
22#include <linux/err.h>
23#include <linux/io.h>
24#include <linux/kernel.h>
25#include <linux/platform_device.h>
26#include <linux/slab.h>
27#include <linux/ssbi.h>
28#include <linux/module.h>
29#include <linux/of.h>
30#include <linux/of_device.h>
31
32/* SSBI 2.0 controller registers */
33#define SSBI2_CMD 0x0008
34#define SSBI2_RD 0x0010
35#define SSBI2_STATUS 0x0014
36#define SSBI2_MODE2 0x001C
37
38/* SSBI_CMD fields */
39#define SSBI_CMD_RDWRN (1 << 24)
40
41/* SSBI_STATUS fields */
42#define SSBI_STATUS_RD_READY (1 << 2)
43#define SSBI_STATUS_READY (1 << 1)
44#define SSBI_STATUS_MCHN_BUSY (1 << 0)
45
46/* SSBI_MODE2 fields */
47#define SSBI_MODE2_REG_ADDR_15_8_SHFT 0x04
48#define SSBI_MODE2_REG_ADDR_15_8_MASK (0x7f << SSBI_MODE2_REG_ADDR_15_8_SHFT)
49
50#define SET_SSBI_MODE2_REG_ADDR_15_8(MD, AD) \
51 (((MD) & 0x0F) | ((((AD) >> 8) << SSBI_MODE2_REG_ADDR_15_8_SHFT) & \
52 SSBI_MODE2_REG_ADDR_15_8_MASK))
53
54/* SSBI PMIC Arbiter command registers */
55#define SSBI_PA_CMD 0x0000
56#define SSBI_PA_RD_STATUS 0x0004
57
58/* SSBI_PA_CMD fields */
59#define SSBI_PA_CMD_RDWRN (1 << 24)
60#define SSBI_PA_CMD_ADDR_MASK 0x7fff /* REG_ADDR_7_0, REG_ADDR_8_14*/
61
62/* SSBI_PA_RD_STATUS fields */
63#define SSBI_PA_RD_STATUS_TRANS_DONE (1 << 27)
64#define SSBI_PA_RD_STATUS_TRANS_DENIED (1 << 26)
65
66#define SSBI_TIMEOUT_US 100
67
68struct ssbi {
69 struct device *slave;
70 void __iomem *base;
71 spinlock_t lock;
72 enum ssbi_controller_type controller_type;
73 int (*read)(struct ssbi *, u16 addr, u8 *buf, int len);
74 int (*write)(struct ssbi *, u16 addr, u8 *buf, int len);
75};
76
77#define to_ssbi(dev) platform_get_drvdata(to_platform_device(dev))
78
79static inline u32 ssbi_readl(struct ssbi *ssbi, u32 reg)
80{
81 return readl(ssbi->base + reg);
82}
83
84static inline void ssbi_writel(struct ssbi *ssbi, u32 val, u32 reg)
85{
86 writel(val, ssbi->base + reg);
87}
88
89/*
90 * Via private exchange with one of the original authors, the hardware
91 * should generally finish a transaction in about 5us. The worst
92 * case, is when using the arbiter and both other CPUs have just
93 * started trying to use the SSBI bus will result in a time of about
94 * 20us. It should never take longer than this.
95 *
96 * As such, this wait merely spins, with a udelay.
97 */
98static int ssbi_wait_mask(struct ssbi *ssbi, u32 set_mask, u32 clr_mask)
99{
100 u32 timeout = SSBI_TIMEOUT_US;
101 u32 val;
102
103 while (timeout--) {
104 val = ssbi_readl(ssbi, SSBI2_STATUS);
105 if (((val & set_mask) == set_mask) && ((val & clr_mask) == 0))
106 return 0;
107 udelay(1);
108 }
109
110 return -ETIMEDOUT;
111}
112
113static int
114ssbi_read_bytes(struct ssbi *ssbi, u16 addr, u8 *buf, int len)
115{
116 u32 cmd = SSBI_CMD_RDWRN | ((addr & 0xff) << 16);
117 int ret = 0;
118
119 if (ssbi->controller_type == MSM_SBI_CTRL_SSBI2) {
120 u32 mode2 = ssbi_readl(ssbi, SSBI2_MODE2);
121 mode2 = SET_SSBI_MODE2_REG_ADDR_15_8(mode2, addr);
122 ssbi_writel(ssbi, mode2, SSBI2_MODE2);
123 }
124
125 while (len) {
126 ret = ssbi_wait_mask(ssbi, SSBI_STATUS_READY, 0);
127 if (ret)
128 goto err;
129
130 ssbi_writel(ssbi, cmd, SSBI2_CMD);
131 ret = ssbi_wait_mask(ssbi, SSBI_STATUS_RD_READY, 0);
132 if (ret)
133 goto err;
134 *buf++ = ssbi_readl(ssbi, SSBI2_RD) & 0xff;
135 len--;
136 }
137
138err:
139 return ret;
140}
141
142static int
143ssbi_write_bytes(struct ssbi *ssbi, u16 addr, u8 *buf, int len)
144{
145 int ret = 0;
146
147 if (ssbi->controller_type == MSM_SBI_CTRL_SSBI2) {
148 u32 mode2 = ssbi_readl(ssbi, SSBI2_MODE2);
149 mode2 = SET_SSBI_MODE2_REG_ADDR_15_8(mode2, addr);
150 ssbi_writel(ssbi, mode2, SSBI2_MODE2);
151 }
152
153 while (len) {
154 ret = ssbi_wait_mask(ssbi, SSBI_STATUS_READY, 0);
155 if (ret)
156 goto err;
157
158 ssbi_writel(ssbi, ((addr & 0xff) << 16) | *buf, SSBI2_CMD);
159 ret = ssbi_wait_mask(ssbi, 0, SSBI_STATUS_MCHN_BUSY);
160 if (ret)
161 goto err;
162 buf++;
163 len--;
164 }
165
166err:
167 return ret;
168}
169
170/*
171 * See ssbi_wait_mask for an explanation of the time and the
172 * busywait.
173 */
174static inline int
175ssbi_pa_transfer(struct ssbi *ssbi, u32 cmd, u8 *data)
176{
177 u32 timeout = SSBI_TIMEOUT_US;
178 u32 rd_status = 0;
179
180 ssbi_writel(ssbi, cmd, SSBI_PA_CMD);
181
182 while (timeout--) {
183 rd_status = ssbi_readl(ssbi, SSBI_PA_RD_STATUS);
184
185 if (rd_status & SSBI_PA_RD_STATUS_TRANS_DENIED)
186 return -EPERM;
187
188 if (rd_status & SSBI_PA_RD_STATUS_TRANS_DONE) {
189 if (data)
190 *data = rd_status & 0xff;
191 return 0;
192 }
193 udelay(1);
194 }
195
196 return -ETIMEDOUT;
197}
198
199static int
200ssbi_pa_read_bytes(struct ssbi *ssbi, u16 addr, u8 *buf, int len)
201{
202 u32 cmd;
203 int ret = 0;
204
205 cmd = SSBI_PA_CMD_RDWRN | (addr & SSBI_PA_CMD_ADDR_MASK) << 8;
206
207 while (len) {
208 ret = ssbi_pa_transfer(ssbi, cmd, buf);
209 if (ret)
210 goto err;
211 buf++;
212 len--;
213 }
214
215err:
216 return ret;
217}
218
219static int
220ssbi_pa_write_bytes(struct ssbi *ssbi, u16 addr, u8 *buf, int len)
221{
222 u32 cmd;
223 int ret = 0;
224
225 while (len) {
226 cmd = (addr & SSBI_PA_CMD_ADDR_MASK) << 8 | *buf;
227 ret = ssbi_pa_transfer(ssbi, cmd, NULL);
228 if (ret)
229 goto err;
230 buf++;
231 len--;
232 }
233
234err:
235 return ret;
236}
237
238int ssbi_read(struct device *dev, u16 addr, u8 *buf, int len)
239{
240 struct ssbi *ssbi = to_ssbi(dev);
241 unsigned long flags;
242 int ret;
243
244 spin_lock_irqsave(&ssbi->lock, flags);
245 ret = ssbi->read(ssbi, addr, buf, len);
246 spin_unlock_irqrestore(&ssbi->lock, flags);
247
248 return ret;
249}
250EXPORT_SYMBOL_GPL(ssbi_read);
251
252int ssbi_write(struct device *dev, u16 addr, u8 *buf, int len)
253{
254 struct ssbi *ssbi = to_ssbi(dev);
255 unsigned long flags;
256 int ret;
257
258 spin_lock_irqsave(&ssbi->lock, flags);
259 ret = ssbi->write(ssbi, addr, buf, len);
260 spin_unlock_irqrestore(&ssbi->lock, flags);
261
262 return ret;
263}
264EXPORT_SYMBOL_GPL(ssbi_write);
265
266static int ssbi_probe(struct platform_device *pdev)
267{
268 struct device_node *np = pdev->dev.of_node;
269 struct resource *mem_res;
270 struct ssbi *ssbi;
271 int ret = 0;
272 const char *type;
273
274 ssbi = kzalloc(sizeof(struct ssbi), GFP_KERNEL);
275 if (!ssbi) {
276 pr_err("can not allocate ssbi_data\n");
277 return -ENOMEM;
278 }
279
280 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
281 if (!mem_res) {
282 pr_err("missing mem resource\n");
283 ret = -EINVAL;
284 goto err_get_mem_res;
285 }
286
287 ssbi->base = ioremap(mem_res->start, resource_size(mem_res));
288 if (!ssbi->base) {
289 pr_err("ioremap of 0x%p failed\n", (void *)mem_res->start);
290 ret = -EINVAL;
291 goto err_ioremap;
292 }
293 platform_set_drvdata(pdev, ssbi);
294
295 type = of_get_property(np, "qcom,controller-type", NULL);
296 if (type == NULL) {
297 pr_err("Missing qcom,controller-type property\n");
298 ret = -EINVAL;
299 goto err_ssbi_controller;
300 }
301 dev_info(&pdev->dev, "SSBI controller type: '%s'\n", type);
302 if (strcmp(type, "ssbi") == 0)
303 ssbi->controller_type = MSM_SBI_CTRL_SSBI;
304 else if (strcmp(type, "ssbi2") == 0)
305 ssbi->controller_type = MSM_SBI_CTRL_SSBI2;
306 else if (strcmp(type, "pmic-arbiter") == 0)
307 ssbi->controller_type = MSM_SBI_CTRL_PMIC_ARBITER;
308 else {
309 pr_err("Unknown qcom,controller-type\n");
310 ret = -EINVAL;
311 goto err_ssbi_controller;
312 }
313
314 if (ssbi->controller_type == MSM_SBI_CTRL_PMIC_ARBITER) {
315 ssbi->read = ssbi_pa_read_bytes;
316 ssbi->write = ssbi_pa_write_bytes;
317 } else {
318 ssbi->read = ssbi_read_bytes;
319 ssbi->write = ssbi_write_bytes;
320 }
321
322 spin_lock_init(&ssbi->lock);
323
324 ret = of_platform_populate(np, NULL, NULL, &pdev->dev);
325 if (ret)
326 goto err_ssbi_controller;
327
328 return 0;
329
330err_ssbi_controller:
331 platform_set_drvdata(pdev, NULL);
332 iounmap(ssbi->base);
333err_ioremap:
334err_get_mem_res:
335 kfree(ssbi);
336 return ret;
337}
338
339static int ssbi_remove(struct platform_device *pdev)
340{
341 struct ssbi *ssbi = platform_get_drvdata(pdev);
342
343 platform_set_drvdata(pdev, NULL);
344 iounmap(ssbi->base);
345 kfree(ssbi);
346 return 0;
347}
348
349static struct of_device_id ssbi_match_table[] = {
350 { .compatible = "qcom,ssbi" },
351 {}
352};
353
354static struct platform_driver ssbi_driver = {
355 .probe = ssbi_probe,
356 .remove = ssbi_remove,
357 .driver = {
358 .name = "ssbi",
359 .owner = THIS_MODULE,
360 .of_match_table = ssbi_match_table,
361 },
362};
363
364static int __init ssbi_init(void)
365{
366 return platform_driver_register(&ssbi_driver);
367}
368module_init(ssbi_init);
369
370static void __exit ssbi_exit(void)
371{
372 platform_driver_unregister(&ssbi_driver);
373}
374module_exit(ssbi_exit)
375
376MODULE_LICENSE("GPL v2");
377MODULE_VERSION("1.0");
378MODULE_ALIAS("platform:ssbi");
379MODULE_AUTHOR("Dima Zavin <dima@android.com>");
diff --git a/drivers/tty/serial/8250/serial_cs.c b/drivers/tty/serial/8250/serial_cs.c
index b7d48b346393..1b74b88e1e1e 100644
--- a/drivers/tty/serial/8250/serial_cs.c
+++ b/drivers/tty/serial/8250/serial_cs.c
@@ -852,18 +852,6 @@ static struct pcmcia_driver serial_cs_driver = {
852 .suspend = serial_suspend, 852 .suspend = serial_suspend,
853 .resume = serial_resume, 853 .resume = serial_resume,
854}; 854};
855 855module_pcmcia_driver(serial_cs_driver);
856static int __init init_serial_cs(void)
857{
858 return pcmcia_register_driver(&serial_cs_driver);
859}
860
861static void __exit exit_serial_cs(void)
862{
863 pcmcia_unregister_driver(&serial_cs_driver);
864}
865
866module_init(init_serial_cs);
867module_exit(exit_serial_cs);
868 856
869MODULE_LICENSE("GPL"); 857MODULE_LICENSE("GPL");
diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index c8b926291e28..b645c47501b4 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -374,6 +374,7 @@ static int uio_get_minor(struct uio_device *idev)
374 retval = idr_alloc(&uio_idr, idev, 0, UIO_MAX_DEVICES, GFP_KERNEL); 374 retval = idr_alloc(&uio_idr, idev, 0, UIO_MAX_DEVICES, GFP_KERNEL);
375 if (retval >= 0) { 375 if (retval >= 0) {
376 idev->minor = retval; 376 idev->minor = retval;
377 retval = 0;
377 } else if (retval == -ENOSPC) { 378 } else if (retval == -ENOSPC) {
378 dev_err(idev->dev, "too many uio devices\n"); 379 dev_err(idev->dev, "too many uio devices\n");
379 retval = -EINVAL; 380 retval = -EINVAL;
diff --git a/drivers/usb/host/sl811_cs.c b/drivers/usb/host/sl811_cs.c
index 3b6f50eaec91..469564e57a52 100644
--- a/drivers/usb/host/sl811_cs.c
+++ b/drivers/usb/host/sl811_cs.c
@@ -200,17 +200,4 @@ static struct pcmcia_driver sl811_cs_driver = {
200 .remove = sl811_cs_detach, 200 .remove = sl811_cs_detach,
201 .id_table = sl811_ids, 201 .id_table = sl811_ids,
202}; 202};
203 203module_pcmcia_driver(sl811_cs_driver);
204/*====================================================================*/
205
206static int __init init_sl811_cs(void)
207{
208 return pcmcia_register_driver(&sl811_cs_driver);
209}
210module_init(init_sl811_cs);
211
212static void __exit exit_sl811_cs(void)
213{
214 pcmcia_unregister_driver(&sl811_cs_driver);
215}
216module_exit(exit_sl811_cs);
diff --git a/drivers/w1/masters/mxc_w1.c b/drivers/w1/masters/mxc_w1.c
index 950d354d50e2..47e12cfc2a57 100644
--- a/drivers/w1/masters/mxc_w1.c
+++ b/drivers/w1/masters/mxc_w1.c
@@ -121,9 +121,9 @@ static int mxc_w1_probe(struct platform_device *pdev)
121 mdev->clkdiv = (clk_get_rate(mdev->clk) / 1000000) - 1; 121 mdev->clkdiv = (clk_get_rate(mdev->clk) / 1000000) - 1;
122 122
123 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 123 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
124 mdev->regs = devm_request_and_ioremap(&pdev->dev, res); 124 mdev->regs = devm_ioremap_resource(&pdev->dev, res);
125 if (!mdev->regs) 125 if (IS_ERR(mdev->regs))
126 return -EBUSY; 126 return PTR_ERR(mdev->regs);
127 127
128 clk_prepare_enable(mdev->clk); 128 clk_prepare_enable(mdev->clk);
129 __raw_writeb(mdev->clkdiv, mdev->regs + MXC_W1_TIME_DIVIDER); 129 __raw_writeb(mdev->clkdiv, mdev->regs + MXC_W1_TIME_DIVIDER);
diff --git a/drivers/w1/slaves/Kconfig b/drivers/w1/slaves/Kconfig
index 762561fbabbf..5e6a3c9e510b 100644
--- a/drivers/w1/slaves/Kconfig
+++ b/drivers/w1/slaves/Kconfig
@@ -22,6 +22,16 @@ config W1_SLAVE_DS2408
22 Say Y here if you want to use a 1-wire 22 Say Y here if you want to use a 1-wire
23 DS2408 8-Channel Addressable Switch device support 23 DS2408 8-Channel Addressable Switch device support
24 24
25config W1_SLAVE_DS2408_READBACK
26 bool "Read-back values written to DS2408's output register"
27 depends on W1_SLAVE_DS2408
28 default y
29 help
30 Enabling this will cause the driver to read back the values written
31 to the chip's output register in order to detect errors.
32
33 This is slower but useful when debugging chips and/or busses.
34
25config W1_SLAVE_DS2413 35config W1_SLAVE_DS2413
26 tristate "Dual Channel Addressable Switch 0x3a family support (DS2413)" 36 tristate "Dual Channel Addressable Switch 0x3a family support (DS2413)"
27 help 37 help
diff --git a/drivers/w1/slaves/w1_ds2408.c b/drivers/w1/slaves/w1_ds2408.c
index 441ad3a3b586..e45eca1044bd 100644
--- a/drivers/w1/slaves/w1_ds2408.c
+++ b/drivers/w1/slaves/w1_ds2408.c
@@ -178,6 +178,15 @@ static ssize_t w1_f29_write_output(
178 w1_write_block(sl->master, w1_buf, 3); 178 w1_write_block(sl->master, w1_buf, 3);
179 179
180 readBack = w1_read_8(sl->master); 180 readBack = w1_read_8(sl->master);
181
182 if (readBack != W1_F29_SUCCESS_CONFIRM_BYTE) {
183 if (w1_reset_resume_command(sl->master))
184 goto error;
185 /* try again, the slave is ready for a command */
186 continue;
187 }
188
189#ifdef CONFIG_W1_SLAVE_DS2408_READBACK
181 /* here the master could read another byte which 190 /* here the master could read another byte which
182 would be the PIO reg (the actual pin logic state) 191 would be the PIO reg (the actual pin logic state)
183 since in this driver we don't know which pins are 192 since in this driver we don't know which pins are
@@ -186,11 +195,6 @@ static ssize_t w1_f29_write_output(
186 if (w1_reset_resume_command(sl->master)) 195 if (w1_reset_resume_command(sl->master))
187 goto error; 196 goto error;
188 197
189 if (readBack != 0xAA) {
190 /* try again, the slave is ready for a command */
191 continue;
192 }
193
194 /* go read back the output latches */ 198 /* go read back the output latches */
195 /* (the direct effect of the write above) */ 199 /* (the direct effect of the write above) */
196 w1_buf[0] = W1_F29_FUNC_READ_PIO_REGS; 200 w1_buf[0] = W1_F29_FUNC_READ_PIO_REGS;
@@ -198,7 +202,9 @@ static ssize_t w1_f29_write_output(
198 w1_buf[2] = 0; 202 w1_buf[2] = 0;
199 w1_write_block(sl->master, w1_buf, 3); 203 w1_write_block(sl->master, w1_buf, 3);
200 /* read the result of the READ_PIO_REGS command */ 204 /* read the result of the READ_PIO_REGS command */
201 if (w1_read_8(sl->master) == *buf) { 205 if (w1_read_8(sl->master) == *buf)
206#endif
207 {
202 /* success! */ 208 /* success! */
203 mutex_unlock(&sl->master->bus_mutex); 209 mutex_unlock(&sl->master->bus_mutex);
204 dev_dbg(&sl->dev, 210 dev_dbg(&sl->dev,
@@ -297,8 +303,7 @@ error:
297 303
298 304
299 305
300#define NB_SYSFS_BIN_FILES 6 306static struct bin_attribute w1_f29_sysfs_bin_files[] = {
301static struct bin_attribute w1_f29_sysfs_bin_files[NB_SYSFS_BIN_FILES] = {
302 { 307 {
303 .attr = { 308 .attr = {
304 .name = "state", 309 .name = "state",
@@ -357,7 +362,7 @@ static int w1_f29_add_slave(struct w1_slave *sl)
357 int err = 0; 362 int err = 0;
358 int i; 363 int i;
359 364
360 for (i = 0; i < NB_SYSFS_BIN_FILES && !err; ++i) 365 for (i = 0; i < ARRAY_SIZE(w1_f29_sysfs_bin_files) && !err; ++i)
361 err = sysfs_create_bin_file( 366 err = sysfs_create_bin_file(
362 &sl->dev.kobj, 367 &sl->dev.kobj,
363 &(w1_f29_sysfs_bin_files[i])); 368 &(w1_f29_sysfs_bin_files[i]));
@@ -371,7 +376,7 @@ static int w1_f29_add_slave(struct w1_slave *sl)
371static void w1_f29_remove_slave(struct w1_slave *sl) 376static void w1_f29_remove_slave(struct w1_slave *sl)
372{ 377{
373 int i; 378 int i;
374 for (i = NB_SYSFS_BIN_FILES - 1; i >= 0; --i) 379 for (i = ARRAY_SIZE(w1_f29_sysfs_bin_files) - 1; i >= 0; --i)
375 sysfs_remove_bin_file(&sl->dev.kobj, 380 sysfs_remove_bin_file(&sl->dev.kobj,
376 &(w1_f29_sysfs_bin_files[i])); 381 &(w1_f29_sysfs_bin_files[i]));
377} 382}
diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index df77ba9a8166..95d0850584da 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -27,6 +27,63 @@
27 27
28#include <linux/types.h> 28#include <linux/types.h>
29 29
30
31/*
32 * Implementation of host controlled snapshot of the guest.
33 */
34
35#define VSS_OP_REGISTER 128
36
37enum hv_vss_op {
38 VSS_OP_CREATE = 0,
39 VSS_OP_DELETE,
40 VSS_OP_HOT_BACKUP,
41 VSS_OP_GET_DM_INFO,
42 VSS_OP_BU_COMPLETE,
43 /*
44 * Following operations are only supported with IC version >= 5.0
45 */
46 VSS_OP_FREEZE, /* Freeze the file systems in the VM */
47 VSS_OP_THAW, /* Unfreeze the file systems */
48 VSS_OP_AUTO_RECOVER,
49 VSS_OP_COUNT /* Number of operations, must be last */
50};
51
52
53/*
54 * Header for all VSS messages.
55 */
56struct hv_vss_hdr {
57 __u8 operation;
58 __u8 reserved[7];
59} __attribute__((packed));
60
61
62/*
63 * Flag values for the hv_vss_check_feature. Linux supports only
64 * one value.
65 */
66#define VSS_HBU_NO_AUTO_RECOVERY 0x00000005
67
68struct hv_vss_check_feature {
69 __u32 flags;
70} __attribute__((packed));
71
72struct hv_vss_check_dm_info {
73 __u32 flags;
74} __attribute__((packed));
75
76struct hv_vss_msg {
77 union {
78 struct hv_vss_hdr vss_hdr;
79 int error;
80 };
81 union {
82 struct hv_vss_check_feature vss_cf;
83 struct hv_vss_check_dm_info dm_info;
84 };
85} __attribute__((packed));
86
30/* 87/*
31 * An implementation of HyperV key value pair (KVP) functionality for Linux. 88 * An implementation of HyperV key value pair (KVP) functionality for Linux.
32 * 89 *
@@ -1253,6 +1310,14 @@ void vmbus_driver_unregister(struct hv_driver *hv_driver);
1253 } 1310 }
1254 1311
1255/* 1312/*
1313 * VSS (Backup/Restore) GUID
1314 */
1315#define HV_VSS_GUID \
1316 .guid = { \
1317 0x29, 0x2e, 0xfa, 0x35, 0x23, 0xea, 0x36, 0x42, \
1318 0x96, 0xae, 0x3a, 0x6e, 0xba, 0xcb, 0xa4, 0x40 \
1319 }
1320/*
1256 * Common header for Hyper-V ICs 1321 * Common header for Hyper-V ICs
1257 */ 1322 */
1258 1323
@@ -1356,6 +1421,10 @@ int hv_kvp_init(struct hv_util_service *);
1356void hv_kvp_deinit(void); 1421void hv_kvp_deinit(void);
1357void hv_kvp_onchannelcallback(void *); 1422void hv_kvp_onchannelcallback(void *);
1358 1423
1424int hv_vss_init(struct hv_util_service *);
1425void hv_vss_deinit(void);
1426void hv_vss_onchannelcallback(void *);
1427
1359/* 1428/*
1360 * Negotiated version with the Host. 1429 * Negotiated version with the Host.
1361 */ 1430 */
diff --git a/include/linux/ipack.h b/include/linux/ipack.h
index fea12cbb2aeb..1888e06ddf64 100644
--- a/include/linux/ipack.h
+++ b/include/linux/ipack.h
@@ -207,19 +207,41 @@ int ipack_driver_register(struct ipack_driver *edrv, struct module *owner,
207void ipack_driver_unregister(struct ipack_driver *edrv); 207void ipack_driver_unregister(struct ipack_driver *edrv);
208 208
209/** 209/**
210 * ipack_device_register -- register an IPack device with the kernel 210 * ipack_device_init -- initialize an IPack device
211 * @dev: the new device to register. 211 * @dev: the new device to initialize.
212 * 212 *
213 * Register a new IPack device ("module" in IndustryPack jargon). The call 213 * Initialize a new IPack device ("module" in IndustryPack jargon). The call
214 * is done by the carrier driver. The carrier should populate the fields 214 * is done by the carrier driver. The carrier should populate the fields
215 * bus and slot as well as the region array of @dev prior to calling this 215 * bus and slot as well as the region array of @dev prior to calling this
216 * function. The rest of the fields will be allocated and populated 216 * function. The rest of the fields will be allocated and populated
217 * during registration. 217 * during initalization.
218 * 218 *
219 * Return zero on success or error code on failure. 219 * Return zero on success or error code on failure.
220 *
221 * NOTE: _Never_ directly free @dev after calling this function, even
222 * if it returned an error! Always use ipack_put_device() to give up the
223 * reference initialized in this function instead.
224 */
225int ipack_device_init(struct ipack_device *dev);
226
227/**
228 * ipack_device_add -- Add an IPack device
229 * @dev: the new device to add.
230 *
231 * Add a new IPack device. The call is done by the carrier driver
232 * after calling ipack_device_init().
233 *
234 * Return zero on success or error code on failure.
235 *
236 * NOTE: _Never_ directly free @dev after calling this function, even
237 * if it returned an error! Always use ipack_put_device() to give up the
238 * reference initialized in this function instead.
220 */ 239 */
221int ipack_device_register(struct ipack_device *dev); 240int ipack_device_add(struct ipack_device *dev);
222void ipack_device_unregister(struct ipack_device *dev); 241void ipack_device_del(struct ipack_device *dev);
242
243void ipack_get_device(struct ipack_device *dev);
244void ipack_put_device(struct ipack_device *dev);
223 245
224/** 246/**
225 * DEFINE_IPACK_DEVICE_TABLE - macro used to describe a IndustryPack table 247 * DEFINE_IPACK_DEVICE_TABLE - macro used to describe a IndustryPack table
diff --git a/include/linux/mei_cl_bus.h b/include/linux/mei_cl_bus.h
new file mode 100644
index 000000000000..d14af7b722ef
--- /dev/null
+++ b/include/linux/mei_cl_bus.h
@@ -0,0 +1,44 @@
1#ifndef _LINUX_MEI_CL_BUS_H
2#define _LINUX_MEI_CL_BUS_H
3
4#include <linux/device.h>
5#include <linux/uuid.h>
6
7struct mei_cl_device;
8
9struct mei_cl_driver {
10 struct device_driver driver;
11 const char *name;
12
13 const struct mei_cl_device_id *id_table;
14
15 int (*probe)(struct mei_cl_device *dev,
16 const struct mei_cl_device_id *id);
17 int (*remove)(struct mei_cl_device *dev);
18};
19
20int __mei_cl_driver_register(struct mei_cl_driver *driver,
21 struct module *owner);
22#define mei_cl_driver_register(driver) \
23 __mei_cl_driver_register(driver, THIS_MODULE)
24
25void mei_cl_driver_unregister(struct mei_cl_driver *driver);
26
27int mei_cl_send(struct mei_cl_device *device, u8 *buf, size_t length);
28int mei_cl_recv(struct mei_cl_device *device, u8 *buf, size_t length);
29
30typedef void (*mei_cl_event_cb_t)(struct mei_cl_device *device,
31 u32 events, void *context);
32int mei_cl_register_event_cb(struct mei_cl_device *device,
33 mei_cl_event_cb_t read_cb, void *context);
34
35#define MEI_CL_EVENT_RX 0
36#define MEI_CL_EVENT_TX 1
37
38void *mei_cl_get_drvdata(const struct mei_cl_device *device);
39void mei_cl_set_drvdata(struct mei_cl_device *device, void *data);
40
41int mei_cl_enable_device(struct mei_cl_device *device);
42int mei_cl_disable_device(struct mei_cl_device *device);
43
44#endif /* _LINUX_MEI_CL_BUS_H */
diff --git a/include/linux/mfd/arizona/core.h b/include/linux/mfd/arizona/core.h
index a710255528d7..cc281368dc55 100644
--- a/include/linux/mfd/arizona/core.h
+++ b/include/linux/mfd/arizona/core.h
@@ -100,6 +100,9 @@ struct arizona {
100 struct regmap_irq_chip_data *aod_irq_chip; 100 struct regmap_irq_chip_data *aod_irq_chip;
101 struct regmap_irq_chip_data *irq_chip; 101 struct regmap_irq_chip_data *irq_chip;
102 102
103 bool hpdet_magic;
104 unsigned int hp_ena;
105
103 struct mutex clk_lock; 106 struct mutex clk_lock;
104 int clk32k_ref; 107 int clk32k_ref;
105 108
diff --git a/include/linux/mfd/arizona/pdata.h b/include/linux/mfd/arizona/pdata.h
index 455c51d22d6b..a0f940987a3e 100644
--- a/include/linux/mfd/arizona/pdata.h
+++ b/include/linux/mfd/arizona/pdata.h
@@ -86,6 +86,11 @@ struct arizona_micd_config {
86 bool gpio; 86 bool gpio;
87}; 87};
88 88
89struct arizona_micd_range {
90 int max; /** Ohms */
91 int key; /** Key to report to input layer */
92};
93
89struct arizona_pdata { 94struct arizona_pdata {
90 int reset; /** GPIO controlling /RESET, if any */ 95 int reset; /** GPIO controlling /RESET, if any */
91 int ldoena; /** GPIO controlling LODENA, if any */ 96 int ldoena; /** GPIO controlling LODENA, if any */
@@ -117,12 +122,21 @@ struct arizona_pdata {
117 /** GPIO5 is used for jack detection */ 122 /** GPIO5 is used for jack detection */
118 bool jd_gpio5; 123 bool jd_gpio5;
119 124
125 /** Internal pull on GPIO5 is disabled when used for jack detection */
126 bool jd_gpio5_nopull;
127
120 /** Use the headphone detect circuit to identify the accessory */ 128 /** Use the headphone detect circuit to identify the accessory */
121 bool hpdet_acc_id; 129 bool hpdet_acc_id;
122 130
131 /** Check for line output with HPDET method */
132 bool hpdet_acc_id_line;
133
123 /** GPIO used for mic isolation with HPDET */ 134 /** GPIO used for mic isolation with HPDET */
124 int hpdet_id_gpio; 135 int hpdet_id_gpio;
125 136
137 /** Extra debounce timeout used during initial mic detection (ms) */
138 int micd_detect_debounce;
139
126 /** GPIO for mic detection polarity */ 140 /** GPIO for mic detection polarity */
127 int micd_pol_gpio; 141 int micd_pol_gpio;
128 142
@@ -135,9 +149,16 @@ struct arizona_pdata {
135 /** Mic detect debounce level */ 149 /** Mic detect debounce level */
136 int micd_dbtime; 150 int micd_dbtime;
137 151
152 /** Mic detect timeout (ms) */
153 int micd_timeout;
154
138 /** Force MICBIAS on for mic detect */ 155 /** Force MICBIAS on for mic detect */
139 bool micd_force_micbias; 156 bool micd_force_micbias;
140 157
158 /** Mic detect level parameters */
159 const struct arizona_micd_range *micd_ranges;
160 int num_micd_ranges;
161
141 /** Headset polarity configurations */ 162 /** Headset polarity configurations */
142 struct arizona_micd_config *micd_configs; 163 struct arizona_micd_config *micd_configs;
143 int num_micd_configs; 164 int num_micd_configs;
diff --git a/include/linux/mfd/arizona/registers.h b/include/linux/mfd/arizona/registers.h
index 340355136069..f43aa7c8d040 100644
--- a/include/linux/mfd/arizona/registers.h
+++ b/include/linux/mfd/arizona/registers.h
@@ -124,6 +124,10 @@
124#define ARIZONA_MIC_DETECT_1 0x2A3 124#define ARIZONA_MIC_DETECT_1 0x2A3
125#define ARIZONA_MIC_DETECT_2 0x2A4 125#define ARIZONA_MIC_DETECT_2 0x2A4
126#define ARIZONA_MIC_DETECT_3 0x2A5 126#define ARIZONA_MIC_DETECT_3 0x2A5
127#define ARIZONA_MIC_DETECT_LEVEL_1 0x2A6
128#define ARIZONA_MIC_DETECT_LEVEL_2 0x2A7
129#define ARIZONA_MIC_DETECT_LEVEL_3 0x2A8
130#define ARIZONA_MIC_DETECT_LEVEL_4 0x2A9
127#define ARIZONA_MIC_NOISE_MIX_CONTROL_1 0x2C3 131#define ARIZONA_MIC_NOISE_MIX_CONTROL_1 0x2C3
128#define ARIZONA_ISOLATION_CONTROL 0x2CB 132#define ARIZONA_ISOLATION_CONTROL 0x2CB
129#define ARIZONA_JACK_DETECT_ANALOGUE 0x2D3 133#define ARIZONA_JACK_DETECT_ANALOGUE 0x2D3
diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
index 779cf7c4a3d1..b508016fb76d 100644
--- a/include/linux/mod_devicetable.h
+++ b/include/linux/mod_devicetable.h
@@ -9,6 +9,7 @@
9 9
10#ifdef __KERNEL__ 10#ifdef __KERNEL__
11#include <linux/types.h> 11#include <linux/types.h>
12#include <linux/uuid.h>
12typedef unsigned long kernel_ulong_t; 13typedef unsigned long kernel_ulong_t;
13#endif 14#endif
14 15
@@ -568,4 +569,12 @@ struct ipack_device_id {
568 __u32 device; /* Device ID or IPACK_ANY_ID */ 569 __u32 device; /* Device ID or IPACK_ANY_ID */
569}; 570};
570 571
572#define MEI_CL_MODULE_PREFIX "mei:"
573#define MEI_CL_NAME_SIZE 32
574
575struct mei_cl_device_id {
576 char name[MEI_CL_NAME_SIZE];
577 kernel_ulong_t driver_info;
578};
579
571#endif /* LINUX_MOD_DEVICETABLE_H */ 580#endif /* LINUX_MOD_DEVICETABLE_H */
diff --git a/include/linux/platform_data/emif_plat.h b/include/linux/platform_data/emif_plat.h
index 03378ca84061..5c19a2a647c4 100644
--- a/include/linux/platform_data/emif_plat.h
+++ b/include/linux/platform_data/emif_plat.h
@@ -40,6 +40,7 @@
40/* Custom config requests */ 40/* Custom config requests */
41#define EMIF_CUSTOM_CONFIG_LPMODE 0x00000001 41#define EMIF_CUSTOM_CONFIG_LPMODE 0x00000001
42#define EMIF_CUSTOM_CONFIG_TEMP_ALERT_POLL_INTERVAL 0x00000002 42#define EMIF_CUSTOM_CONFIG_TEMP_ALERT_POLL_INTERVAL 0x00000002
43#define EMIF_CUSTOM_CONFIG_EXTENDED_TEMP_PART 0x00000004
43 44
44#ifndef __ASSEMBLY__ 45#ifndef __ASSEMBLY__
45/** 46/**
diff --git a/include/linux/ssbi.h b/include/linux/ssbi.h
new file mode 100644
index 000000000000..44ef5da21470
--- /dev/null
+++ b/include/linux/ssbi.h
@@ -0,0 +1,38 @@
1/* Copyright (C) 2010 Google, Inc.
2 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
3 * Author: Dima Zavin <dima@android.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 and
7 * only version 2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#ifndef _LINUX_SSBI_H
16#define _LINUX_SSBI_H
17
18#include <linux/types.h>
19
20struct ssbi_slave_info {
21 const char *name;
22 void *platform_data;
23};
24
25enum ssbi_controller_type {
26 MSM_SBI_CTRL_SSBI = 0,
27 MSM_SBI_CTRL_SSBI2,
28 MSM_SBI_CTRL_PMIC_ARBITER,
29};
30
31struct ssbi_platform_data {
32 struct ssbi_slave_info slave;
33 enum ssbi_controller_type controller_type;
34};
35
36int ssbi_write(struct device *dev, u16 addr, u8 *buf, int len);
37int ssbi_read(struct device *dev, u16 addr, u8 *buf, int len);
38#endif
diff --git a/include/pcmcia/ds.h b/include/pcmcia/ds.h
index 3bbbd78e1439..2d56e428506c 100644
--- a/include/pcmcia/ds.h
+++ b/include/pcmcia/ds.h
@@ -65,6 +65,18 @@ struct pcmcia_driver {
65int pcmcia_register_driver(struct pcmcia_driver *driver); 65int pcmcia_register_driver(struct pcmcia_driver *driver);
66void pcmcia_unregister_driver(struct pcmcia_driver *driver); 66void pcmcia_unregister_driver(struct pcmcia_driver *driver);
67 67
68/**
69 * module_pcmcia_driver() - Helper macro for registering a pcmcia driver
70 * @__pcmcia_driver: pcmcia_driver struct
71 *
72 * Helper macro for pcmcia drivers which do not do anything special in module
73 * init/exit. This eliminates a lot of boilerplate. Each module may only use
74 * this macro once, and calling it replaces module_init() and module_exit().
75 */
76#define module_pcmcia_driver(__pcmcia_driver) \
77 module_driver(__pcmcia_driver, pcmcia_register_driver, \
78 pcmcia_unregister_driver)
79
68/* for struct resource * array embedded in struct pcmcia_device */ 80/* for struct resource * array embedded in struct pcmcia_device */
69enum { 81enum {
70 PCMCIA_IOPORT_0, 82 PCMCIA_IOPORT_0,
diff --git a/include/uapi/linux/connector.h b/include/uapi/linux/connector.h
index 8761a0349c74..4cb283505e45 100644
--- a/include/uapi/linux/connector.h
+++ b/include/uapi/linux/connector.h
@@ -44,8 +44,11 @@
44#define CN_VAL_DRBD 0x1 44#define CN_VAL_DRBD 0x1
45#define CN_KVP_IDX 0x9 /* HyperV KVP */ 45#define CN_KVP_IDX 0x9 /* HyperV KVP */
46#define CN_KVP_VAL 0x1 /* queries from the kernel */ 46#define CN_KVP_VAL 0x1 /* queries from the kernel */
47#define CN_VSS_IDX 0xA /* HyperV VSS */
48#define CN_VSS_VAL 0x1 /* queries from the kernel */
47 49
48#define CN_NETLINK_USERS 10 /* Highest index + 1 */ 50
51#define CN_NETLINK_USERS 11 /* Highest index + 1 */
49 52
50/* 53/*
51 * Maximum connector's message size. 54 * Maximum connector's message size.
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 8fcced7823fa..7ff1536f01b8 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1397,6 +1397,7 @@ void split_page(struct page *page, unsigned int order)
1397 for (i = 1; i < (1 << order); i++) 1397 for (i = 1; i < (1 << order); i++)
1398 set_page_refcounted(page + i); 1398 set_page_refcounted(page + i);
1399} 1399}
1400EXPORT_SYMBOL_GPL(split_page);
1400 1401
1401static int __isolate_free_page(struct page *page, unsigned int order) 1402static int __isolate_free_page(struct page *page, unsigned int order)
1402{ 1403{
diff --git a/scripts/mod/devicetable-offsets.c b/scripts/mod/devicetable-offsets.c
index b45260bfeaa0..e66d4d258e1a 100644
--- a/scripts/mod/devicetable-offsets.c
+++ b/scripts/mod/devicetable-offsets.c
@@ -174,5 +174,8 @@ int main(void)
174 DEVID_FIELD(x86_cpu_id, model); 174 DEVID_FIELD(x86_cpu_id, model);
175 DEVID_FIELD(x86_cpu_id, vendor); 175 DEVID_FIELD(x86_cpu_id, vendor);
176 176
177 DEVID(mei_cl_device_id);
178 DEVID_FIELD(mei_cl_device_id, name);
179
177 return 0; 180 return 0;
178} 181}
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index 771ac17f635d..45f9a3377dcd 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -1133,6 +1133,18 @@ static int do_x86cpu_entry(const char *filename, void *symval,
1133} 1133}
1134ADD_TO_DEVTABLE("x86cpu", x86_cpu_id, do_x86cpu_entry); 1134ADD_TO_DEVTABLE("x86cpu", x86_cpu_id, do_x86cpu_entry);
1135 1135
1136/* Looks like: mei:S */
1137static int do_mei_entry(const char *filename, void *symval,
1138 char *alias)
1139{
1140 DEF_FIELD_ADDR(symval, mei_cl_device_id, name);
1141
1142 sprintf(alias, MEI_CL_MODULE_PREFIX "%s", *name);
1143
1144 return 1;
1145}
1146ADD_TO_DEVTABLE("mei", mei_cl_device_id, do_mei_entry);
1147
1136/* Does namelen bytes of name exactly match the symbol? */ 1148/* Does namelen bytes of name exactly match the symbol? */
1137static bool sym_is(const char *name, unsigned namelen, const char *symbol) 1149static bool sym_is(const char *name, unsigned namelen, const char *symbol)
1138{ 1150{
diff --git a/sound/pcmcia/pdaudiocf/pdaudiocf.c b/sound/pcmcia/pdaudiocf/pdaudiocf.c
index f9b5229b2723..8f489de5c4c6 100644
--- a/sound/pcmcia/pdaudiocf/pdaudiocf.c
+++ b/sound/pcmcia/pdaudiocf/pdaudiocf.c
@@ -295,18 +295,5 @@ static struct pcmcia_driver pdacf_cs_driver = {
295 .suspend = pdacf_suspend, 295 .suspend = pdacf_suspend,
296 .resume = pdacf_resume, 296 .resume = pdacf_resume,
297#endif 297#endif
298
299}; 298};
300 299module_pcmcia_driver(pdacf_cs_driver);
301static int __init init_pdacf(void)
302{
303 return pcmcia_register_driver(&pdacf_cs_driver);
304}
305
306static void __exit exit_pdacf(void)
307{
308 pcmcia_unregister_driver(&pdacf_cs_driver);
309}
310
311module_init(init_pdacf);
312module_exit(exit_pdacf);
diff --git a/sound/pcmcia/vx/vxpocket.c b/sound/pcmcia/vx/vxpocket.c
index 8f9350475c7b..d4db7ecaa6bf 100644
--- a/sound/pcmcia/vx/vxpocket.c
+++ b/sound/pcmcia/vx/vxpocket.c
@@ -367,16 +367,4 @@ static struct pcmcia_driver vxp_cs_driver = {
367 .resume = vxp_resume, 367 .resume = vxp_resume,
368#endif 368#endif
369}; 369};
370 370module_pcmcia_driver(vxp_cs_driver);
371static int __init init_vxpocket(void)
372{
373 return pcmcia_register_driver(&vxp_cs_driver);
374}
375
376static void __exit exit_vxpocket(void)
377{
378 pcmcia_unregister_driver(&vxp_cs_driver);
379}
380
381module_init(init_vxpocket);
382module_exit(exit_vxpocket);
diff --git a/sound/soc/codecs/arizona.c b/sound/soc/codecs/arizona.c
index ac948a671ea6..e7d34711412c 100644
--- a/sound/soc/codecs/arizona.c
+++ b/sound/soc/codecs/arizona.c
@@ -364,6 +364,39 @@ int arizona_out_ev(struct snd_soc_dapm_widget *w,
364} 364}
365EXPORT_SYMBOL_GPL(arizona_out_ev); 365EXPORT_SYMBOL_GPL(arizona_out_ev);
366 366
367int arizona_hp_ev(struct snd_soc_dapm_widget *w,
368 struct snd_kcontrol *kcontrol,
369 int event)
370{
371 struct arizona_priv *priv = snd_soc_codec_get_drvdata(w->codec);
372 unsigned int mask = 1 << w->shift;
373 unsigned int val;
374
375 switch (event) {
376 case SND_SOC_DAPM_POST_PMU:
377 val = mask;
378 break;
379 case SND_SOC_DAPM_PRE_PMD:
380 val = 0;
381 break;
382 default:
383 return -EINVAL;
384 }
385
386 /* Store the desired state for the HP outputs */
387 priv->arizona->hp_ena &= ~mask;
388 priv->arizona->hp_ena |= val;
389
390 /* Force off if HPDET magic is active */
391 if (priv->arizona->hpdet_magic)
392 val = 0;
393
394 snd_soc_update_bits(w->codec, ARIZONA_OUTPUT_ENABLES_1, mask, val);
395
396 return arizona_out_ev(w, kcontrol, event);
397}
398EXPORT_SYMBOL_GPL(arizona_hp_ev);
399
367static unsigned int arizona_sysclk_48k_rates[] = { 400static unsigned int arizona_sysclk_48k_rates[] = {
368 6144000, 401 6144000,
369 12288000, 402 12288000,
diff --git a/sound/soc/codecs/arizona.h b/sound/soc/codecs/arizona.h
index 116372c91f5d..13dd2916b721 100644
--- a/sound/soc/codecs/arizona.h
+++ b/sound/soc/codecs/arizona.h
@@ -184,6 +184,9 @@ extern int arizona_in_ev(struct snd_soc_dapm_widget *w,
184extern int arizona_out_ev(struct snd_soc_dapm_widget *w, 184extern int arizona_out_ev(struct snd_soc_dapm_widget *w,
185 struct snd_kcontrol *kcontrol, 185 struct snd_kcontrol *kcontrol,
186 int event); 186 int event);
187extern int arizona_hp_ev(struct snd_soc_dapm_widget *w,
188 struct snd_kcontrol *kcontrol,
189 int event);
187 190
188extern int arizona_set_sysclk(struct snd_soc_codec *codec, int clk_id, 191extern int arizona_set_sysclk(struct snd_soc_codec *codec, int clk_id,
189 int source, unsigned int freq, int dir); 192 int source, unsigned int freq, int dir);
diff --git a/sound/soc/codecs/wm5102.c b/sound/soc/codecs/wm5102.c
index 34d0201d6a78..15bc31f1abb1 100644
--- a/sound/soc/codecs/wm5102.c
+++ b/sound/soc/codecs/wm5102.c
@@ -1131,11 +1131,11 @@ ARIZONA_DSP_WIDGETS(DSP1, "DSP1"),
1131SND_SOC_DAPM_VALUE_MUX("AEC Loopback", ARIZONA_DAC_AEC_CONTROL_1, 1131SND_SOC_DAPM_VALUE_MUX("AEC Loopback", ARIZONA_DAC_AEC_CONTROL_1,
1132 ARIZONA_AEC_LOOPBACK_ENA, 0, &wm5102_aec_loopback_mux), 1132 ARIZONA_AEC_LOOPBACK_ENA, 0, &wm5102_aec_loopback_mux),
1133 1133
1134SND_SOC_DAPM_PGA_E("OUT1L", ARIZONA_OUTPUT_ENABLES_1, 1134SND_SOC_DAPM_PGA_E("OUT1L", SND_SOC_NOPM,
1135 ARIZONA_OUT1L_ENA_SHIFT, 0, NULL, 0, arizona_out_ev, 1135 ARIZONA_OUT1L_ENA_SHIFT, 0, NULL, 0, arizona_hp_ev,
1136 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 1136 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),
1137SND_SOC_DAPM_PGA_E("OUT1R", ARIZONA_OUTPUT_ENABLES_1, 1137SND_SOC_DAPM_PGA_E("OUT1R", SND_SOC_NOPM,
1138 ARIZONA_OUT1R_ENA_SHIFT, 0, NULL, 0, arizona_out_ev, 1138 ARIZONA_OUT1R_ENA_SHIFT, 0, NULL, 0, arizona_hp_ev,
1139 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 1139 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),
1140SND_SOC_DAPM_PGA_E("OUT2L", ARIZONA_OUTPUT_ENABLES_1, 1140SND_SOC_DAPM_PGA_E("OUT2L", ARIZONA_OUTPUT_ENABLES_1,
1141 ARIZONA_OUT2L_ENA_SHIFT, 0, NULL, 0, arizona_out_ev, 1141 ARIZONA_OUT2L_ENA_SHIFT, 0, NULL, 0, arizona_out_ev,
diff --git a/sound/soc/codecs/wm5110.c b/sound/soc/codecs/wm5110.c
index cdeb301da1f6..7841b42a819c 100644
--- a/sound/soc/codecs/wm5110.c
+++ b/sound/soc/codecs/wm5110.c
@@ -551,11 +551,11 @@ SND_SOC_DAPM_AIF_IN("AIF3RX1", NULL, 0,
551SND_SOC_DAPM_AIF_IN("AIF3RX2", NULL, 0, 551SND_SOC_DAPM_AIF_IN("AIF3RX2", NULL, 0,
552 ARIZONA_AIF3_RX_ENABLES, ARIZONA_AIF3RX2_ENA_SHIFT, 0), 552 ARIZONA_AIF3_RX_ENABLES, ARIZONA_AIF3RX2_ENA_SHIFT, 0),
553 553
554SND_SOC_DAPM_PGA_E("OUT1L", ARIZONA_OUTPUT_ENABLES_1, 554SND_SOC_DAPM_PGA_E("OUT1L", SND_SOC_NOPM,
555 ARIZONA_OUT1L_ENA_SHIFT, 0, NULL, 0, arizona_out_ev, 555 ARIZONA_OUT1L_ENA_SHIFT, 0, NULL, 0, arizona_hp_ev,
556 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 556 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),
557SND_SOC_DAPM_PGA_E("OUT1R", ARIZONA_OUTPUT_ENABLES_1, 557SND_SOC_DAPM_PGA_E("OUT1R", SND_SOC_NOPM,
558 ARIZONA_OUT1R_ENA_SHIFT, 0, NULL, 0, arizona_out_ev, 558 ARIZONA_OUT1R_ENA_SHIFT, 0, NULL, 0, arizona_hp_ev,
559 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 559 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),
560SND_SOC_DAPM_PGA_E("OUT2L", ARIZONA_OUTPUT_ENABLES_1, 560SND_SOC_DAPM_PGA_E("OUT2L", ARIZONA_OUTPUT_ENABLES_1,
561 ARIZONA_OUT2L_ENA_SHIFT, 0, NULL, 0, arizona_out_ev, 561 ARIZONA_OUT2L_ENA_SHIFT, 0, NULL, 0, arizona_out_ev,
diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index c800ea4c8bf9..5a1f6489d185 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -102,6 +102,10 @@ static struct utsname uts_buf;
102#define MAX_FILE_NAME 100 102#define MAX_FILE_NAME 100
103#define ENTRIES_PER_BLOCK 50 103#define ENTRIES_PER_BLOCK 50
104 104
105#ifndef SOL_NETLINK
106#define SOL_NETLINK 270
107#endif
108
105struct kvp_record { 109struct kvp_record {
106 char key[HV_KVP_EXCHANGE_MAX_KEY_SIZE]; 110 char key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
107 char value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE]; 111 char value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
@@ -1407,7 +1411,7 @@ netlink_send(int fd, struct cn_msg *msg)
1407 1411
1408int main(void) 1412int main(void)
1409{ 1413{
1410 int fd, len, sock_opt; 1414 int fd, len, nl_group;
1411 int error; 1415 int error;
1412 struct cn_msg *message; 1416 struct cn_msg *message;
1413 struct pollfd pfd; 1417 struct pollfd pfd;
@@ -1443,7 +1447,7 @@ int main(void)
1443 addr.nl_family = AF_NETLINK; 1447 addr.nl_family = AF_NETLINK;
1444 addr.nl_pad = 0; 1448 addr.nl_pad = 0;
1445 addr.nl_pid = 0; 1449 addr.nl_pid = 0;
1446 addr.nl_groups = CN_KVP_IDX; 1450 addr.nl_groups = 0;
1447 1451
1448 1452
1449 error = bind(fd, (struct sockaddr *)&addr, sizeof(addr)); 1453 error = bind(fd, (struct sockaddr *)&addr, sizeof(addr));
@@ -1452,8 +1456,8 @@ int main(void)
1452 close(fd); 1456 close(fd);
1453 exit(EXIT_FAILURE); 1457 exit(EXIT_FAILURE);
1454 } 1458 }
1455 sock_opt = addr.nl_groups; 1459 nl_group = CN_KVP_IDX;
1456 setsockopt(fd, 270, 1, &sock_opt, sizeof(sock_opt)); 1460 setsockopt(fd, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, &nl_group, sizeof(nl_group));
1457 /* 1461 /*
1458 * Register ourselves with the kernel. 1462 * Register ourselves with the kernel.
1459 */ 1463 */
@@ -1499,6 +1503,10 @@ int main(void)
1499 } 1503 }
1500 1504
1501 incoming_msg = (struct nlmsghdr *)kvp_recv_buffer; 1505 incoming_msg = (struct nlmsghdr *)kvp_recv_buffer;
1506
1507 if (incoming_msg->nlmsg_type != NLMSG_DONE)
1508 continue;
1509
1502 incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg); 1510 incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg);
1503 hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data; 1511 hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data;
1504 1512
diff --git a/tools/hv/hv_vss_daemon.c b/tools/hv/hv_vss_daemon.c
new file mode 100644
index 000000000000..fea03a3edaf4
--- /dev/null
+++ b/tools/hv/hv_vss_daemon.c
@@ -0,0 +1,249 @@
1/*
2 * An implementation of the host initiated guest snapshot for Hyper-V.
3 *
4 *
5 * Copyright (C) 2013, Microsoft, Inc.
6 * Author : K. Y. Srinivasan <kys@microsoft.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published
10 * by the Free Software Foundation.
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, GOOD TITLE or
15 * NON INFRINGEMENT. See the GNU General Public License for more
16 * details.
17 *
18 */
19
20
21#include <sys/types.h>
22#include <sys/socket.h>
23#include <sys/poll.h>
24#include <sys/ioctl.h>
25#include <linux/types.h>
26#include <fcntl.h>
27#include <stdio.h>
28#include <mntent.h>
29#include <stdlib.h>
30#include <unistd.h>
31#include <string.h>
32#include <ctype.h>
33#include <errno.h>
34#include <arpa/inet.h>
35#include <linux/fs.h>
36#include <linux/connector.h>
37#include <linux/hyperv.h>
38#include <linux/netlink.h>
39#include <syslog.h>
40
41static char vss_recv_buffer[4096];
42static char vss_send_buffer[4096];
43static struct sockaddr_nl addr;
44
45#ifndef SOL_NETLINK
46#define SOL_NETLINK 270
47#endif
48
49
50static int vss_do_freeze(char *dir, unsigned int cmd, char *fs_op)
51{
52 int ret, fd = open(dir, O_RDONLY);
53
54 if (fd < 0)
55 return 1;
56 ret = ioctl(fd, cmd, 0);
57 syslog(LOG_INFO, "VSS: %s of %s: %s\n", fs_op, dir, strerror(errno));
58 close(fd);
59 return !!ret;
60}
61
62static int vss_operate(int operation)
63{
64 char *fs_op;
65 char match[] = "/dev/";
66 FILE *mounts;
67 struct mntent *ent;
68 unsigned int cmd;
69 int error = 0, root_seen = 0;
70
71 switch (operation) {
72 case VSS_OP_FREEZE:
73 cmd = FIFREEZE;
74 fs_op = "freeze";
75 break;
76 case VSS_OP_THAW:
77 cmd = FITHAW;
78 fs_op = "thaw";
79 break;
80 default:
81 return -1;
82 }
83
84 mounts = setmntent("/proc/mounts", "r");
85 if (mounts == NULL)
86 return -1;
87
88 while ((ent = getmntent(mounts))) {
89 if (strncmp(ent->mnt_fsname, match, strlen(match)))
90 continue;
91 if (strcmp(ent->mnt_type, "iso9660") == 0)
92 continue;
93 if (strcmp(ent->mnt_dir, "/") == 0) {
94 root_seen = 1;
95 continue;
96 }
97 error |= vss_do_freeze(ent->mnt_dir, cmd, fs_op);
98 }
99 endmntent(mounts);
100
101 if (root_seen) {
102 error |= vss_do_freeze("/", cmd, fs_op);
103 }
104
105 return error;
106}
107
108static int netlink_send(int fd, struct cn_msg *msg)
109{
110 struct nlmsghdr *nlh;
111 unsigned int size;
112 struct msghdr message;
113 char buffer[64];
114 struct iovec iov[2];
115
116 size = NLMSG_SPACE(sizeof(struct cn_msg) + msg->len);
117
118 nlh = (struct nlmsghdr *)buffer;
119 nlh->nlmsg_seq = 0;
120 nlh->nlmsg_pid = getpid();
121 nlh->nlmsg_type = NLMSG_DONE;
122 nlh->nlmsg_len = NLMSG_LENGTH(size - sizeof(*nlh));
123 nlh->nlmsg_flags = 0;
124
125 iov[0].iov_base = nlh;
126 iov[0].iov_len = sizeof(*nlh);
127
128 iov[1].iov_base = msg;
129 iov[1].iov_len = size;
130
131 memset(&message, 0, sizeof(message));
132 message.msg_name = &addr;
133 message.msg_namelen = sizeof(addr);
134 message.msg_iov = iov;
135 message.msg_iovlen = 2;
136
137 return sendmsg(fd, &message, 0);
138}
139
140int main(void)
141{
142 int fd, len, nl_group;
143 int error;
144 struct cn_msg *message;
145 struct pollfd pfd;
146 struct nlmsghdr *incoming_msg;
147 struct cn_msg *incoming_cn_msg;
148 int op;
149 struct hv_vss_msg *vss_msg;
150
151 if (daemon(1, 0))
152 return 1;
153
154 openlog("Hyper-V VSS", 0, LOG_USER);
155 syslog(LOG_INFO, "VSS starting; pid is:%d", getpid());
156
157 fd = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR);
158 if (fd < 0) {
159 syslog(LOG_ERR, "netlink socket creation failed; error:%d", fd);
160 exit(EXIT_FAILURE);
161 }
162 addr.nl_family = AF_NETLINK;
163 addr.nl_pad = 0;
164 addr.nl_pid = 0;
165 addr.nl_groups = 0;
166
167
168 error = bind(fd, (struct sockaddr *)&addr, sizeof(addr));
169 if (error < 0) {
170 syslog(LOG_ERR, "bind failed; error:%d", error);
171 close(fd);
172 exit(EXIT_FAILURE);
173 }
174 nl_group = CN_VSS_IDX;
175 setsockopt(fd, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, &nl_group, sizeof(nl_group));
176 /*
177 * Register ourselves with the kernel.
178 */
179 message = (struct cn_msg *)vss_send_buffer;
180 message->id.idx = CN_VSS_IDX;
181 message->id.val = CN_VSS_VAL;
182 message->ack = 0;
183 vss_msg = (struct hv_vss_msg *)message->data;
184 vss_msg->vss_hdr.operation = VSS_OP_REGISTER;
185
186 message->len = sizeof(struct hv_vss_msg);
187
188 len = netlink_send(fd, message);
189 if (len < 0) {
190 syslog(LOG_ERR, "netlink_send failed; error:%d", len);
191 close(fd);
192 exit(EXIT_FAILURE);
193 }
194
195 pfd.fd = fd;
196
197 while (1) {
198 struct sockaddr *addr_p = (struct sockaddr *) &addr;
199 socklen_t addr_l = sizeof(addr);
200 pfd.events = POLLIN;
201 pfd.revents = 0;
202 poll(&pfd, 1, -1);
203
204 len = recvfrom(fd, vss_recv_buffer, sizeof(vss_recv_buffer), 0,
205 addr_p, &addr_l);
206
207 if (len < 0) {
208 syslog(LOG_ERR, "recvfrom failed; pid:%u error:%d %s",
209 addr.nl_pid, errno, strerror(errno));
210 close(fd);
211 return -1;
212 }
213
214 if (addr.nl_pid) {
215 syslog(LOG_WARNING,
216 "Received packet from untrusted pid:%u",
217 addr.nl_pid);
218 continue;
219 }
220
221 incoming_msg = (struct nlmsghdr *)vss_recv_buffer;
222
223 if (incoming_msg->nlmsg_type != NLMSG_DONE)
224 continue;
225
226 incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg);
227 vss_msg = (struct hv_vss_msg *)incoming_cn_msg->data;
228 op = vss_msg->vss_hdr.operation;
229 error = HV_S_OK;
230
231 switch (op) {
232 case VSS_OP_FREEZE:
233 case VSS_OP_THAW:
234 error = vss_operate(op);
235 if (error)
236 error = HV_E_FAIL;
237 break;
238 default:
239 syslog(LOG_ERR, "Illegal op:%d\n", op);
240 }
241 vss_msg->error = error;
242 len = netlink_send(fd, incoming_cn_msg);
243 if (len < 0) {
244 syslog(LOG_ERR, "net_link send failed; error:%d", len);
245 exit(EXIT_FAILURE);
246 }
247 }
248
249}