aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd/cros_ec_spi.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-08-07 20:17:39 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-08-07 20:17:39 -0400
commit54c72d5987ff9f3cf59529d5d4f5cf19eae3f695 (patch)
tree3fee972d54926627895aa07684ddb2e2388e4614 /drivers/mfd/cros_ec_spi.c
parent66bb0aa077978dbb76e6283531eb3cc7a878de38 (diff)
parent7caa79917ad4c1f91366b11f18e48623554aaa52 (diff)
Merge tag 'mfd-for-linus-3.17' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd
Pull MFD update from Lee Jones: "Changes to existing drivers: - checkpatch fixes throughout the subsystem - use Regmap to handle IRQs in max77686, extcon-max77693 and mc13xxx-core - use DMA in rtsx_pcr - restrict building on unsupported architectures on timberdale, cs5535 - SPI hardening in cros_ec_spi - more robust error handing in asic3, cros_ec, ab8500-debugfs, max77686 and pcf50633-core - reorder PM runtime and regulator handing during shutdown in arizona - enable wakeup in cros_ec_spi - unused variable/code clean-up in pm8921-core, cros_ec, htc-i2cpld, tps65912-spi, wm5110-tables and ab8500-debugfs - add regulator handing into suspend() in sec-core - remove pointless wrapper functions in extcon-max77693 and i2c-cros-ec-tunnel - use cross-architecture friendly data sizes in stmpe-i2c, arizona, max77686 and tps65910 - devicetree documentation updates throughout - provide power management support in max77686 - few OF clean-ups in max77686 - use manged resources in tps6105x New drivers/supported devices: - add support for s2mpu02 to sec-core - add support for Allwinner A32 to sun6i-prcm - add support for Maxim 77802 in max77686 - add support for DA9063 AD in da9063 - new driver for Intel PMICs (generic) and specifically Crystal Cove (Re-)moved drivers == - move out keyboard functionality cros_ec ==> input/keyboard/cros_ec_keyb" * tag 'mfd-for-linus-3.17' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd: (101 commits) MAINTAINERS: Update MFD repo location mfd: omap-usb-host: Fix improper mask use. mfd: arizona: Only free the CTRLIF_ERR IRQ if we requested it mfd: arizona: Add missing handling for ISRC3 under/overclocked mfd: wm5110: Add new interrupt register definitions mfd: arizona: Rename thermal shutdown interrupt mfd: wm5110: Add in the output done interrupts mfd: wm5110: Remove non-existant interrupts mfd: tps65912-spi: Remove unused variable mfd: htc-i2cpld: Remove unused code mfd: da9063: Add support for AD silicon variant mfd: arizona: Map MICVDD from extcon device to the Arizona core mfd: arizona: Add MICVDD to mapped regulators for wm8997 mfd: max77686: Ensure device type IDs are architecture agnostic mfd: max77686: Add Maxim 77802 PMIC support mfd: tps6105x: Use managed resources when allocating memory mfd: wm8997-tables: Suppress 'line over 80 chars' warnings mfd: kempld-core: Correct a variety of checkpatch warnings mfd: ipaq-micro: Fix coding style errors/warnings reported by checkpatch mfd: si476x-cmd: Remedy checkpatch style complains ...
Diffstat (limited to 'drivers/mfd/cros_ec_spi.c')
-rw-r--r--drivers/mfd/cros_ec_spi.c56
1 files changed, 26 insertions, 30 deletions
diff --git a/drivers/mfd/cros_ec_spi.c b/drivers/mfd/cros_ec_spi.c
index 8c1c7cc373f8..588c700af39c 100644
--- a/drivers/mfd/cros_ec_spi.c
+++ b/drivers/mfd/cros_ec_spi.c
@@ -73,7 +73,7 @@
73 * if no record 73 * if no record
74 * @end_of_msg_delay: used to set the delay_usecs on the spi_transfer that 74 * @end_of_msg_delay: used to set the delay_usecs on the spi_transfer that
75 * is sent when we want to turn off CS at the end of a transaction. 75 * is sent when we want to turn off CS at the end of a transaction.
76 * @lock: mutex to ensure only one user of cros_ec_command_spi_xfer at a time 76 * @lock: mutex to ensure only one user of cros_ec_cmd_xfer_spi at a time
77 */ 77 */
78struct cros_ec_spi { 78struct cros_ec_spi {
79 struct spi_device *spi; 79 struct spi_device *spi;
@@ -210,13 +210,13 @@ static int cros_ec_spi_receive_response(struct cros_ec_device *ec_dev,
210} 210}
211 211
212/** 212/**
213 * cros_ec_command_spi_xfer - Transfer a message over SPI and receive the reply 213 * cros_ec_cmd_xfer_spi - Transfer a message over SPI and receive the reply
214 * 214 *
215 * @ec_dev: ChromeOS EC device 215 * @ec_dev: ChromeOS EC device
216 * @ec_msg: Message to transfer 216 * @ec_msg: Message to transfer
217 */ 217 */
218static int cros_ec_command_spi_xfer(struct cros_ec_device *ec_dev, 218static int cros_ec_cmd_xfer_spi(struct cros_ec_device *ec_dev,
219 struct cros_ec_msg *ec_msg) 219 struct cros_ec_command *ec_msg)
220{ 220{
221 struct cros_ec_spi *ec_spi = ec_dev->priv; 221 struct cros_ec_spi *ec_spi = ec_dev->priv;
222 struct spi_transfer trans; 222 struct spi_transfer trans;
@@ -258,23 +258,19 @@ static int cros_ec_command_spi_xfer(struct cros_ec_device *ec_dev,
258 /* Get the response */ 258 /* Get the response */
259 if (!ret) { 259 if (!ret) {
260 ret = cros_ec_spi_receive_response(ec_dev, 260 ret = cros_ec_spi_receive_response(ec_dev,
261 ec_msg->in_len + EC_MSG_TX_PROTO_BYTES); 261 ec_msg->insize + EC_MSG_TX_PROTO_BYTES);
262 } else { 262 } else {
263 dev_err(ec_dev->dev, "spi transfer failed: %d\n", ret); 263 dev_err(ec_dev->dev, "spi transfer failed: %d\n", ret);
264 } 264 }
265 265
266 /* turn off CS */ 266 /*
267 * Turn off CS, possibly adding a delay to ensure the rising edge
268 * doesn't come too soon after the end of the data.
269 */
267 spi_message_init(&msg); 270 spi_message_init(&msg);
268 271 memset(&trans, 0, sizeof(trans));
269 if (ec_spi->end_of_msg_delay) { 272 trans.delay_usecs = ec_spi->end_of_msg_delay;
270 /* 273 spi_message_add_tail(&trans, &msg);
271 * Add delay for last transaction, to ensure the rising edge
272 * doesn't come too soon after the end of the data.
273 */
274 memset(&trans, 0, sizeof(trans));
275 trans.delay_usecs = ec_spi->end_of_msg_delay;
276 spi_message_add_tail(&trans, &msg);
277 }
278 274
279 final_ret = spi_sync(ec_spi->spi, &msg); 275 final_ret = spi_sync(ec_spi->spi, &msg);
280 ec_spi->last_transfer_ns = ktime_get_ns(); 276 ec_spi->last_transfer_ns = ktime_get_ns();
@@ -285,20 +281,19 @@ static int cros_ec_command_spi_xfer(struct cros_ec_device *ec_dev,
285 goto exit; 281 goto exit;
286 } 282 }
287 283
288 /* check response error code */
289 ptr = ec_dev->din; 284 ptr = ec_dev->din;
290 if (ptr[0]) { 285
291 dev_warn(ec_dev->dev, "command 0x%02x returned an error %d\n", 286 /* check response error code */
292 ec_msg->cmd, ptr[0]); 287 ec_msg->result = ptr[0];
293 debug_packet(ec_dev->dev, "in_err", ptr, len); 288 ret = cros_ec_check_result(ec_dev, ec_msg);
294 ret = -EINVAL; 289 if (ret)
295 goto exit; 290 goto exit;
296 } 291
297 len = ptr[1]; 292 len = ptr[1];
298 sum = ptr[0] + ptr[1]; 293 sum = ptr[0] + ptr[1];
299 if (len > ec_msg->in_len) { 294 if (len > ec_msg->insize) {
300 dev_err(ec_dev->dev, "packet too long (%d bytes, expected %d)", 295 dev_err(ec_dev->dev, "packet too long (%d bytes, expected %d)",
301 len, ec_msg->in_len); 296 len, ec_msg->insize);
302 ret = -ENOSPC; 297 ret = -ENOSPC;
303 goto exit; 298 goto exit;
304 } 299 }
@@ -306,8 +301,8 @@ static int cros_ec_command_spi_xfer(struct cros_ec_device *ec_dev,
306 /* copy response packet payload and compute checksum */ 301 /* copy response packet payload and compute checksum */
307 for (i = 0; i < len; i++) { 302 for (i = 0; i < len; i++) {
308 sum += ptr[i + 2]; 303 sum += ptr[i + 2];
309 if (ec_msg->in_len) 304 if (ec_msg->insize)
310 ec_msg->in_buf[i] = ptr[i + 2]; 305 ec_msg->indata[i] = ptr[i + 2];
311 } 306 }
312 sum &= 0xff; 307 sum &= 0xff;
313 308
@@ -321,7 +316,7 @@ static int cros_ec_command_spi_xfer(struct cros_ec_device *ec_dev,
321 goto exit; 316 goto exit;
322 } 317 }
323 318
324 ret = 0; 319 ret = len;
325exit: 320exit:
326 mutex_unlock(&ec_spi->lock); 321 mutex_unlock(&ec_spi->lock);
327 return ret; 322 return ret;
@@ -364,11 +359,10 @@ static int cros_ec_spi_probe(struct spi_device *spi)
364 cros_ec_spi_dt_probe(ec_spi, dev); 359 cros_ec_spi_dt_probe(ec_spi, dev);
365 360
366 spi_set_drvdata(spi, ec_dev); 361 spi_set_drvdata(spi, ec_dev);
367 ec_dev->name = "SPI";
368 ec_dev->dev = dev; 362 ec_dev->dev = dev;
369 ec_dev->priv = ec_spi; 363 ec_dev->priv = ec_spi;
370 ec_dev->irq = spi->irq; 364 ec_dev->irq = spi->irq;
371 ec_dev->command_xfer = cros_ec_command_spi_xfer; 365 ec_dev->cmd_xfer = cros_ec_cmd_xfer_spi;
372 ec_dev->ec_name = ec_spi->spi->modalias; 366 ec_dev->ec_name = ec_spi->spi->modalias;
373 ec_dev->phys_name = dev_name(&ec_spi->spi->dev); 367 ec_dev->phys_name = dev_name(&ec_spi->spi->dev);
374 ec_dev->parent = &ec_spi->spi->dev; 368 ec_dev->parent = &ec_spi->spi->dev;
@@ -381,6 +375,8 @@ static int cros_ec_spi_probe(struct spi_device *spi)
381 return err; 375 return err;
382 } 376 }
383 377
378 device_init_wakeup(&spi->dev, true);
379
384 return 0; 380 return 0;
385} 381}
386 382