2 * tps65910.c -- TI TPS6591x
4 * Copyright 2010 Texas Instruments Inc.
6 * Author: Jorge Eduardo Candelaria <jedu@slimlogic.co.uk>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/init.h>
18 #include <linux/slab.h>
19 #include <linux/err.h>
20 #include <linux/platform_device.h>
21 #include <linux/debugfs.h>
22 #include <linux/gpio.h>
23 #include <linux/mfd/tps65910.h>
29 /* Comparator 1 voltage selection table in millivolts */
30 static const u16 COMP_VSEL_TABLE[] = {
31 0, 2500, 2500, 2500, 2500, 2550, 2600, 2650,
32 2700, 2750, 2800, 2850, 2900, 2950, 3000, 3050,
33 3100, 3150, 3200, 3250, 3300, 3350, 3400, 3450,
41 const u16 *vsel_table;
44 static struct comparator tps_comparators[] = {
47 .reg = TPS65911_VMBCH,
49 .vsel_table = COMP_VSEL_TABLE,
53 .reg = TPS65911_VMBCH2,
55 .vsel_table = COMP_VSEL_TABLE,
59 static int comp_threshold_set(struct tps65910 *tps65910, int id, int voltage)
61 struct comparator tps_comp = tps_comparators[id];
69 while (curr_voltage < tps_comp.uV_max) {
70 curr_voltage = tps_comp.vsel_table[index];
71 if (curr_voltage >= voltage)
73 else if (curr_voltage < voltage)
77 if (curr_voltage > tps_comp.uV_max)
81 ret = tps65910->write(tps65910, tps_comp.reg, 1, &val);
86 static int comp_threshold_get(struct tps65910 *tps65910, int id)
88 struct comparator tps_comp = tps_comparators[id];
95 ret = tps65910->read(tps65910, tps_comp.reg, 1, &val);
100 return tps_comp.vsel_table[val];
103 static ssize_t comp_threshold_show(struct device *dev,
104 struct device_attribute *attr, char *buf)
106 struct tps65910 *tps65910 = dev_get_drvdata(dev->parent);
107 struct attribute comp_attr = attr->attr;
110 if (!strcmp(comp_attr.name, "comp1_threshold"))
112 else if (!strcmp(comp_attr.name, "comp2_threshold"))
117 uVolt = comp_threshold_get(tps65910, id);
119 return sprintf(buf, "%d\n", uVolt);
122 static DEVICE_ATTR(comp1_threshold, S_IRUGO, comp_threshold_show, NULL);
123 static DEVICE_ATTR(comp2_threshold, S_IRUGO, comp_threshold_show, NULL);
125 static int tps65911_comparator_probe(struct platform_device *pdev)
127 struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
128 struct tps65910_board *pdata = dev_get_platdata(tps65910->dev);
131 ret = comp_threshold_set(tps65910, COMP1, pdata->vmbch_threshold);
133 dev_err(&pdev->dev, "cannot set COMP1 threshold\n");
137 ret = comp_threshold_set(tps65910, COMP2, pdata->vmbch2_threshold);
139 dev_err(&pdev->dev, "cannot set COMP2 threshold\n");
143 /* Create sysfs entry */
144 ret = device_create_file(&pdev->dev, &dev_attr_comp1_threshold);
146 dev_err(&pdev->dev, "failed to add COMP1 sysfs file\n");
148 ret = device_create_file(&pdev->dev, &dev_attr_comp2_threshold);
150 dev_err(&pdev->dev, "failed to add COMP2 sysfs file\n");
155 static int tps65911_comparator_remove(struct platform_device *pdev)
157 struct tps65910 *tps65910;
159 tps65910 = dev_get_drvdata(pdev->dev.parent);
160 device_remove_file(&pdev->dev, &dev_attr_comp2_threshold);
161 device_remove_file(&pdev->dev, &dev_attr_comp1_threshold);
166 static struct platform_driver tps65911_comparator_driver = {
168 .name = "tps65911-comparator",
170 .probe = tps65911_comparator_probe,
171 .remove = tps65911_comparator_remove,
174 static int __init tps65911_comparator_init(void)
176 return platform_driver_register(&tps65911_comparator_driver);
178 subsys_initcall(tps65911_comparator_init);
180 static void __exit tps65911_comparator_exit(void)
182 platform_driver_unregister(&tps65911_comparator_driver);
184 module_exit(tps65911_comparator_exit);
186 MODULE_AUTHOR("Jorge Eduardo Candelaria <jedu@slimlogic.co.uk>");
187 MODULE_DESCRIPTION("TPS65911 comparator driver");
188 MODULE_LICENSE("GPL v2");
189 MODULE_ALIAS("platform:tps65911-comparator");