tps65023.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* Copyright (c) 2009, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. */
  13. #include <linux/i2c.h>
  14. #include <linux/mfd/tps65023.h>
  15. #include <linux/module.h>
  16. /* TPS65023_registers */
  17. #define TPS65023_VERSION 0
  18. #define TPS65023_PGOODZ 1
  19. #define TPS65023_MASK 2
  20. #define TPS65023_REG_CTRL 3
  21. #define TPS65023_CON_CTRL 4
  22. #define TPS65023_CON_CTRL2 5
  23. #define TPS65023_DEFCORE 6
  24. #define TPS65023_DEFSLEW 7
  25. #define TPS65023_LDO_CTRL 8
  26. #define TPS65023_MAX 9
  27. static struct i2c_client *tpsclient;
  28. int tps65023_set_dcdc1_level(int mvolts)
  29. {
  30. int val;
  31. int ret;
  32. if (!tpsclient)
  33. return -ENODEV;
  34. if (mvolts < 800 || mvolts > 1600)
  35. return -EINVAL;
  36. if (mvolts == 1600)
  37. val = 0x1F;
  38. else
  39. val = ((mvolts - 800)/25) & 0x1F;
  40. ret = i2c_smbus_write_byte_data(tpsclient, TPS65023_DEFCORE, val);
  41. if (!ret)
  42. ret = i2c_smbus_write_byte_data(tpsclient,
  43. TPS65023_CON_CTRL2, 0x80);
  44. return ret;
  45. }
  46. EXPORT_SYMBOL(tps65023_set_dcdc1_level);
  47. int tps65023_get_dcdc1_level(int *mvolts)
  48. {
  49. int val;
  50. if (!tpsclient)
  51. return -ENODEV;
  52. val = i2c_smbus_read_byte_data(tpsclient, TPS65023_DEFCORE) & 0x1F;
  53. if (val == 0x1F)
  54. *mvolts = 1600;
  55. else
  56. *mvolts = (val * 25) + 800;
  57. return 0;
  58. }
  59. EXPORT_SYMBOL(tps65023_get_dcdc1_level);
  60. static int tps65023_probe(struct i2c_client *client,
  61. const struct i2c_device_id *dev_id)
  62. {
  63. if (!i2c_check_functionality(client->adapter,
  64. I2C_FUNC_SMBUS_BYTE_DATA)) {
  65. printk(KERN_ERR "TPS65023 does not support SMBUS_BYTE_DATA.\n");
  66. return -EINVAL;
  67. }
  68. tpsclient = client;
  69. printk(KERN_INFO "TPS65023: PMIC probed.\n");
  70. return 0;
  71. }
  72. static int __devexit tps65023_remove(struct i2c_client *client)
  73. {
  74. tpsclient = NULL;
  75. return 0;
  76. }
  77. static const struct i2c_device_id tps65023_id[] = {
  78. { "tps65023", 0 },
  79. { }
  80. };
  81. MODULE_DEVICE_TABLE(i2c, tps65023_id);
  82. static struct i2c_driver tps65023_driver = {
  83. .driver = {
  84. .name = "tps65023",
  85. .owner = THIS_MODULE,
  86. },
  87. .probe = tps65023_probe,
  88. .remove = __devexit_p(tps65023_remove),
  89. .id_table = tps65023_id,
  90. };
  91. static int __init tps65023_init(void)
  92. {
  93. return i2c_add_driver(&tps65023_driver);
  94. }
  95. static void __exit tps65023_exit(void)
  96. {
  97. i2c_del_driver(&tps65023_driver);
  98. }
  99. module_init(tps65023_init);
  100. module_exit(tps65023_exit);