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