1 /* drivers/regulator/charge-regulator.c
\r
3 * Copyright (C) 2010 ROCKCHIP, Inc.
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 /*******************************************************************/
16 /* COPYRIGHT (C) ROCK-CHIPS FUZHOU . ALL RIGHTS RESERVED. */
17 /*******************************************************************
18 FILE : charge-regulator.c
\r
19 DESC : charge current change driver
\r
25 ********************************************************************/
28 #include <linux/bug.h>
29 #include <linux/err.h>
\r
30 #include <linux/platform_device.h>
\r
31 #include <linux/kernel.h>
32 #include <linux/regulator/driver.h>
33 #include <linux/regulator/charge-regulator.h>
\r
34 #include <linux/gpio.h>
\r
38 #define DBG(x...) printk(KERN_INFO x)
44 const static int charge_current_map[] = {
\r
48 static int charge_current_is_enabled(struct regulator_dev *dev)
\r
53 static int charge_current_enable(struct regulator_dev *dev)
\r
58 static int charge_current_disable(struct regulator_dev *dev)
\r
63 static int charge_get_current(struct regulator_dev *dev)
\r
65 const int *current_map = charge_current_map;
\r
67 struct charge_platform_data *pdata = rdev_get_drvdata(dev);
\r
69 gpio_direction_input(pdata->gpio_charge);
\r
71 return gpio_get_value(pdata->gpio_charge) ? current_map[0] *1000:current_map[1]*1000;
\r
74 static int charge_set_current(struct regulator_dev *dev,
\r
75 int min_uA, int max_uA)
\r
77 DBG("enter charge_set_current , max_uA = %d\n",max_uA);
\r
78 struct charge_platform_data *pdata = rdev_get_drvdata(dev);
\r
79 const int *current_map = charge_current_map;
\r
80 int max_mA = max_uA / 1000;
\r
81 if ( max_mA == current_map[0] )
\r
82 gpio_direction_output(pdata->gpio_charge, GPIO_HIGH);
\r
84 gpio_direction_output(pdata->gpio_charge, GPIO_LOW);
\r
90 static struct regulator_ops charge_current_ops = {
\r
91 .is_enabled = charge_current_is_enabled,
\r
92 .enable = charge_current_enable,
\r
93 .disable = charge_current_disable,
\r
94 .get_current_limit = charge_get_current,
\r
95 .set_current_limit = charge_set_current,
\r
98 static struct regulator_desc chargeregulator= {
\r
99 .name = "charge-regulator",
\r
100 .ops = &charge_current_ops,
\r
101 .type = REGULATOR_CURRENT,
\r
106 static int __devinit charge_regulator_probe(struct platform_device *pdev)
\r
109 struct charge_platform_data *pdata = pdev->dev.platform_data;
\r
110 struct regulator_dev *rdev;
\r
113 rdev = regulator_register(&chargeregulator, &pdev->dev,
\r
114 pdata->init_data, pdata);
\r
115 if (IS_ERR(rdev)) {
\r
116 dev_dbg(&pdev->dev, "couldn't register regulator\n");
117 return PTR_ERR(rdev);
\r
120 ret = gpio_request(pdata->gpio_charge, "charge_current");
\r
123 dev_err(&pdev->dev,"failed to request charge gpio\n");
\r
127 platform_set_drvdata(pdev, rdev);
\r
128 printk(KERN_INFO "charge_regulator: driver initialized\n");
\r
132 gpio_free(pdata->gpio_charge);
\r
137 static int __devexit charge_regulator_remove(struct platform_device *pdev)
\r
139 struct charge_platform_data *pdata = pdev->dev.platform_data;
\r
140 struct regulator_dev *rdev = platform_get_drvdata(pdev);
\r
142 regulator_unregister(rdev);
\r
143 gpio_free(pdata->gpio_charge);
\r
148 static struct platform_driver charge_regulator_driver = {
\r
150 .name = "charge-regulator",
\r
152 .remove = __devexit_p(charge_regulator_remove),
\r
156 static int __init charge_regulator_module_init(void)
\r
158 return platform_driver_probe(&charge_regulator_driver, charge_regulator_probe);
161 static void __exit charge_regulator_module_exit(void)
\r
163 platform_driver_unregister(&charge_regulator_driver);
\r
167 module_init(charge_regulator_module_init);
\r
169 module_exit(charge_regulator_module_exit);
\r
171 MODULE_LICENSE("GPL");
172 MODULE_AUTHOR("hxy <hxy@rock-chips.com>");
\r
173 MODULE_DESCRIPTION("charge current change driver");
\r