olpc-ec.c (560331eaee6c552adc1b8201063ccbfe5009bc12) | olpc-ec.c (231c0c216172a92feb02a99edff6b38b3ebd90a8) |
---|---|
1/* 2 * Generic driver for the OLPC Embedded Controller. 3 * 4 * Author: Andres Salomon <dilinger@queued.net> 5 * 6 * Copyright (C) 2011-2012 One Laptop per Child Foundation. 7 * 8 * Licensed under the GPL v2 or later. 9 */ 10#include <linux/completion.h> 11#include <linux/debugfs.h> 12#include <linux/spinlock.h> 13#include <linux/mutex.h> 14#include <linux/platform_device.h> 15#include <linux/slab.h> 16#include <linux/workqueue.h> 17#include <linux/init.h> 18#include <linux/list.h> | 1/* 2 * Generic driver for the OLPC Embedded Controller. 3 * 4 * Author: Andres Salomon <dilinger@queued.net> 5 * 6 * Copyright (C) 2011-2012 One Laptop per Child Foundation. 7 * 8 * Licensed under the GPL v2 or later. 9 */ 10#include <linux/completion.h> 11#include <linux/debugfs.h> 12#include <linux/spinlock.h> 13#include <linux/mutex.h> 14#include <linux/platform_device.h> 15#include <linux/slab.h> 16#include <linux/workqueue.h> 17#include <linux/init.h> 18#include <linux/list.h> |
19#include <linux/regulator/driver.h> |
|
19#include <linux/olpc-ec.h> 20 21struct ec_cmd_desc { 22 u8 cmd; 23 u8 *inbuf, *outbuf; 24 size_t inlen, outlen; 25 26 int err; --- 4 unchanged lines hidden (view full) --- 31}; 32 33struct olpc_ec_priv { 34 struct olpc_ec_driver *drv; 35 u8 version; 36 struct work_struct worker; 37 struct mutex cmd_lock; 38 | 20#include <linux/olpc-ec.h> 21 22struct ec_cmd_desc { 23 u8 cmd; 24 u8 *inbuf, *outbuf; 25 size_t inlen, outlen; 26 27 int err; --- 4 unchanged lines hidden (view full) --- 32}; 33 34struct olpc_ec_priv { 35 struct olpc_ec_driver *drv; 36 u8 version; 37 struct work_struct worker; 38 struct mutex cmd_lock; 39 |
40 /* DCON regulator */ 41 struct regulator_dev *dcon_rdev; 42 bool dcon_enabled; 43 |
|
39 /* Pending EC commands */ 40 struct list_head cmd_q; 41 spinlock_t cmd_q_lock; 42 43 struct dentry *dbgfs_dir; 44 45 /* 46 * EC event mask to be applied during suspend (defining wakeup --- 294 unchanged lines hidden (view full) --- 341 342static struct dentry *olpc_ec_setup_debugfs(void) 343{ 344 return NULL; 345} 346 347#endif /* CONFIG_DEBUG_FS */ 348 | 44 /* Pending EC commands */ 45 struct list_head cmd_q; 46 spinlock_t cmd_q_lock; 47 48 struct dentry *dbgfs_dir; 49 50 /* 51 * EC event mask to be applied during suspend (defining wakeup --- 294 unchanged lines hidden (view full) --- 346 347static struct dentry *olpc_ec_setup_debugfs(void) 348{ 349 return NULL; 350} 351 352#endif /* CONFIG_DEBUG_FS */ 353 |
354static int olpc_ec_set_dcon_power(struct olpc_ec_priv *ec, bool state) 355{ 356 unsigned char ec_byte = state; 357 int ret; 358 359 if (ec->dcon_enabled == state) 360 return 0; 361 362 ret = olpc_ec_cmd(EC_DCON_POWER_MODE, &ec_byte, 1, NULL, 0); 363 if (ret) 364 return ret; 365 366 ec->dcon_enabled = state; 367 return 0; 368} 369 370static int dcon_regulator_enable(struct regulator_dev *rdev) 371{ 372 struct olpc_ec_priv *ec = rdev_get_drvdata(rdev); 373 374 return olpc_ec_set_dcon_power(ec, true); 375} 376 377static int dcon_regulator_disable(struct regulator_dev *rdev) 378{ 379 struct olpc_ec_priv *ec = rdev_get_drvdata(rdev); 380 381 return olpc_ec_set_dcon_power(ec, false); 382} 383 384static int dcon_regulator_is_enabled(struct regulator_dev *rdev) 385{ 386 struct olpc_ec_priv *ec = rdev_get_drvdata(rdev); 387 388 return ec->dcon_enabled ? 1 : 0; 389} 390 391static struct regulator_ops dcon_regulator_ops = { 392 .enable = dcon_regulator_enable, 393 .disable = dcon_regulator_disable, 394 .is_enabled = dcon_regulator_is_enabled, 395}; 396 397static const struct regulator_desc dcon_desc = { 398 .name = "dcon", 399 .id = 0, 400 .ops = &dcon_regulator_ops, 401 .type = REGULATOR_VOLTAGE, 402 .owner = THIS_MODULE, 403}; 404 |
|
349static int olpc_ec_probe(struct platform_device *pdev) 350{ 351 struct olpc_ec_priv *ec; | 405static int olpc_ec_probe(struct platform_device *pdev) 406{ 407 struct olpc_ec_priv *ec; |
408 struct regulator_config config = { }; |
|
352 int err; 353 354 if (!ec_driver) 355 return -ENODEV; 356 357 ec = kzalloc(sizeof(*ec), GFP_KERNEL); 358 if (!ec) 359 return -ENOMEM; --- 11 unchanged lines hidden (view full) --- 371 /* get the EC revision */ 372 err = olpc_ec_cmd(EC_FIRMWARE_REV, NULL, 0, &ec->version, 1); 373 if (err) { 374 ec_priv = NULL; 375 kfree(ec); 376 return err; 377 } 378 | 409 int err; 410 411 if (!ec_driver) 412 return -ENODEV; 413 414 ec = kzalloc(sizeof(*ec), GFP_KERNEL); 415 if (!ec) 416 return -ENOMEM; --- 11 unchanged lines hidden (view full) --- 428 /* get the EC revision */ 429 err = olpc_ec_cmd(EC_FIRMWARE_REV, NULL, 0, &ec->version, 1); 430 if (err) { 431 ec_priv = NULL; 432 kfree(ec); 433 return err; 434 } 435 |
436 config.dev = pdev->dev.parent; 437 config.driver_data = ec; 438 ec->dcon_enabled = true; 439 ec->dcon_rdev = devm_regulator_register(&pdev->dev, &dcon_desc, 440 &config); 441 if (IS_ERR(ec->dcon_rdev)) { 442 dev_err(&pdev->dev, "failed to register DCON regulator\n"); 443 return PTR_ERR(ec->dcon_rdev); 444 } 445 |
|
379 ec->dbgfs_dir = olpc_ec_setup_debugfs(); 380 381 return err; 382} 383 384static int olpc_ec_suspend(struct device *dev) 385{ 386 struct platform_device *pdev = to_platform_device(dev); --- 40 unchanged lines hidden --- | 446 ec->dbgfs_dir = olpc_ec_setup_debugfs(); 447 448 return err; 449} 450 451static int olpc_ec_suspend(struct device *dev) 452{ 453 struct platform_device *pdev = to_platform_device(dev); --- 40 unchanged lines hidden --- |