88pm80x.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * I2C driver for Marvell 88PM80x
  3. *
  4. * Copyright (C) 2012 Marvell International Ltd.
  5. * Haojian Zhuang <haojian.zhuang@marvell.com>
  6. * Joseph(Yossi) Hanin <yhanin@marvell.com>
  7. * Qiao Zhou <zhouqiao@marvell.com>
  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 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/i2c.h>
  16. #include <linux/mfd/88pm80x.h>
  17. #include <linux/slab.h>
  18. #include <linux/uaccess.h>
  19. #include <linux/err.h>
  20. const struct regmap_config pm80x_regmap_config = {
  21. .reg_bits = 8,
  22. .val_bits = 8,
  23. };
  24. int __devinit pm80x_init(struct i2c_client *client,
  25. const struct i2c_device_id *id)
  26. {
  27. struct pm80x_chip *chip;
  28. struct regmap *map;
  29. int ret = 0;
  30. chip =
  31. devm_kzalloc(&client->dev, sizeof(struct pm80x_chip), GFP_KERNEL);
  32. if (!chip)
  33. return -ENOMEM;
  34. map = devm_regmap_init_i2c(client, &pm80x_regmap_config);
  35. if (IS_ERR(map)) {
  36. ret = PTR_ERR(map);
  37. dev_err(&client->dev, "Failed to allocate register map: %d\n",
  38. ret);
  39. goto err_regmap_init;
  40. }
  41. chip->id = id->driver_data;
  42. if (chip->id < CHIP_PM800 || chip->id > CHIP_PM805) {
  43. ret = -EINVAL;
  44. goto err_chip_id;
  45. }
  46. chip->client = client;
  47. chip->regmap = map;
  48. chip->irq = client->irq;
  49. chip->dev = &client->dev;
  50. dev_set_drvdata(chip->dev, chip);
  51. i2c_set_clientdata(chip->client, chip);
  52. device_init_wakeup(&client->dev, 1);
  53. return 0;
  54. err_chip_id:
  55. regmap_exit(map);
  56. err_regmap_init:
  57. devm_kfree(&client->dev, chip);
  58. return ret;
  59. }
  60. EXPORT_SYMBOL_GPL(pm80x_init);
  61. int __devexit pm80x_deinit(struct i2c_client *client)
  62. {
  63. struct pm80x_chip *chip = i2c_get_clientdata(client);
  64. regmap_exit(chip->regmap);
  65. devm_kfree(&client->dev, chip);
  66. return 0;
  67. }
  68. EXPORT_SYMBOL_GPL(pm80x_deinit);
  69. #ifdef CONFIG_PM_SLEEP
  70. static int pm80x_suspend(struct device *dev)
  71. {
  72. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  73. struct pm80x_chip *chip = i2c_get_clientdata(client);
  74. if (chip && chip->wu_flag)
  75. if (device_may_wakeup(chip->dev))
  76. enable_irq_wake(chip->irq);
  77. return 0;
  78. }
  79. static int pm80x_resume(struct device *dev)
  80. {
  81. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  82. struct pm80x_chip *chip = i2c_get_clientdata(client);
  83. if (chip && chip->wu_flag)
  84. if (device_may_wakeup(chip->dev))
  85. disable_irq_wake(chip->irq);
  86. return 0;
  87. }
  88. #endif
  89. SIMPLE_DEV_PM_OPS(pm80x_pm_ops, pm80x_suspend, pm80x_resume);
  90. EXPORT_SYMBOL_GPL(pm80x_pm_ops);
  91. MODULE_DESCRIPTION("I2C Driver for Marvell 88PM80x");
  92. MODULE_AUTHOR("Qiao Zhou <zhouqiao@marvell.com>");
  93. MODULE_LICENSE("GPL");