aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2015-02-15 13:48:44 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2015-02-15 13:48:44 -0500
commit4ba63072b998cc31515cc6305c25f3b808b50c01 (patch)
tree779863511765c70bfd232f676b885f940ba88722 /drivers/misc
parente29876723f7cb7728f0d6a674d23f92673e9f112 (diff)
parent5fb31cd839c21130c0b2524ceb9244e98dfe10e3 (diff)
Merge tag 'char-misc-3.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc
Pull char / misc patches from Greg KH: "Here's the big char/misc driver update for 3.20-rc1. Lots of little things in here, all described in the changelog. Nothing major or unusual, except maybe the binder selinux stuff, which was all acked by the proper selinux people and they thought it best to come through this tree. All of this has been in linux-next with no reported issues for a while" * tag 'char-misc-3.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc: (90 commits) coresight: fix function etm_writel_cp14() parameter order coresight-etm: remove check for unknown Kconfig macro coresight: fixing CPU hwid lookup in device tree coresight: remove the unnecessary function coresight_is_bit_set() coresight: fix the debug AMBA bus name coresight: remove the extra spaces coresight: fix the link between orphan connection and newly added device coresight: remove the unnecessary replicator property coresight: fix the replicator subtype value pdfdocs: Fix 'make pdfdocs' failure for 'uio-howto.tmpl' mcb: Fix error path of mcb_pci_probe virtio/console: verify device has config space ti-st: clean up data types (fix harmless memory corruption) mei: me: release hw from reset only during the reset flow mei: mask interrupt set bit on clean reset bit extcon: max77693: Constify struct regmap_config extcon: adc-jack: Release IIO channel on driver remove extcon: Remove duplicated include from extcon-class.c Drivers: hv: vmbus: hv_process_timer_expiration() can be static Drivers: hv: vmbus: serialize Offer and Rescind offer ...
Diffstat (limited to 'drivers/misc')
-rw-r--r--drivers/misc/ad525x_dpot-spi.c4
-rw-r--r--drivers/misc/ad525x_dpot.c7
-rw-r--r--drivers/misc/genwqe/card_base.h1
-rw-r--r--drivers/misc/genwqe/card_sysfs.c1
-rw-r--r--drivers/misc/ioc4.c31
-rw-r--r--drivers/misc/mei/amthif.c14
-rw-r--r--drivers/misc/mei/bus.c69
-rw-r--r--drivers/misc/mei/client.c156
-rw-r--r--drivers/misc/mei/client.h17
-rw-r--r--drivers/misc/mei/debugfs.c32
-rw-r--r--drivers/misc/mei/hbm.c34
-rw-r--r--drivers/misc/mei/hw-me.c5
-rw-r--r--drivers/misc/mei/main.c22
-rw-r--r--drivers/misc/mei/mei_dev.h8
-rw-r--r--drivers/misc/mei/nfc.c2
-rw-r--r--drivers/misc/mei/wd.c1
-rw-r--r--drivers/misc/ti-st/st_core.c24
-rw-r--r--drivers/misc/ti-st/st_kim.c144
-rw-r--r--drivers/misc/ti-st/st_ll.c17
-rw-r--r--drivers/misc/vmw_vmci/vmci_driver.c2
-rw-r--r--drivers/misc/vmw_vmci/vmci_host.c13
21 files changed, 418 insertions, 186 deletions
diff --git a/drivers/misc/ad525x_dpot-spi.c b/drivers/misc/ad525x_dpot-spi.c
index 9da04ede04f3..f4c82eafa8e5 100644
--- a/drivers/misc/ad525x_dpot-spi.c
+++ b/drivers/misc/ad525x_dpot-spi.c
@@ -15,18 +15,21 @@
15static int write8(void *client, u8 val) 15static int write8(void *client, u8 val)
16{ 16{
17 u8 data = val; 17 u8 data = val;
18
18 return spi_write(client, &data, 1); 19 return spi_write(client, &data, 1);
19} 20}
20 21
21static int write16(void *client, u8 reg, u8 val) 22static int write16(void *client, u8 reg, u8 val)
22{ 23{
23 u8 data[2] = {reg, val}; 24 u8 data[2] = {reg, val};
25
24 return spi_write(client, data, 2); 26 return spi_write(client, data, 2);
25} 27}
26 28
27static int write24(void *client, u8 reg, u16 val) 29static int write24(void *client, u8 reg, u16 val)
28{ 30{
29 u8 data[3] = {reg, val >> 8, val}; 31 u8 data[3] = {reg, val >> 8, val};
32
30 return spi_write(client, data, 3); 33 return spi_write(client, data, 3);
31} 34}
32 35
@@ -34,6 +37,7 @@ static int read8(void *client)
34{ 37{
35 int ret; 38 int ret;
36 u8 data; 39 u8 data;
40
37 ret = spi_read(client, &data, 1); 41 ret = spi_read(client, &data, 1);
38 if (ret < 0) 42 if (ret < 0)
39 return ret; 43 return ret;
diff --git a/drivers/misc/ad525x_dpot.c b/drivers/misc/ad525x_dpot.c
index a43053daad0e..15e88078ba1e 100644
--- a/drivers/misc/ad525x_dpot.c
+++ b/drivers/misc/ad525x_dpot.c
@@ -176,6 +176,7 @@ static s32 dpot_read_i2c(struct dpot_data *dpot, u8 reg)
176{ 176{
177 int value; 177 int value;
178 unsigned ctrl = 0; 178 unsigned ctrl = 0;
179
179 switch (dpot->uid) { 180 switch (dpot->uid) {
180 case DPOT_UID(AD5246_ID): 181 case DPOT_UID(AD5246_ID):
181 case DPOT_UID(AD5247_ID): 182 case DPOT_UID(AD5247_ID):
@@ -333,7 +334,6 @@ static s32 dpot_write_i2c(struct dpot_data *dpot, u8 reg, u16 value)
333 case DPOT_UID(AD5246_ID): 334 case DPOT_UID(AD5246_ID):
334 case DPOT_UID(AD5247_ID): 335 case DPOT_UID(AD5247_ID):
335 return dpot_write_d8(dpot, value); 336 return dpot_write_d8(dpot, value);
336 break;
337 337
338 case DPOT_UID(AD5245_ID): 338 case DPOT_UID(AD5245_ID):
339 case DPOT_UID(AD5241_ID): 339 case DPOT_UID(AD5241_ID):
@@ -345,7 +345,6 @@ static s32 dpot_write_i2c(struct dpot_data *dpot, u8 reg, u16 value)
345 ctrl = ((reg & DPOT_RDAC_MASK) == DPOT_RDAC0) ? 345 ctrl = ((reg & DPOT_RDAC_MASK) == DPOT_RDAC0) ?
346 0 : DPOT_AD5282_RDAC_AB; 346 0 : DPOT_AD5282_RDAC_AB;
347 return dpot_write_r8d8(dpot, ctrl, value); 347 return dpot_write_r8d8(dpot, ctrl, value);
348 break;
349 case DPOT_UID(AD5171_ID): 348 case DPOT_UID(AD5171_ID):
350 case DPOT_UID(AD5273_ID): 349 case DPOT_UID(AD5273_ID):
351 if (reg & DPOT_ADDR_OTP) { 350 if (reg & DPOT_ADDR_OTP) {
@@ -355,7 +354,6 @@ static s32 dpot_write_i2c(struct dpot_data *dpot, u8 reg, u16 value)
355 ctrl = DPOT_AD5273_FUSE; 354 ctrl = DPOT_AD5273_FUSE;
356 } 355 }
357 return dpot_write_r8d8(dpot, ctrl, value); 356 return dpot_write_r8d8(dpot, ctrl, value);
358 break;
359 case DPOT_UID(AD5172_ID): 357 case DPOT_UID(AD5172_ID):
360 case DPOT_UID(AD5173_ID): 358 case DPOT_UID(AD5173_ID):
361 ctrl = ((reg & DPOT_RDAC_MASK) == DPOT_RDAC0) ? 359 ctrl = ((reg & DPOT_RDAC_MASK) == DPOT_RDAC0) ?
@@ -367,7 +365,6 @@ static s32 dpot_write_i2c(struct dpot_data *dpot, u8 reg, u16 value)
367 ctrl |= DPOT_AD5170_2_3_FUSE; 365 ctrl |= DPOT_AD5170_2_3_FUSE;
368 } 366 }
369 return dpot_write_r8d8(dpot, ctrl, value); 367 return dpot_write_r8d8(dpot, ctrl, value);
370 break;
371 case DPOT_UID(AD5170_ID): 368 case DPOT_UID(AD5170_ID):
372 if (reg & DPOT_ADDR_OTP) { 369 if (reg & DPOT_ADDR_OTP) {
373 tmp = dpot_read_r8d16(dpot, tmp); 370 tmp = dpot_read_r8d16(dpot, tmp);
@@ -376,7 +373,6 @@ static s32 dpot_write_i2c(struct dpot_data *dpot, u8 reg, u16 value)
376 ctrl = DPOT_AD5170_2_3_FUSE; 373 ctrl = DPOT_AD5170_2_3_FUSE;
377 } 374 }
378 return dpot_write_r8d8(dpot, ctrl, value); 375 return dpot_write_r8d8(dpot, ctrl, value);
379 break;
380 case DPOT_UID(AD5272_ID): 376 case DPOT_UID(AD5272_ID):
381 case DPOT_UID(AD5274_ID): 377 case DPOT_UID(AD5274_ID):
382 dpot_write_r8d8(dpot, DPOT_AD5270_1_2_4_CTRLREG << 2, 378 dpot_write_r8d8(dpot, DPOT_AD5270_1_2_4_CTRLREG << 2,
@@ -391,7 +387,6 @@ static s32 dpot_write_i2c(struct dpot_data *dpot, u8 reg, u16 value)
391 387
392 return dpot_write_r8d8(dpot, (DPOT_AD5270_1_2_4_RDAC << 2) | 388 return dpot_write_r8d8(dpot, (DPOT_AD5270_1_2_4_RDAC << 2) |
393 (value >> 8), value & 0xFF); 389 (value >> 8), value & 0xFF);
394 break;
395 default: 390 default:
396 if (reg & DPOT_ADDR_CMD) 391 if (reg & DPOT_ADDR_CMD)
397 return dpot_write_d8(dpot, reg); 392 return dpot_write_d8(dpot, reg);
diff --git a/drivers/misc/genwqe/card_base.h b/drivers/misc/genwqe/card_base.h
index c64d7cad1085..e7353449874b 100644
--- a/drivers/misc/genwqe/card_base.h
+++ b/drivers/misc/genwqe/card_base.h
@@ -34,7 +34,6 @@
34#include <linux/semaphore.h> 34#include <linux/semaphore.h>
35#include <linux/uaccess.h> 35#include <linux/uaccess.h>
36#include <linux/io.h> 36#include <linux/io.h>
37#include <linux/version.h>
38#include <linux/debugfs.h> 37#include <linux/debugfs.h>
39#include <linux/slab.h> 38#include <linux/slab.h>
40 39
diff --git a/drivers/misc/genwqe/card_sysfs.c b/drivers/misc/genwqe/card_sysfs.c
index 2c33fbca9225..6ab31eff0536 100644
--- a/drivers/misc/genwqe/card_sysfs.c
+++ b/drivers/misc/genwqe/card_sysfs.c
@@ -24,7 +24,6 @@
24 * debugging, please also see the debugfs interfaces of this driver. 24 * debugging, please also see the debugfs interfaces of this driver.
25 */ 25 */
26 26
27#include <linux/version.h>
28#include <linux/kernel.h> 27#include <linux/kernel.h>
29#include <linux/types.h> 28#include <linux/types.h>
30#include <linux/module.h> 29#include <linux/module.h>
diff --git a/drivers/misc/ioc4.c b/drivers/misc/ioc4.c
index 3336ddca45ac..8758d033db23 100644
--- a/drivers/misc/ioc4.c
+++ b/drivers/misc/ioc4.c
@@ -144,9 +144,9 @@ ioc4_clock_calibrate(struct ioc4_driver_data *idd)
144{ 144{
145 union ioc4_int_out int_out; 145 union ioc4_int_out int_out;
146 union ioc4_gpcr gpcr; 146 union ioc4_gpcr gpcr;
147 unsigned int state, last_state = 1; 147 unsigned int state, last_state;
148 uint64_t start, end, period; 148 uint64_t start, end, period;
149 unsigned int count = 0; 149 unsigned int count;
150 150
151 /* Enable output */ 151 /* Enable output */
152 gpcr.raw = 0; 152 gpcr.raw = 0;
@@ -167,19 +167,20 @@ ioc4_clock_calibrate(struct ioc4_driver_data *idd)
167 mmiowb(); 167 mmiowb();
168 168
169 /* Check square wave period averaged over some number of cycles */ 169 /* Check square wave period averaged over some number of cycles */
170 do { 170 start = ktime_get_ns();
171 int_out.raw = readl(&idd->idd_misc_regs->int_out.raw); 171 state = 1; /* make sure the first read isn't a rising edge */
172 state = int_out.fields.int_out; 172 for (count = 0; count <= IOC4_CALIBRATE_END; count++) {
173 if (!last_state && state) { 173 do { /* wait for a rising edge */
174 count++; 174 last_state = state;
175 if (count == IOC4_CALIBRATE_END) { 175 int_out.raw = readl(&idd->idd_misc_regs->int_out.raw);
176 end = ktime_get_ns(); 176 state = int_out.fields.int_out;
177 break; 177 } while (last_state || !state);
178 } else if (count == IOC4_CALIBRATE_DISCARD) 178
179 start = ktime_get_ns(); 179 /* discard the first few cycles */
180 } 180 if (count == IOC4_CALIBRATE_DISCARD)
181 last_state = state; 181 start = ktime_get_ns();
182 } while (1); 182 }
183 end = ktime_get_ns();
183 184
184 /* Calculation rearranged to preserve intermediate precision. 185 /* Calculation rearranged to preserve intermediate precision.
185 * Logically: 186 * Logically:
diff --git a/drivers/misc/mei/amthif.c b/drivers/misc/mei/amthif.c
index 79f53941779d..c4cb9a984a5f 100644
--- a/drivers/misc/mei/amthif.c
+++ b/drivers/misc/mei/amthif.c
@@ -97,23 +97,25 @@ int mei_amthif_host_init(struct mei_device *dev)
97 /* allocate storage for ME message buffer */ 97 /* allocate storage for ME message buffer */
98 msg_buf = kcalloc(dev->iamthif_mtu, 98 msg_buf = kcalloc(dev->iamthif_mtu,
99 sizeof(unsigned char), GFP_KERNEL); 99 sizeof(unsigned char), GFP_KERNEL);
100 if (!msg_buf) 100 if (!msg_buf) {
101 return -ENOMEM; 101 ret = -ENOMEM;
102 goto out;
103 }
102 104
103 dev->iamthif_msg_buf = msg_buf; 105 dev->iamthif_msg_buf = msg_buf;
104 106
105 ret = mei_cl_link(cl, MEI_IAMTHIF_HOST_CLIENT_ID); 107 ret = mei_cl_link(cl, MEI_IAMTHIF_HOST_CLIENT_ID);
106
107 if (ret < 0) { 108 if (ret < 0) {
108 dev_err(dev->dev, 109 dev_err(dev->dev, "amthif: failed cl_link %d\n", ret);
109 "amthif: failed link client %d\n", ret); 110 goto out;
110 return ret;
111 } 111 }
112 112
113 ret = mei_cl_connect(cl, NULL); 113 ret = mei_cl_connect(cl, NULL);
114 114
115 dev->iamthif_state = MEI_IAMTHIF_IDLE; 115 dev->iamthif_state = MEI_IAMTHIF_IDLE;
116 116
117out:
118 mei_me_cl_put(me_cl);
117 return ret; 119 return ret;
118} 120}
119 121
diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c
index b3a72bca5242..be767f4db26a 100644
--- a/drivers/misc/mei/bus.c
+++ b/drivers/misc/mei/bus.c
@@ -224,46 +224,53 @@ void mei_cl_driver_unregister(struct mei_cl_driver *driver)
224} 224}
225EXPORT_SYMBOL_GPL(mei_cl_driver_unregister); 225EXPORT_SYMBOL_GPL(mei_cl_driver_unregister);
226 226
227static int ___mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length, 227static ssize_t ___mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length,
228 bool blocking) 228 bool blocking)
229{ 229{
230 struct mei_device *dev; 230 struct mei_device *dev;
231 struct mei_me_client *me_cl; 231 struct mei_me_client *me_cl = NULL;
232 struct mei_cl_cb *cb; 232 struct mei_cl_cb *cb = NULL;
233 int rets; 233 ssize_t rets;
234 234
235 if (WARN_ON(!cl || !cl->dev)) 235 if (WARN_ON(!cl || !cl->dev))
236 return -ENODEV; 236 return -ENODEV;
237 237
238 dev = cl->dev; 238 dev = cl->dev;
239 239
240 if (cl->state != MEI_FILE_CONNECTED) 240 mutex_lock(&dev->device_lock);
241 return -ENODEV; 241 if (cl->state != MEI_FILE_CONNECTED) {
242 rets = -ENODEV;
243 goto out;
244 }
242 245
243 /* Check if we have an ME client device */ 246 /* Check if we have an ME client device */
244 me_cl = mei_me_cl_by_uuid_id(dev, &cl->cl_uuid, cl->me_client_id); 247 me_cl = mei_me_cl_by_uuid_id(dev, &cl->cl_uuid, cl->me_client_id);
245 if (!me_cl) 248 if (!me_cl) {
246 return -ENOTTY; 249 rets = -ENOTTY;
250 goto out;
251 }
247 252
248 if (length > me_cl->props.max_msg_length) 253 if (length > me_cl->props.max_msg_length) {
249 return -EFBIG; 254 rets = -EFBIG;
255 goto out;
256 }
250 257
251 cb = mei_io_cb_init(cl, NULL); 258 cb = mei_io_cb_init(cl, NULL);
252 if (!cb) 259 if (!cb) {
253 return -ENOMEM; 260 rets = -ENOMEM;
261 goto out;
262 }
254 263
255 rets = mei_io_cb_alloc_req_buf(cb, length); 264 rets = mei_io_cb_alloc_req_buf(cb, length);
256 if (rets < 0) { 265 if (rets < 0)
257 mei_io_cb_free(cb); 266 goto out;
258 return rets;
259 }
260 267
261 memcpy(cb->request_buffer.data, buf, length); 268 memcpy(cb->request_buffer.data, buf, length);
262 269
263 mutex_lock(&dev->device_lock);
264
265 rets = mei_cl_write(cl, cb, blocking); 270 rets = mei_cl_write(cl, cb, blocking);
266 271
272out:
273 mei_me_cl_put(me_cl);
267 mutex_unlock(&dev->device_lock); 274 mutex_unlock(&dev->device_lock);
268 if (rets < 0) 275 if (rets < 0)
269 mei_io_cb_free(cb); 276 mei_io_cb_free(cb);
@@ -271,12 +278,12 @@ static int ___mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length,
271 return rets; 278 return rets;
272} 279}
273 280
274int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length) 281ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length)
275{ 282{
276 struct mei_device *dev; 283 struct mei_device *dev;
277 struct mei_cl_cb *cb; 284 struct mei_cl_cb *cb;
278 size_t r_length; 285 size_t r_length;
279 int err; 286 ssize_t rets;
280 287
281 if (WARN_ON(!cl || !cl->dev)) 288 if (WARN_ON(!cl || !cl->dev))
282 return -ENODEV; 289 return -ENODEV;
@@ -286,11 +293,9 @@ int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length)
286 mutex_lock(&dev->device_lock); 293 mutex_lock(&dev->device_lock);
287 294
288 if (!cl->read_cb) { 295 if (!cl->read_cb) {
289 err = mei_cl_read_start(cl, length); 296 rets = mei_cl_read_start(cl, length);
290 if (err < 0) { 297 if (rets < 0)
291 mutex_unlock(&dev->device_lock); 298 goto out;
292 return err;
293 }
294 } 299 }
295 300
296 if (cl->reading_state != MEI_READ_COMPLETE && 301 if (cl->reading_state != MEI_READ_COMPLETE &&
@@ -313,13 +318,13 @@ int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length)
313 cb = cl->read_cb; 318 cb = cl->read_cb;
314 319
315 if (cl->reading_state != MEI_READ_COMPLETE) { 320 if (cl->reading_state != MEI_READ_COMPLETE) {
316 r_length = 0; 321 rets = 0;
317 goto out; 322 goto out;
318 } 323 }
319 324
320 r_length = min_t(size_t, length, cb->buf_idx); 325 r_length = min_t(size_t, length, cb->buf_idx);
321
322 memcpy(buf, cb->response_buffer.data, r_length); 326 memcpy(buf, cb->response_buffer.data, r_length);
327 rets = r_length;
323 328
324 mei_io_cb_free(cb); 329 mei_io_cb_free(cb);
325 cl->reading_state = MEI_IDLE; 330 cl->reading_state = MEI_IDLE;
@@ -328,20 +333,20 @@ int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length)
328out: 333out:
329 mutex_unlock(&dev->device_lock); 334 mutex_unlock(&dev->device_lock);
330 335
331 return r_length; 336 return rets;
332} 337}
333 338
334inline int __mei_cl_async_send(struct mei_cl *cl, u8 *buf, size_t length) 339inline ssize_t __mei_cl_async_send(struct mei_cl *cl, u8 *buf, size_t length)
335{ 340{
336 return ___mei_cl_send(cl, buf, length, 0); 341 return ___mei_cl_send(cl, buf, length, 0);
337} 342}
338 343
339inline int __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length) 344inline ssize_t __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length)
340{ 345{
341 return ___mei_cl_send(cl, buf, length, 1); 346 return ___mei_cl_send(cl, buf, length, 1);
342} 347}
343 348
344int mei_cl_send(struct mei_cl_device *device, u8 *buf, size_t length) 349ssize_t mei_cl_send(struct mei_cl_device *device, u8 *buf, size_t length)
345{ 350{
346 struct mei_cl *cl = device->cl; 351 struct mei_cl *cl = device->cl;
347 352
@@ -355,7 +360,7 @@ int mei_cl_send(struct mei_cl_device *device, u8 *buf, size_t length)
355} 360}
356EXPORT_SYMBOL_GPL(mei_cl_send); 361EXPORT_SYMBOL_GPL(mei_cl_send);
357 362
358int mei_cl_recv(struct mei_cl_device *device, u8 *buf, size_t length) 363ssize_t mei_cl_recv(struct mei_cl_device *device, u8 *buf, size_t length)
359{ 364{
360 struct mei_cl *cl = device->cl; 365 struct mei_cl *cl = device->cl;
361 366
diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c
index 1382d551d7ed..dfbddfe1c7a0 100644
--- a/drivers/misc/mei/client.c
+++ b/drivers/misc/mei/client.c
@@ -27,7 +27,63 @@
27#include "client.h" 27#include "client.h"
28 28
29/** 29/**
30 * mei_me_cl_init - initialize me client
31 *
32 * @me_cl: me client
33 */
34void mei_me_cl_init(struct mei_me_client *me_cl)
35{
36 INIT_LIST_HEAD(&me_cl->list);
37 kref_init(&me_cl->refcnt);
38}
39
40/**
41 * mei_me_cl_get - increases me client refcount
42 *
43 * @me_cl: me client
44 *
45 * Locking: called under "dev->device_lock" lock
46 *
47 * Return: me client or NULL
48 */
49struct mei_me_client *mei_me_cl_get(struct mei_me_client *me_cl)
50{
51 if (me_cl)
52 kref_get(&me_cl->refcnt);
53
54 return me_cl;
55}
56
57/**
58 * mei_me_cl_release - unlink and free me client
59 *
60 * Locking: called under "dev->device_lock" lock
61 *
62 * @ref: me_client refcount
63 */
64static void mei_me_cl_release(struct kref *ref)
65{
66 struct mei_me_client *me_cl =
67 container_of(ref, struct mei_me_client, refcnt);
68 list_del(&me_cl->list);
69 kfree(me_cl);
70}
71/**
72 * mei_me_cl_put - decrease me client refcount and free client if necessary
73 *
74 * Locking: called under "dev->device_lock" lock
75 *
76 * @me_cl: me client
77 */
78void mei_me_cl_put(struct mei_me_client *me_cl)
79{
80 if (me_cl)
81 kref_put(&me_cl->refcnt, mei_me_cl_release);
82}
83
84/**
30 * mei_me_cl_by_uuid - locate me client by uuid 85 * mei_me_cl_by_uuid - locate me client by uuid
86 * increases ref count
31 * 87 *
32 * @dev: mei device 88 * @dev: mei device
33 * @uuid: me client uuid 89 * @uuid: me client uuid
@@ -43,13 +99,14 @@ struct mei_me_client *mei_me_cl_by_uuid(const struct mei_device *dev,
43 99
44 list_for_each_entry(me_cl, &dev->me_clients, list) 100 list_for_each_entry(me_cl, &dev->me_clients, list)
45 if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0) 101 if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0)
46 return me_cl; 102 return mei_me_cl_get(me_cl);
47 103
48 return NULL; 104 return NULL;
49} 105}
50 106
51/** 107/**
52 * mei_me_cl_by_id - locate me client by client id 108 * mei_me_cl_by_id - locate me client by client id
109 * increases ref count
53 * 110 *
54 * @dev: the device structure 111 * @dev: the device structure
55 * @client_id: me client id 112 * @client_id: me client id
@@ -65,12 +122,14 @@ struct mei_me_client *mei_me_cl_by_id(struct mei_device *dev, u8 client_id)
65 122
66 list_for_each_entry(me_cl, &dev->me_clients, list) 123 list_for_each_entry(me_cl, &dev->me_clients, list)
67 if (me_cl->client_id == client_id) 124 if (me_cl->client_id == client_id)
68 return me_cl; 125 return mei_me_cl_get(me_cl);
126
69 return NULL; 127 return NULL;
70} 128}
71 129
72/** 130/**
73 * mei_me_cl_by_uuid_id - locate me client by client id and uuid 131 * mei_me_cl_by_uuid_id - locate me client by client id and uuid
132 * increases ref count
74 * 133 *
75 * @dev: the device structure 134 * @dev: the device structure
76 * @uuid: me client uuid 135 * @uuid: me client uuid
@@ -88,31 +147,67 @@ struct mei_me_client *mei_me_cl_by_uuid_id(struct mei_device *dev,
88 list_for_each_entry(me_cl, &dev->me_clients, list) 147 list_for_each_entry(me_cl, &dev->me_clients, list)
89 if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0 && 148 if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0 &&
90 me_cl->client_id == client_id) 149 me_cl->client_id == client_id)
91 return me_cl; 150 return mei_me_cl_get(me_cl);
151
92 return NULL; 152 return NULL;
93} 153}
94 154
95/** 155/**
96 * mei_me_cl_remove - remove me client matching uuid and client_id 156 * mei_me_cl_rm_by_uuid - remove all me clients matching uuid
97 * 157 *
98 * @dev: the device structure 158 * @dev: the device structure
99 * @uuid: me client uuid 159 * @uuid: me client uuid
100 * @client_id: me client address 160 *
161 * Locking: called under "dev->device_lock" lock
101 */ 162 */
102void mei_me_cl_remove(struct mei_device *dev, const uuid_le *uuid, u8 client_id) 163void mei_me_cl_rm_by_uuid(struct mei_device *dev, const uuid_le *uuid)
103{ 164{
104 struct mei_me_client *me_cl, *next; 165 struct mei_me_client *me_cl, *next;
105 166
167 dev_dbg(dev->dev, "remove %pUl\n", uuid);
168 list_for_each_entry_safe(me_cl, next, &dev->me_clients, list)
169 if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0)
170 mei_me_cl_put(me_cl);
171}
172
173/**
174 * mei_me_cl_rm_by_uuid_id - remove all me clients matching client id
175 *
176 * @dev: the device structure
177 * @uuid: me client uuid
178 * @id: me client id
179 *
180 * Locking: called under "dev->device_lock" lock
181 */
182void mei_me_cl_rm_by_uuid_id(struct mei_device *dev, const uuid_le *uuid, u8 id)
183{
184 struct mei_me_client *me_cl, *next;
185 const uuid_le *pn;
186
187 dev_dbg(dev->dev, "remove %pUl %d\n", uuid, id);
106 list_for_each_entry_safe(me_cl, next, &dev->me_clients, list) { 188 list_for_each_entry_safe(me_cl, next, &dev->me_clients, list) {
107 if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0 && 189 pn = &me_cl->props.protocol_name;
108 me_cl->client_id == client_id) { 190 if (me_cl->client_id == id && uuid_le_cmp(*uuid, *pn) == 0)
109 list_del(&me_cl->list); 191 mei_me_cl_put(me_cl);
110 kfree(me_cl);
111 break;
112 }
113 } 192 }
114} 193}
115 194
195/**
196 * mei_me_cl_rm_all - remove all me clients
197 *
198 * @dev: the device structure
199 *
200 * Locking: called under "dev->device_lock" lock
201 */
202void mei_me_cl_rm_all(struct mei_device *dev)
203{
204 struct mei_me_client *me_cl, *next;
205
206 list_for_each_entry_safe(me_cl, next, &dev->me_clients, list)
207 mei_me_cl_put(me_cl);
208}
209
210
116 211
117/** 212/**
118 * mei_cl_cmp_id - tells if the clients are the same 213 * mei_cl_cmp_id - tells if the clients are the same
@@ -695,6 +790,7 @@ int mei_cl_flow_ctrl_creds(struct mei_cl *cl)
695{ 790{
696 struct mei_device *dev; 791 struct mei_device *dev;
697 struct mei_me_client *me_cl; 792 struct mei_me_client *me_cl;
793 int rets = 0;
698 794
699 if (WARN_ON(!cl || !cl->dev)) 795 if (WARN_ON(!cl || !cl->dev))
700 return -EINVAL; 796 return -EINVAL;
@@ -704,18 +800,19 @@ int mei_cl_flow_ctrl_creds(struct mei_cl *cl)
704 if (cl->mei_flow_ctrl_creds > 0) 800 if (cl->mei_flow_ctrl_creds > 0)
705 return 1; 801 return 1;
706 802
707 me_cl = mei_me_cl_by_id(dev, cl->me_client_id); 803 me_cl = mei_me_cl_by_uuid_id(dev, &cl->cl_uuid, cl->me_client_id);
708 if (!me_cl) { 804 if (!me_cl) {
709 cl_err(dev, cl, "no such me client %d\n", cl->me_client_id); 805 cl_err(dev, cl, "no such me client %d\n", cl->me_client_id);
710 return -ENOENT; 806 return -ENOENT;
711 } 807 }
712 808
713 if (me_cl->mei_flow_ctrl_creds) { 809 if (me_cl->mei_flow_ctrl_creds > 0) {
810 rets = 1;
714 if (WARN_ON(me_cl->props.single_recv_buf == 0)) 811 if (WARN_ON(me_cl->props.single_recv_buf == 0))
715 return -EINVAL; 812 rets = -EINVAL;
716 return 1;
717 } 813 }
718 return 0; 814 mei_me_cl_put(me_cl);
815 return rets;
719} 816}
720 817
721/** 818/**
@@ -732,28 +829,36 @@ int mei_cl_flow_ctrl_reduce(struct mei_cl *cl)
732{ 829{
733 struct mei_device *dev; 830 struct mei_device *dev;
734 struct mei_me_client *me_cl; 831 struct mei_me_client *me_cl;
832 int rets;
735 833
736 if (WARN_ON(!cl || !cl->dev)) 834 if (WARN_ON(!cl || !cl->dev))
737 return -EINVAL; 835 return -EINVAL;
738 836
739 dev = cl->dev; 837 dev = cl->dev;
740 838
741 me_cl = mei_me_cl_by_id(dev, cl->me_client_id); 839 me_cl = mei_me_cl_by_uuid_id(dev, &cl->cl_uuid, cl->me_client_id);
742 if (!me_cl) { 840 if (!me_cl) {
743 cl_err(dev, cl, "no such me client %d\n", cl->me_client_id); 841 cl_err(dev, cl, "no such me client %d\n", cl->me_client_id);
744 return -ENOENT; 842 return -ENOENT;
745 } 843 }
746 844
747 if (me_cl->props.single_recv_buf) { 845 if (me_cl->props.single_recv_buf) {
748 if (WARN_ON(me_cl->mei_flow_ctrl_creds <= 0)) 846 if (WARN_ON(me_cl->mei_flow_ctrl_creds <= 0)) {
749 return -EINVAL; 847 rets = -EINVAL;
848 goto out;
849 }
750 me_cl->mei_flow_ctrl_creds--; 850 me_cl->mei_flow_ctrl_creds--;
751 } else { 851 } else {
752 if (WARN_ON(cl->mei_flow_ctrl_creds <= 0)) 852 if (WARN_ON(cl->mei_flow_ctrl_creds <= 0)) {
753 return -EINVAL; 853 rets = -EINVAL;
854 goto out;
855 }
754 cl->mei_flow_ctrl_creds--; 856 cl->mei_flow_ctrl_creds--;
755 } 857 }
756 return 0; 858 rets = 0;
859out:
860 mei_me_cl_put(me_cl);
861 return rets;
757} 862}
758 863
759/** 864/**
@@ -788,6 +893,9 @@ int mei_cl_read_start(struct mei_cl *cl, size_t length)
788 cl_err(dev, cl, "no such me client %d\n", cl->me_client_id); 893 cl_err(dev, cl, "no such me client %d\n", cl->me_client_id);
789 return -ENOTTY; 894 return -ENOTTY;
790 } 895 }
896 /* always allocate at least client max message */
897 length = max_t(size_t, length, me_cl->props.max_msg_length);
898 mei_me_cl_put(me_cl);
791 899
792 rets = pm_runtime_get(dev->dev); 900 rets = pm_runtime_get(dev->dev);
793 if (rets < 0 && rets != -EINPROGRESS) { 901 if (rets < 0 && rets != -EINPROGRESS) {
@@ -802,8 +910,6 @@ int mei_cl_read_start(struct mei_cl *cl, size_t length)
802 goto out; 910 goto out;
803 } 911 }
804 912
805 /* always allocate at least client max message */
806 length = max_t(size_t, length, me_cl->props.max_msg_length);
807 rets = mei_io_cb_alloc_resp_buf(cb, length); 913 rets = mei_io_cb_alloc_resp_buf(cb, length);
808 if (rets) 914 if (rets)
809 goto out; 915 goto out;
diff --git a/drivers/misc/mei/client.h b/drivers/misc/mei/client.h
index d9d0c1525259..cfcde8e97fc4 100644
--- a/drivers/misc/mei/client.h
+++ b/drivers/misc/mei/client.h
@@ -24,15 +24,22 @@
24 24
25#include "mei_dev.h" 25#include "mei_dev.h"
26 26
27/*
28 * reference counting base function
29 */
30void mei_me_cl_init(struct mei_me_client *me_cl);
31void mei_me_cl_put(struct mei_me_client *me_cl);
32struct mei_me_client *mei_me_cl_get(struct mei_me_client *me_cl);
33
27struct mei_me_client *mei_me_cl_by_uuid(const struct mei_device *dev, 34struct mei_me_client *mei_me_cl_by_uuid(const struct mei_device *dev,
28 const uuid_le *cuuid); 35 const uuid_le *uuid);
29struct mei_me_client *mei_me_cl_by_id(struct mei_device *dev, u8 client_id); 36struct mei_me_client *mei_me_cl_by_id(struct mei_device *dev, u8 client_id);
30
31struct mei_me_client *mei_me_cl_by_uuid_id(struct mei_device *dev, 37struct mei_me_client *mei_me_cl_by_uuid_id(struct mei_device *dev,
32 const uuid_le *uuid, u8 client_id); 38 const uuid_le *uuid, u8 client_id);
33 39void mei_me_cl_rm_by_uuid(struct mei_device *dev, const uuid_le *uuid);
34void mei_me_cl_remove(struct mei_device *dev, 40void mei_me_cl_rm_by_uuid_id(struct mei_device *dev,
35 const uuid_le *uuid, u8 client_id); 41 const uuid_le *uuid, u8 id);
42void mei_me_cl_rm_all(struct mei_device *dev);
36 43
37/* 44/*
38 * MEI IO Functions 45 * MEI IO Functions
diff --git a/drivers/misc/mei/debugfs.c b/drivers/misc/mei/debugfs.c
index b60b4263cf0f..b125380ee871 100644
--- a/drivers/misc/mei/debugfs.c
+++ b/drivers/misc/mei/debugfs.c
@@ -21,20 +21,22 @@
21#include <linux/mei.h> 21#include <linux/mei.h>
22 22
23#include "mei_dev.h" 23#include "mei_dev.h"
24#include "client.h"
24#include "hw.h" 25#include "hw.h"
25 26
26static ssize_t mei_dbgfs_read_meclients(struct file *fp, char __user *ubuf, 27static ssize_t mei_dbgfs_read_meclients(struct file *fp, char __user *ubuf,
27 size_t cnt, loff_t *ppos) 28 size_t cnt, loff_t *ppos)
28{ 29{
29 struct mei_device *dev = fp->private_data; 30 struct mei_device *dev = fp->private_data;
30 struct mei_me_client *me_cl; 31 struct mei_me_client *me_cl, *n;
31 size_t bufsz = 1; 32 size_t bufsz = 1;
32 char *buf; 33 char *buf;
33 int i = 0; 34 int i = 0;
34 int pos = 0; 35 int pos = 0;
35 int ret; 36 int ret;
36 37
37#define HDR " |id|fix| UUID |con|msg len|sb|\n" 38#define HDR \
39" |id|fix| UUID |con|msg len|sb|refc|\n"
38 40
39 mutex_lock(&dev->device_lock); 41 mutex_lock(&dev->device_lock);
40 42
@@ -54,16 +56,22 @@ static ssize_t mei_dbgfs_read_meclients(struct file *fp, char __user *ubuf,
54 if (dev->dev_state != MEI_DEV_ENABLED) 56 if (dev->dev_state != MEI_DEV_ENABLED)
55 goto out; 57 goto out;
56 58
57 list_for_each_entry(me_cl, &dev->me_clients, list) { 59 list_for_each_entry_safe(me_cl, n, &dev->me_clients, list) {
58 60
59 pos += scnprintf(buf + pos, bufsz - pos, 61 me_cl = mei_me_cl_get(me_cl);
60 "%2d|%2d|%3d|%pUl|%3d|%7d|%2d|\n", 62 if (me_cl) {
61 i++, me_cl->client_id, 63 pos += scnprintf(buf + pos, bufsz - pos,
62 me_cl->props.fixed_address, 64 "%2d|%2d|%3d|%pUl|%3d|%7d|%2d|%4d|\n",
63 &me_cl->props.protocol_name, 65 i++, me_cl->client_id,
64 me_cl->props.max_number_of_connections, 66 me_cl->props.fixed_address,
65 me_cl->props.max_msg_length, 67 &me_cl->props.protocol_name,
66 me_cl->props.single_recv_buf); 68 me_cl->props.max_number_of_connections,
69 me_cl->props.max_msg_length,
70 me_cl->props.single_recv_buf,
71 atomic_read(&me_cl->refcnt.refcount));
72 }
73
74 mei_me_cl_put(me_cl);
67 } 75 }
68out: 76out:
69 mutex_unlock(&dev->device_lock); 77 mutex_unlock(&dev->device_lock);
diff --git a/drivers/misc/mei/hbm.c b/drivers/misc/mei/hbm.c
index 239d7f5d6a92..c8412d41e4f1 100644
--- a/drivers/misc/mei/hbm.c
+++ b/drivers/misc/mei/hbm.c
@@ -105,21 +105,6 @@ void mei_hbm_idle(struct mei_device *dev)
105} 105}
106 106
107/** 107/**
108 * mei_me_cl_remove_all - remove all me clients
109 *
110 * @dev: the device structure
111 */
112static void mei_me_cl_remove_all(struct mei_device *dev)
113{
114 struct mei_me_client *me_cl, *next;
115
116 list_for_each_entry_safe(me_cl, next, &dev->me_clients, list) {
117 list_del(&me_cl->list);
118 kfree(me_cl);
119 }
120}
121
122/**
123 * mei_hbm_reset - reset hbm counters and book keeping data structurs 108 * mei_hbm_reset - reset hbm counters and book keeping data structurs
124 * 109 *
125 * @dev: the device structure 110 * @dev: the device structure
@@ -128,7 +113,7 @@ void mei_hbm_reset(struct mei_device *dev)
128{ 113{
129 dev->me_client_index = 0; 114 dev->me_client_index = 0;
130 115
131 mei_me_cl_remove_all(dev); 116 mei_me_cl_rm_all(dev);
132 117
133 mei_hbm_idle(dev); 118 mei_hbm_idle(dev);
134} 119}
@@ -339,11 +324,16 @@ static int mei_hbm_me_cl_add(struct mei_device *dev,
339 struct hbm_props_response *res) 324 struct hbm_props_response *res)
340{ 325{
341 struct mei_me_client *me_cl; 326 struct mei_me_client *me_cl;
327 const uuid_le *uuid = &res->client_properties.protocol_name;
328
329 mei_me_cl_rm_by_uuid(dev, uuid);
342 330
343 me_cl = kzalloc(sizeof(struct mei_me_client), GFP_KERNEL); 331 me_cl = kzalloc(sizeof(struct mei_me_client), GFP_KERNEL);
344 if (!me_cl) 332 if (!me_cl)
345 return -ENOMEM; 333 return -ENOMEM;
346 334
335 mei_me_cl_init(me_cl);
336
347 me_cl->props = res->client_properties; 337 me_cl->props = res->client_properties;
348 me_cl->client_id = res->me_addr; 338 me_cl->client_id = res->me_addr;
349 me_cl->mei_flow_ctrl_creds = 0; 339 me_cl->mei_flow_ctrl_creds = 0;
@@ -484,6 +474,7 @@ static int mei_hbm_add_single_flow_creds(struct mei_device *dev,
484 struct hbm_flow_control *flow) 474 struct hbm_flow_control *flow)
485{ 475{
486 struct mei_me_client *me_cl; 476 struct mei_me_client *me_cl;
477 int rets;
487 478
488 me_cl = mei_me_cl_by_id(dev, flow->me_addr); 479 me_cl = mei_me_cl_by_id(dev, flow->me_addr);
489 if (!me_cl) { 480 if (!me_cl) {
@@ -492,14 +483,19 @@ static int mei_hbm_add_single_flow_creds(struct mei_device *dev,
492 return -ENOENT; 483 return -ENOENT;
493 } 484 }
494 485
495 if (WARN_ON(me_cl->props.single_recv_buf == 0)) 486 if (WARN_ON(me_cl->props.single_recv_buf == 0)) {
496 return -EINVAL; 487 rets = -EINVAL;
488 goto out;
489 }
497 490
498 me_cl->mei_flow_ctrl_creds++; 491 me_cl->mei_flow_ctrl_creds++;
499 dev_dbg(dev->dev, "recv flow ctrl msg ME %d (single) creds = %d.\n", 492 dev_dbg(dev->dev, "recv flow ctrl msg ME %d (single) creds = %d.\n",
500 flow->me_addr, me_cl->mei_flow_ctrl_creds); 493 flow->me_addr, me_cl->mei_flow_ctrl_creds);
501 494
502 return 0; 495 rets = 0;
496out:
497 mei_me_cl_put(me_cl);
498 return rets;
503} 499}
504 500
505/** 501/**
diff --git a/drivers/misc/mei/hw-me.c b/drivers/misc/mei/hw-me.c
index 06ff0a2ec960..f8fd503dfbd6 100644
--- a/drivers/misc/mei/hw-me.c
+++ b/drivers/misc/mei/hw-me.c
@@ -242,7 +242,7 @@ static int mei_me_hw_reset(struct mei_device *dev, bool intr_enable)
242 if ((hcsr & H_RST) == H_RST) { 242 if ((hcsr & H_RST) == H_RST) {
243 dev_warn(dev->dev, "H_RST is set = 0x%08X", hcsr); 243 dev_warn(dev->dev, "H_RST is set = 0x%08X", hcsr);
244 hcsr &= ~H_RST; 244 hcsr &= ~H_RST;
245 mei_me_reg_write(hw, H_CSR, hcsr); 245 mei_hcsr_set(hw, hcsr);
246 hcsr = mei_hcsr_read(hw); 246 hcsr = mei_hcsr_read(hw);
247 } 247 }
248 248
@@ -335,6 +335,7 @@ static int mei_me_hw_ready_wait(struct mei_device *dev)
335 return -ETIME; 335 return -ETIME;
336 } 336 }
337 337
338 mei_me_hw_reset_release(dev);
338 dev->recvd_hw_ready = false; 339 dev->recvd_hw_ready = false;
339 return 0; 340 return 0;
340} 341}
@@ -731,9 +732,7 @@ irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id)
731 /* check if we need to start the dev */ 732 /* check if we need to start the dev */
732 if (!mei_host_is_ready(dev)) { 733 if (!mei_host_is_ready(dev)) {
733 if (mei_hw_is_ready(dev)) { 734 if (mei_hw_is_ready(dev)) {
734 mei_me_hw_reset_release(dev);
735 dev_dbg(dev->dev, "we need to start the dev.\n"); 735 dev_dbg(dev->dev, "we need to start the dev.\n");
736
737 dev->recvd_hw_ready = true; 736 dev->recvd_hw_ready = true;
738 wake_up(&dev->wait_hw_ready); 737 wake_up(&dev->wait_hw_ready);
739 } else { 738 } else {
diff --git a/drivers/misc/mei/main.c b/drivers/misc/mei/main.c
index ae56ba6ca0e3..3c019c0e60eb 100644
--- a/drivers/misc/mei/main.c
+++ b/drivers/misc/mei/main.c
@@ -303,7 +303,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
303 size_t length, loff_t *offset) 303 size_t length, loff_t *offset)
304{ 304{
305 struct mei_cl *cl = file->private_data; 305 struct mei_cl *cl = file->private_data;
306 struct mei_me_client *me_cl; 306 struct mei_me_client *me_cl = NULL;
307 struct mei_cl_cb *write_cb = NULL; 307 struct mei_cl_cb *write_cb = NULL;
308 struct mei_device *dev; 308 struct mei_device *dev;
309 unsigned long timeout = 0; 309 unsigned long timeout = 0;
@@ -399,12 +399,14 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
399 "amthif write failed with status = %d\n", rets); 399 "amthif write failed with status = %d\n", rets);
400 goto out; 400 goto out;
401 } 401 }
402 mei_me_cl_put(me_cl);
402 mutex_unlock(&dev->device_lock); 403 mutex_unlock(&dev->device_lock);
403 return length; 404 return length;
404 } 405 }
405 406
406 rets = mei_cl_write(cl, write_cb, false); 407 rets = mei_cl_write(cl, write_cb, false);
407out: 408out:
409 mei_me_cl_put(me_cl);
408 mutex_unlock(&dev->device_lock); 410 mutex_unlock(&dev->device_lock);
409 if (rets < 0) 411 if (rets < 0)
410 mei_io_cb_free(write_cb); 412 mei_io_cb_free(write_cb);
@@ -433,24 +435,19 @@ static int mei_ioctl_connect_client(struct file *file,
433 cl = file->private_data; 435 cl = file->private_data;
434 dev = cl->dev; 436 dev = cl->dev;
435 437
436 if (dev->dev_state != MEI_DEV_ENABLED) { 438 if (dev->dev_state != MEI_DEV_ENABLED)
437 rets = -ENODEV; 439 return -ENODEV;
438 goto end;
439 }
440 440
441 if (cl->state != MEI_FILE_INITIALIZING && 441 if (cl->state != MEI_FILE_INITIALIZING &&
442 cl->state != MEI_FILE_DISCONNECTED) { 442 cl->state != MEI_FILE_DISCONNECTED)
443 rets = -EBUSY; 443 return -EBUSY;
444 goto end;
445 }
446 444
447 /* find ME client we're trying to connect to */ 445 /* find ME client we're trying to connect to */
448 me_cl = mei_me_cl_by_uuid(dev, &data->in_client_uuid); 446 me_cl = mei_me_cl_by_uuid(dev, &data->in_client_uuid);
449 if (!me_cl || me_cl->props.fixed_address) { 447 if (!me_cl || me_cl->props.fixed_address) {
450 dev_dbg(dev->dev, "Cannot connect to FW Client UUID = %pUl\n", 448 dev_dbg(dev->dev, "Cannot connect to FW Client UUID = %pUl\n",
451 &data->in_client_uuid); 449 &data->in_client_uuid);
452 rets = -ENOTTY; 450 return -ENOTTY;
453 goto end;
454 } 451 }
455 452
456 cl->me_client_id = me_cl->client_id; 453 cl->me_client_id = me_cl->client_id;
@@ -487,17 +484,16 @@ static int mei_ioctl_connect_client(struct file *file,
487 goto end; 484 goto end;
488 } 485 }
489 486
490
491 /* prepare the output buffer */ 487 /* prepare the output buffer */
492 client = &data->out_client_properties; 488 client = &data->out_client_properties;
493 client->max_msg_length = me_cl->props.max_msg_length; 489 client->max_msg_length = me_cl->props.max_msg_length;
494 client->protocol_version = me_cl->props.protocol_version; 490 client->protocol_version = me_cl->props.protocol_version;
495 dev_dbg(dev->dev, "Can connect?\n"); 491 dev_dbg(dev->dev, "Can connect?\n");
496 492
497
498 rets = mei_cl_connect(cl, file); 493 rets = mei_cl_connect(cl, file);
499 494
500end: 495end:
496 mei_me_cl_put(me_cl);
501 return rets; 497 return rets;
502} 498}
503 499
diff --git a/drivers/misc/mei/mei_dev.h b/drivers/misc/mei/mei_dev.h
index 3dad74a8d496..6c6ce9381535 100644
--- a/drivers/misc/mei/mei_dev.h
+++ b/drivers/misc/mei/mei_dev.h
@@ -172,12 +172,14 @@ struct mei_fw_status {
172 * struct mei_me_client - representation of me (fw) client 172 * struct mei_me_client - representation of me (fw) client
173 * 173 *
174 * @list: link in me client list 174 * @list: link in me client list
175 * @refcnt: struct reference count
175 * @props: client properties 176 * @props: client properties
176 * @client_id: me client id 177 * @client_id: me client id
177 * @mei_flow_ctrl_creds: flow control credits 178 * @mei_flow_ctrl_creds: flow control credits
178 */ 179 */
179struct mei_me_client { 180struct mei_me_client {
180 struct list_head list; 181 struct list_head list;
182 struct kref refcnt;
181 struct mei_client_properties props; 183 struct mei_client_properties props;
182 u8 client_id; 184 u8 client_id;
183 u8 mei_flow_ctrl_creds; 185 u8 mei_flow_ctrl_creds;
@@ -345,9 +347,9 @@ struct mei_cl_device *mei_cl_add_device(struct mei_device *dev,
345 struct mei_cl_ops *ops); 347 struct mei_cl_ops *ops);
346void mei_cl_remove_device(struct mei_cl_device *device); 348void mei_cl_remove_device(struct mei_cl_device *device);
347 349
348int __mei_cl_async_send(struct mei_cl *cl, u8 *buf, size_t length); 350ssize_t __mei_cl_async_send(struct mei_cl *cl, u8 *buf, size_t length);
349int __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length); 351ssize_t __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length);
350int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length); 352ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length);
351void mei_cl_bus_rx_event(struct mei_cl *cl); 353void mei_cl_bus_rx_event(struct mei_cl *cl);
352void mei_cl_bus_remove_devices(struct mei_device *dev); 354void mei_cl_bus_remove_devices(struct mei_device *dev);
353int mei_cl_bus_init(void); 355int mei_cl_bus_init(void);
diff --git a/drivers/misc/mei/nfc.c b/drivers/misc/mei/nfc.c
index 60ca9240368e..bb61a119b8bb 100644
--- a/drivers/misc/mei/nfc.c
+++ b/drivers/misc/mei/nfc.c
@@ -521,6 +521,7 @@ int mei_nfc_host_init(struct mei_device *dev)
521 521
522 cl_info->me_client_id = me_cl->client_id; 522 cl_info->me_client_id = me_cl->client_id;
523 cl_info->cl_uuid = me_cl->props.protocol_name; 523 cl_info->cl_uuid = me_cl->props.protocol_name;
524 mei_me_cl_put(me_cl);
524 525
525 ret = mei_cl_link(cl_info, MEI_HOST_CLIENT_ID_ANY); 526 ret = mei_cl_link(cl_info, MEI_HOST_CLIENT_ID_ANY);
526 if (ret) 527 if (ret)
@@ -539,6 +540,7 @@ int mei_nfc_host_init(struct mei_device *dev)
539 540
540 cl->me_client_id = me_cl->client_id; 541 cl->me_client_id = me_cl->client_id;
541 cl->cl_uuid = me_cl->props.protocol_name; 542 cl->cl_uuid = me_cl->props.protocol_name;
543 mei_me_cl_put(me_cl);
542 544
543 ret = mei_cl_link(cl, MEI_HOST_CLIENT_ID_ANY); 545 ret = mei_cl_link(cl, MEI_HOST_CLIENT_ID_ANY);
544 if (ret) 546 if (ret)
diff --git a/drivers/misc/mei/wd.c b/drivers/misc/mei/wd.c
index b1d892cea94d..475f1dea45bf 100644
--- a/drivers/misc/mei/wd.c
+++ b/drivers/misc/mei/wd.c
@@ -76,6 +76,7 @@ int mei_wd_host_init(struct mei_device *dev)
76 76
77 cl->me_client_id = me_cl->client_id; 77 cl->me_client_id = me_cl->client_id;
78 cl->cl_uuid = me_cl->props.protocol_name; 78 cl->cl_uuid = me_cl->props.protocol_name;
79 mei_me_cl_put(me_cl);
79 80
80 ret = mei_cl_link(cl, MEI_WD_HOST_CLIENT_ID); 81 ret = mei_cl_link(cl, MEI_WD_HOST_CLIENT_ID);
81 82
diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
index 54be83d3efdd..c8c6a363069c 100644
--- a/drivers/misc/ti-st/st_core.c
+++ b/drivers/misc/ti-st/st_core.c
@@ -343,12 +343,26 @@ void st_int_recv(void *disc_data,
343 /* Unknow packet? */ 343 /* Unknow packet? */
344 default: 344 default:
345 type = *ptr; 345 type = *ptr;
346 if (st_gdata->list[type] == NULL) {
347 pr_err("chip/interface misbehavior dropping"
348 " frame starting with 0x%02x", type);
349 goto done;
350 346
347 /* Default case means non-HCILL packets,
348 * possibilities are packets for:
349 * (a) valid protocol - Supported Protocols within
350 * the ST_MAX_CHANNELS.
351 * (b) registered protocol - Checked by
352 * "st_gdata->list[type] == NULL)" are supported
353 * protocols only.
354 * Rules out any invalid protocol and
355 * unregistered protocols with channel ID < 16.
356 */
357
358 if ((type >= ST_MAX_CHANNELS) ||
359 (st_gdata->list[type] == NULL)) {
360 pr_err("chip/interface misbehavior: "
361 "dropping frame starting "
362 "with 0x%02x\n", type);
363 goto done;
351 } 364 }
365
352 st_gdata->rx_skb = alloc_skb( 366 st_gdata->rx_skb = alloc_skb(
353 st_gdata->list[type]->max_frame_size, 367 st_gdata->list[type]->max_frame_size,
354 GFP_ATOMIC); 368 GFP_ATOMIC);
@@ -893,5 +907,3 @@ void st_core_exit(struct st_data_s *st_gdata)
893 kfree(st_gdata); 907 kfree(st_gdata);
894 } 908 }
895} 909}
896
897
diff --git a/drivers/misc/ti-st/st_kim.c b/drivers/misc/ti-st/st_kim.c
index e4b7ee4f57b8..18e7a03985d4 100644
--- a/drivers/misc/ti-st/st_kim.c
+++ b/drivers/misc/ti-st/st_kim.c
@@ -36,7 +36,8 @@
36#include <linux/skbuff.h> 36#include <linux/skbuff.h>
37#include <linux/ti_wilink_st.h> 37#include <linux/ti_wilink_st.h>
38#include <linux/module.h> 38#include <linux/module.h>
39 39#include <linux/of.h>
40#include <linux/of_device.h>
40 41
41#define MAX_ST_DEVICES 3 /* Imagine 1 on each UART for now */ 42#define MAX_ST_DEVICES 3 /* Imagine 1 on each UART for now */
42static struct platform_device *st_kim_devices[MAX_ST_DEVICES]; 43static struct platform_device *st_kim_devices[MAX_ST_DEVICES];
@@ -44,6 +45,9 @@ static struct platform_device *st_kim_devices[MAX_ST_DEVICES];
44/**********************************************************************/ 45/**********************************************************************/
45/* internal functions */ 46/* internal functions */
46 47
48struct ti_st_plat_data *dt_pdata;
49static struct ti_st_plat_data *get_platform_data(struct device *dev);
50
47/** 51/**
48 * st_get_plat_device - 52 * st_get_plat_device -
49 * function which returns the reference to the platform device 53 * function which returns the reference to the platform device
@@ -215,6 +219,7 @@ static long read_local_version(struct kim_data_s *kim_gdata, char *bts_scr_name)
215{ 219{
216 unsigned short version = 0, chip = 0, min_ver = 0, maj_ver = 0; 220 unsigned short version = 0, chip = 0, min_ver = 0, maj_ver = 0;
217 const char read_ver_cmd[] = { 0x01, 0x01, 0x10, 0x00 }; 221 const char read_ver_cmd[] = { 0x01, 0x01, 0x10, 0x00 };
222 long timeout;
218 223
219 pr_debug("%s", __func__); 224 pr_debug("%s", __func__);
220 225
@@ -224,10 +229,11 @@ static long read_local_version(struct kim_data_s *kim_gdata, char *bts_scr_name)
224 return -EIO; 229 return -EIO;
225 } 230 }
226 231
227 if (!wait_for_completion_interruptible_timeout( 232 timeout = wait_for_completion_interruptible_timeout(
228 &kim_gdata->kim_rcvd, msecs_to_jiffies(CMD_RESP_TIME))) { 233 &kim_gdata->kim_rcvd, msecs_to_jiffies(CMD_RESP_TIME));
229 pr_err(" waiting for ver info- timed out "); 234 if (timeout <= 0) {
230 return -ETIMEDOUT; 235 pr_err(" waiting for ver info- timed out or received signal");
236 return timeout ? -ERESTARTSYS : -ETIMEDOUT;
231 } 237 }
232 reinit_completion(&kim_gdata->kim_rcvd); 238 reinit_completion(&kim_gdata->kim_rcvd);
233 /* the positions 12 & 13 in the response buffer provide with the 239 /* the positions 12 & 13 in the response buffer provide with the
@@ -391,13 +397,14 @@ static long download_firmware(struct kim_data_s *kim_gdata)
391 break; 397 break;
392 case ACTION_WAIT_EVENT: /* wait */ 398 case ACTION_WAIT_EVENT: /* wait */
393 pr_debug("W"); 399 pr_debug("W");
394 if (!wait_for_completion_interruptible_timeout( 400 err = wait_for_completion_interruptible_timeout(
395 &kim_gdata->kim_rcvd, 401 &kim_gdata->kim_rcvd,
396 msecs_to_jiffies(CMD_RESP_TIME))) { 402 msecs_to_jiffies(CMD_RESP_TIME));
397 pr_err("response timeout during fw download "); 403 if (err <= 0) {
404 pr_err("response timeout/signaled during fw download ");
398 /* timed out */ 405 /* timed out */
399 release_firmware(kim_gdata->fw_entry); 406 release_firmware(kim_gdata->fw_entry);
400 return -ETIMEDOUT; 407 return err ? -ERESTARTSYS : -ETIMEDOUT;
401 } 408 }
402 reinit_completion(&kim_gdata->kim_rcvd); 409 reinit_completion(&kim_gdata->kim_rcvd);
403 break; 410 break;
@@ -462,7 +469,12 @@ long st_kim_start(void *kim_data)
462 struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data; 469 struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data;
463 470
464 pr_info(" %s", __func__); 471 pr_info(" %s", __func__);
465 pdata = kim_gdata->kim_pdev->dev.platform_data; 472 if (kim_gdata->kim_pdev->dev.of_node) {
473 pr_debug("use device tree data");
474 pdata = dt_pdata;
475 } else {
476 pdata = kim_gdata->kim_pdev->dev.platform_data;
477 }
466 478
467 do { 479 do {
468 /* platform specific enabling code here */ 480 /* platform specific enabling code here */
@@ -522,12 +534,18 @@ long st_kim_stop(void *kim_data)
522{ 534{
523 long err = 0; 535 long err = 0;
524 struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data; 536 struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data;
525 struct ti_st_plat_data *pdata = 537 struct ti_st_plat_data *pdata;
526 kim_gdata->kim_pdev->dev.platform_data;
527 struct tty_struct *tty = kim_gdata->core_data->tty; 538 struct tty_struct *tty = kim_gdata->core_data->tty;
528 539
529 reinit_completion(&kim_gdata->ldisc_installed); 540 reinit_completion(&kim_gdata->ldisc_installed);
530 541
542 if (kim_gdata->kim_pdev->dev.of_node) {
543 pr_debug("use device tree data");
544 pdata = dt_pdata;
545 } else
546 pdata = kim_gdata->kim_pdev->dev.platform_data;
547
548
531 if (tty) { /* can be called before ldisc is installed */ 549 if (tty) { /* can be called before ldisc is installed */
532 /* Flush any pending characters in the driver and discipline. */ 550 /* Flush any pending characters in the driver and discipline. */
533 tty_ldisc_flush(tty); 551 tty_ldisc_flush(tty);
@@ -620,7 +638,7 @@ static ssize_t show_baud_rate(struct device *dev,
620 struct device_attribute *attr, char *buf) 638 struct device_attribute *attr, char *buf)
621{ 639{
622 struct kim_data_s *kim_data = dev_get_drvdata(dev); 640 struct kim_data_s *kim_data = dev_get_drvdata(dev);
623 return sprintf(buf, "%ld\n", kim_data->baud_rate); 641 return sprintf(buf, "%d\n", kim_data->baud_rate);
624} 642}
625 643
626static ssize_t show_flow_cntrl(struct device *dev, 644static ssize_t show_flow_cntrl(struct device *dev,
@@ -676,12 +694,16 @@ void st_kim_ref(struct st_data_s **core_data, int id)
676 struct kim_data_s *kim_gdata; 694 struct kim_data_s *kim_gdata;
677 /* get kim_gdata reference from platform device */ 695 /* get kim_gdata reference from platform device */
678 pdev = st_get_plat_device(id); 696 pdev = st_get_plat_device(id);
679 if (!pdev) { 697 if (!pdev)
680 *core_data = NULL; 698 goto err;
681 return;
682 }
683 kim_gdata = platform_get_drvdata(pdev); 699 kim_gdata = platform_get_drvdata(pdev);
700 if (!kim_gdata)
701 goto err;
702
684 *core_data = kim_gdata->core_data; 703 *core_data = kim_gdata->core_data;
704 return;
705err:
706 *core_data = NULL;
685} 707}
686 708
687static int kim_version_open(struct inode *i, struct file *f) 709static int kim_version_open(struct inode *i, struct file *f)
@@ -715,13 +737,53 @@ static const struct file_operations list_debugfs_fops = {
715 * board-*.c file 737 * board-*.c file
716 */ 738 */
717 739
740static const struct of_device_id kim_of_match[] = {
741{
742 .compatible = "kim",
743 },
744 {}
745};
746MODULE_DEVICE_TABLE(of, kim_of_match);
747
748static struct ti_st_plat_data *get_platform_data(struct device *dev)
749{
750 struct device_node *np = dev->of_node;
751 const u32 *dt_property;
752 int len;
753
754 dt_pdata = kzalloc(sizeof(*dt_pdata), GFP_KERNEL);
755
756 if (!dt_pdata)
757 pr_err("Can't allocate device_tree platform data\n");
758
759 dt_property = of_get_property(np, "dev_name", &len);
760 if (dt_property)
761 memcpy(&dt_pdata->dev_name, dt_property, len);
762 of_property_read_u32(np, "nshutdown_gpio",
763 &dt_pdata->nshutdown_gpio);
764 of_property_read_u32(np, "flow_cntrl", &dt_pdata->flow_cntrl);
765 of_property_read_u32(np, "baud_rate", &dt_pdata->baud_rate);
766
767 return dt_pdata;
768}
769
718static struct dentry *kim_debugfs_dir; 770static struct dentry *kim_debugfs_dir;
719static int kim_probe(struct platform_device *pdev) 771static int kim_probe(struct platform_device *pdev)
720{ 772{
721 struct kim_data_s *kim_gdata; 773 struct kim_data_s *kim_gdata;
722 struct ti_st_plat_data *pdata = pdev->dev.platform_data; 774 struct ti_st_plat_data *pdata;
723 int err; 775 int err;
724 776
777 if (pdev->dev.of_node)
778 pdata = get_platform_data(&pdev->dev);
779 else
780 pdata = pdev->dev.platform_data;
781
782 if (pdata == NULL) {
783 dev_err(&pdev->dev, "Platform Data is missing\n");
784 return -ENXIO;
785 }
786
725 if ((pdev->id != -1) && (pdev->id < MAX_ST_DEVICES)) { 787 if ((pdev->id != -1) && (pdev->id < MAX_ST_DEVICES)) {
726 /* multiple devices could exist */ 788 /* multiple devices could exist */
727 st_kim_devices[pdev->id] = pdev; 789 st_kim_devices[pdev->id] = pdev;
@@ -750,14 +812,14 @@ static int kim_probe(struct platform_device *pdev)
750 kim_gdata->nshutdown = pdata->nshutdown_gpio; 812 kim_gdata->nshutdown = pdata->nshutdown_gpio;
751 err = gpio_request(kim_gdata->nshutdown, "kim"); 813 err = gpio_request(kim_gdata->nshutdown, "kim");
752 if (unlikely(err)) { 814 if (unlikely(err)) {
753 pr_err(" gpio %ld request failed ", kim_gdata->nshutdown); 815 pr_err(" gpio %d request failed ", kim_gdata->nshutdown);
754 return err; 816 return err;
755 } 817 }
756 818
757 /* Configure nShutdown GPIO as output=0 */ 819 /* Configure nShutdown GPIO as output=0 */
758 err = gpio_direction_output(kim_gdata->nshutdown, 0); 820 err = gpio_direction_output(kim_gdata->nshutdown, 0);
759 if (unlikely(err)) { 821 if (unlikely(err)) {
760 pr_err(" unable to configure gpio %ld", kim_gdata->nshutdown); 822 pr_err(" unable to configure gpio %d", kim_gdata->nshutdown);
761 return err; 823 return err;
762 } 824 }
763 /* get reference of pdev for request_firmware 825 /* get reference of pdev for request_firmware
@@ -781,8 +843,7 @@ static int kim_probe(struct platform_device *pdev)
781 kim_debugfs_dir = debugfs_create_dir("ti-st", NULL); 843 kim_debugfs_dir = debugfs_create_dir("ti-st", NULL);
782 if (!kim_debugfs_dir) { 844 if (!kim_debugfs_dir) {
783 pr_err(" debugfs entries creation failed "); 845 pr_err(" debugfs entries creation failed ");
784 err = -EIO; 846 return 0;
785 goto err_debugfs_dir;
786 } 847 }
787 848
788 debugfs_create_file("version", S_IRUGO, kim_debugfs_dir, 849 debugfs_create_file("version", S_IRUGO, kim_debugfs_dir,
@@ -791,9 +852,6 @@ static int kim_probe(struct platform_device *pdev)
791 kim_gdata, &list_debugfs_fops); 852 kim_gdata, &list_debugfs_fops);
792 return 0; 853 return 0;
793 854
794err_debugfs_dir:
795 sysfs_remove_group(&pdev->dev.kobj, &uim_attr_grp);
796
797err_sysfs_group: 855err_sysfs_group:
798 st_core_exit(kim_gdata->core_data); 856 st_core_exit(kim_gdata->core_data);
799 857
@@ -806,9 +864,16 @@ err_core_init:
806static int kim_remove(struct platform_device *pdev) 864static int kim_remove(struct platform_device *pdev)
807{ 865{
808 /* free the GPIOs requested */ 866 /* free the GPIOs requested */
809 struct ti_st_plat_data *pdata = pdev->dev.platform_data; 867 struct ti_st_plat_data *pdata;
810 struct kim_data_s *kim_gdata; 868 struct kim_data_s *kim_gdata;
811 869
870 if (pdev->dev.of_node) {
871 pr_debug("use device tree data");
872 pdata = dt_pdata;
873 } else {
874 pdata = pdev->dev.platform_data;
875 }
876
812 kim_gdata = platform_get_drvdata(pdev); 877 kim_gdata = platform_get_drvdata(pdev);
813 878
814 /* Free the Bluetooth/FM/GPIO 879 /* Free the Bluetooth/FM/GPIO
@@ -826,27 +891,44 @@ static int kim_remove(struct platform_device *pdev)
826 891
827 kfree(kim_gdata); 892 kfree(kim_gdata);
828 kim_gdata = NULL; 893 kim_gdata = NULL;
894 kfree(dt_pdata);
895 dt_pdata = NULL;
896
829 return 0; 897 return 0;
830} 898}
831 899
832static int kim_suspend(struct platform_device *pdev, pm_message_t state) 900static int kim_suspend(struct platform_device *pdev, pm_message_t state)
833{ 901{
834 struct ti_st_plat_data *pdata = pdev->dev.platform_data; 902 struct ti_st_plat_data *pdata;
903
904 if (pdev->dev.of_node) {
905 pr_debug("use device tree data");
906 pdata = dt_pdata;
907 } else {
908 pdata = pdev->dev.platform_data;
909 }
835 910
836 if (pdata->suspend) 911 if (pdata->suspend)
837 return pdata->suspend(pdev, state); 912 return pdata->suspend(pdev, state);
838 913
839 return -EOPNOTSUPP; 914 return 0;
840} 915}
841 916
842static int kim_resume(struct platform_device *pdev) 917static int kim_resume(struct platform_device *pdev)
843{ 918{
844 struct ti_st_plat_data *pdata = pdev->dev.platform_data; 919 struct ti_st_plat_data *pdata;
920
921 if (pdev->dev.of_node) {
922 pr_debug("use device tree data");
923 pdata = dt_pdata;
924 } else {
925 pdata = pdev->dev.platform_data;
926 }
845 927
846 if (pdata->resume) 928 if (pdata->resume)
847 return pdata->resume(pdev); 929 return pdata->resume(pdev);
848 930
849 return -EOPNOTSUPP; 931 return 0;
850} 932}
851 933
852/**********************************************************************/ 934/**********************************************************************/
@@ -858,6 +940,8 @@ static struct platform_driver kim_platform_driver = {
858 .resume = kim_resume, 940 .resume = kim_resume,
859 .driver = { 941 .driver = {
860 .name = "kim", 942 .name = "kim",
943 .owner = THIS_MODULE,
944 .of_match_table = of_match_ptr(kim_of_match),
861 }, 945 },
862}; 946};
863 947
diff --git a/drivers/misc/ti-st/st_ll.c b/drivers/misc/ti-st/st_ll.c
index 93b4d67cc4a3..518e1b7f2f95 100644
--- a/drivers/misc/ti-st/st_ll.c
+++ b/drivers/misc/ti-st/st_ll.c
@@ -26,6 +26,7 @@
26#include <linux/ti_wilink_st.h> 26#include <linux/ti_wilink_st.h>
27 27
28/**********************************************************************/ 28/**********************************************************************/
29
29/* internal functions */ 30/* internal functions */
30static void send_ll_cmd(struct st_data_s *st_data, 31static void send_ll_cmd(struct st_data_s *st_data,
31 unsigned char cmd) 32 unsigned char cmd)
@@ -53,7 +54,13 @@ static void ll_device_want_to_sleep(struct st_data_s *st_data)
53 54
54 /* communicate to platform about chip asleep */ 55 /* communicate to platform about chip asleep */
55 kim_data = st_data->kim_data; 56 kim_data = st_data->kim_data;
56 pdata = kim_data->kim_pdev->dev.platform_data; 57 if (kim_data->kim_pdev->dev.of_node) {
58 pr_debug("use device tree data");
59 pdata = dt_pdata;
60 } else {
61 pdata = kim_data->kim_pdev->dev.platform_data;
62 }
63
57 if (pdata->chip_asleep) 64 if (pdata->chip_asleep)
58 pdata->chip_asleep(NULL); 65 pdata->chip_asleep(NULL);
59} 66}
@@ -86,7 +93,13 @@ static void ll_device_want_to_wakeup(struct st_data_s *st_data)
86 93
87 /* communicate to platform about chip wakeup */ 94 /* communicate to platform about chip wakeup */
88 kim_data = st_data->kim_data; 95 kim_data = st_data->kim_data;
89 pdata = kim_data->kim_pdev->dev.platform_data; 96 if (kim_data->kim_pdev->dev.of_node) {
97 pr_debug("use device tree data");
98 pdata = dt_pdata;
99 } else {
100 pdata = kim_data->kim_pdev->dev.platform_data;
101 }
102
90 if (pdata->chip_awake) 103 if (pdata->chip_awake)
91 pdata->chip_awake(NULL); 104 pdata->chip_awake(NULL);
92} 105}
diff --git a/drivers/misc/vmw_vmci/vmci_driver.c b/drivers/misc/vmw_vmci/vmci_driver.c
index 3dee7ae123e7..032d35cf93ca 100644
--- a/drivers/misc/vmw_vmci/vmci_driver.c
+++ b/drivers/misc/vmw_vmci/vmci_driver.c
@@ -113,5 +113,5 @@ module_exit(vmci_drv_exit);
113 113
114MODULE_AUTHOR("VMware, Inc."); 114MODULE_AUTHOR("VMware, Inc.");
115MODULE_DESCRIPTION("VMware Virtual Machine Communication Interface."); 115MODULE_DESCRIPTION("VMware Virtual Machine Communication Interface.");
116MODULE_VERSION("1.1.0.0-k"); 116MODULE_VERSION("1.1.1.0-k");
117MODULE_LICENSE("GPL v2"); 117MODULE_LICENSE("GPL v2");
diff --git a/drivers/misc/vmw_vmci/vmci_host.c b/drivers/misc/vmw_vmci/vmci_host.c
index 1723a6e4f2e8..66fc9921fc85 100644
--- a/drivers/misc/vmw_vmci/vmci_host.c
+++ b/drivers/misc/vmw_vmci/vmci_host.c
@@ -218,13 +218,12 @@ static int drv_cp_harray_to_user(void __user *user_buf_uva,
218} 218}
219 219
220/* 220/*
221 * Sets up a given context for notify to work. Calls drv_map_bool_ptr() 221 * Sets up a given context for notify to work. Maps the notify
222 * which maps the notify boolean in user VA in kernel space. 222 * boolean in user VA into kernel space.
223 */ 223 */
224static int vmci_host_setup_notify(struct vmci_ctx *context, 224static int vmci_host_setup_notify(struct vmci_ctx *context,
225 unsigned long uva) 225 unsigned long uva)
226{ 226{
227 struct page *page;
228 int retval; 227 int retval;
229 228
230 if (context->notify_page) { 229 if (context->notify_page) {
@@ -243,14 +242,16 @@ static int vmci_host_setup_notify(struct vmci_ctx *context,
243 /* 242 /*
244 * Lock physical page backing a given user VA. 243 * Lock physical page backing a given user VA.
245 */ 244 */
246 retval = get_user_pages_fast(PAGE_ALIGN(uva), 1, 1, &page); 245 retval = get_user_pages_fast(uva, 1, 1, &context->notify_page);
247 if (retval != 1) 246 if (retval != 1) {
247 context->notify_page = NULL;
248 return VMCI_ERROR_GENERIC; 248 return VMCI_ERROR_GENERIC;
249 }
249 250
250 /* 251 /*
251 * Map the locked page and set up notify pointer. 252 * Map the locked page and set up notify pointer.
252 */ 253 */
253 context->notify = kmap(page) + (uva & (PAGE_SIZE - 1)); 254 context->notify = kmap(context->notify_page) + (uva & (PAGE_SIZE - 1));
254 vmci_ctx_check_signal_notify(context); 255 vmci_ctx_check_signal_notify(context);
255 256
256 return VMCI_SUCCESS; 257 return VMCI_SUCCESS;