blob: 318692fe7beb7b2898beaf2ea9c169dcad742fcf [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Copyright (c) 2009, Code Aurora Forum. 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
14#include <linux/i2c.h>
15#include <linux/mfd/tps65023.h>
Steve Mucklef132c6c2012-06-06 18:30:57 -070016#include <linux/module.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070017
18/* TPS65023_registers */
19#define TPS65023_VERSION 0
20#define TPS65023_PGOODZ 1
21#define TPS65023_MASK 2
22#define TPS65023_REG_CTRL 3
23#define TPS65023_CON_CTRL 4
24#define TPS65023_CON_CTRL2 5
25#define TPS65023_DEFCORE 6
26#define TPS65023_DEFSLEW 7
27#define TPS65023_LDO_CTRL 8
28#define TPS65023_MAX 9
29
30static struct i2c_client *tpsclient;
31
32int tps65023_set_dcdc1_level(int mvolts)
33{
34 int val;
35 int ret;
36
37 if (!tpsclient)
38 return -ENODEV;
39
40 if (mvolts < 800 || mvolts > 1600)
41 return -EINVAL;
42
43 if (mvolts == 1600)
44 val = 0x1F;
45 else
46 val = ((mvolts - 800)/25) & 0x1F;
47
48 ret = i2c_smbus_write_byte_data(tpsclient, TPS65023_DEFCORE, val);
49
50 if (!ret)
51 ret = i2c_smbus_write_byte_data(tpsclient,
52 TPS65023_CON_CTRL2, 0x80);
53
54 return ret;
55}
56EXPORT_SYMBOL(tps65023_set_dcdc1_level);
57
58int tps65023_get_dcdc1_level(int *mvolts)
59{
60 int val;
61
62 if (!tpsclient)
63 return -ENODEV;
64
65 val = i2c_smbus_read_byte_data(tpsclient, TPS65023_DEFCORE) & 0x1F;
66
67 if (val == 0x1F)
68 *mvolts = 1600;
69 else
70 *mvolts = (val * 25) + 800;
71 return 0;
72}
73EXPORT_SYMBOL(tps65023_get_dcdc1_level);
74
75static int tps65023_probe(struct i2c_client *client,
76 const struct i2c_device_id *dev_id)
77{
78 if (!i2c_check_functionality(client->adapter,
79 I2C_FUNC_SMBUS_BYTE_DATA)) {
80 printk(KERN_ERR "TPS65023 does not support SMBUS_BYTE_DATA.\n");
81 return -EINVAL;
82 }
83
84 tpsclient = client;
85 printk(KERN_INFO "TPS65023: PMIC probed.\n");
86 return 0;
87}
88
89static int __devexit tps65023_remove(struct i2c_client *client)
90{
91 tpsclient = NULL;
92 return 0;
93}
94
95static const struct i2c_device_id tps65023_id[] = {
96 { "tps65023", 0 },
97 { }
98};
99MODULE_DEVICE_TABLE(i2c, tps65023_id);
100
101static struct i2c_driver tps65023_driver = {
102 .driver = {
103 .name = "tps65023",
104 .owner = THIS_MODULE,
105 },
106 .probe = tps65023_probe,
107 .remove = __devexit_p(tps65023_remove),
108 .id_table = tps65023_id,
109};
110
111static int __init tps65023_init(void)
112{
113 return i2c_add_driver(&tps65023_driver);
114}
115
116
117static void __exit tps65023_exit(void)
118{
119 i2c_del_driver(&tps65023_driver);
120}
121
122module_init(tps65023_init);
123module_exit(tps65023_exit);