mirror of
https://github.com/torvalds/linux.git
synced 2026-06-08 22:52:35 +02:00
change charge current
This commit is contained in:
parent
f81e80071a
commit
ad7dac93fc
|
|
@ -38,6 +38,10 @@
|
|||
#include <mach/gpio.h>
|
||||
#include <mach/spi_fpga.h>
|
||||
#include <mach/rk2818_camera.h> /* ddl@rock-chips.com : camera support */
|
||||
#include <linux/pda_power.h>
|
||||
#include <linux/regulator/charge-regulator.h>
|
||||
#include <linux/regulator/machine.h>
|
||||
#include <linux/usb/gpio_vbus.h>
|
||||
#include <mach/rk2818_nand.h>
|
||||
|
||||
#include <linux/mtd/nand.h>
|
||||
|
|
@ -821,6 +825,125 @@ static struct i2c_board_info __initdata board_i2c3_devices[] = {
|
|||
#endif
|
||||
};
|
||||
|
||||
/*
|
||||
* External power
|
||||
*/
|
||||
|
||||
static int power_supply_init(struct device *dev)
|
||||
{
|
||||
return gpio_request(FPGA_PIO2_08, "AC charger detect");
|
||||
}
|
||||
|
||||
static int rk2818_is_ac_online(void)
|
||||
{
|
||||
return !gpio_get_value(FPGA_PIO2_08);
|
||||
}
|
||||
|
||||
static void power_supply_exit(struct device *dev)
|
||||
{
|
||||
gpio_free(FPGA_PIO2_08);
|
||||
}
|
||||
|
||||
static char *rk2818_supplicant[] = {
|
||||
"rk2818-battery"
|
||||
};
|
||||
|
||||
static struct pda_power_pdata power_supply_info = {
|
||||
.init = power_supply_init,
|
||||
.is_ac_online = rk2818_is_ac_online,
|
||||
.exit = power_supply_exit,
|
||||
.supplied_to = rk2818_supplicant,
|
||||
.num_supplicants = ARRAY_SIZE(rk2818_supplicant),
|
||||
};
|
||||
|
||||
static struct resource power_supply_resources[] = {
|
||||
[0] = {
|
||||
.name = "ac",
|
||||
.flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
|
||||
IORESOURCE_IRQ_LOWEDGE,
|
||||
},
|
||||
[1] = {
|
||||
.name = "usb",
|
||||
.flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
|
||||
IORESOURCE_IRQ_LOWEDGE,
|
||||
},
|
||||
};
|
||||
|
||||
static struct platform_device power_supply = {
|
||||
.name = "pda-power",
|
||||
.id = -1,
|
||||
.dev = {
|
||||
.platform_data = &power_supply_info,
|
||||
},
|
||||
.resource = power_supply_resources,
|
||||
.num_resources = ARRAY_SIZE(power_supply_resources),
|
||||
};
|
||||
|
||||
/*
|
||||
* USB "Transceiver"
|
||||
*/
|
||||
|
||||
static struct resource gpio_vbus_resource = {
|
||||
.flags = IORESOURCE_IRQ,
|
||||
.start = IRQ_NR_OTG,
|
||||
.end = IRQ_NR_OTG,
|
||||
};
|
||||
|
||||
static struct gpio_vbus_mach_info gpio_vbus_info = {
|
||||
.gpio_vbus = FPGA_PIO4_06,
|
||||
};
|
||||
|
||||
static struct platform_device gpio_vbus = {
|
||||
.name = "gpio-vbus",
|
||||
.id = -1,
|
||||
.num_resources = 1,
|
||||
.resource = &gpio_vbus_resource,
|
||||
.dev = {
|
||||
.platform_data = &gpio_vbus_info,
|
||||
},
|
||||
};
|
||||
|
||||
/*
|
||||
* Battery charger
|
||||
*/
|
||||
|
||||
static struct regulator_consumer_supply rk2818_consumers[] = {
|
||||
{
|
||||
.dev=&rk2818_device_battery.dev,
|
||||
.supply = "battery",
|
||||
},
|
||||
{
|
||||
.dev = &gpio_vbus.dev,
|
||||
.supply = "vbus_draw",
|
||||
},
|
||||
{
|
||||
.dev = &power_supply.dev,
|
||||
.supply = "ac_draw",
|
||||
},
|
||||
};
|
||||
|
||||
static struct regulator_init_data charge_init_data = {
|
||||
.constraints = {
|
||||
.max_uA = 1200000,
|
||||
.valid_ops_mask = REGULATOR_CHANGE_CURRENT,
|
||||
},
|
||||
.num_consumer_supplies = ARRAY_SIZE(rk2818_consumers),
|
||||
.consumer_supplies = rk2818_consumers,
|
||||
};
|
||||
|
||||
static struct charge_platform_data charge_current_info = {
|
||||
.gpio_charge = FPGA_PIO2_08,
|
||||
.init_data = &charge_init_data,
|
||||
};
|
||||
|
||||
static struct platform_device charge_current = {
|
||||
.name = "charge-regulator",
|
||||
.id = -1,
|
||||
.dev = {
|
||||
.platform_data = &charge_current_info,
|
||||
},
|
||||
};
|
||||
|
||||
/*****************************************************************************************
|
||||
* camera devices
|
||||
* author: ddl@rock-chips.com
|
||||
|
|
@ -1708,6 +1831,10 @@ static struct platform_device *devices[] __initdata = {
|
|||
#endif
|
||||
&rk2818_device_adc,
|
||||
&rk2818_device_adckey,
|
||||
#if defined(CONFIG_RK2818_REGULATOR_CHARGE)
|
||||
&power_supply,
|
||||
&charge_current,
|
||||
#endif
|
||||
&rk2818_device_battery,
|
||||
&rk2818_device_fb,
|
||||
&rk2818_device_backlight,
|
||||
|
|
|
|||
24
drivers/power/rk2818_battery.c
Executable file → Normal file
24
drivers/power/rk2818_battery.c
Executable file → Normal file
|
|
@ -17,6 +17,7 @@
|
|||
#include <linux/err.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/power_supply.h>
|
||||
#include <linux/regulator/consumer.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/pci.h>
|
||||
#include <linux/interrupt.h>
|
||||
|
|
@ -98,7 +99,7 @@ int gBatSlopeLevel = SLOPE_LOW_LEVEL;
|
|||
int gBatVoltageLevel = VOLTAGE_MID_LEVEL;
|
||||
int gBatUseStatus = BAT_LOADER_STATUS;
|
||||
|
||||
|
||||
static struct regulator *pChargeregulator;
|
||||
|
||||
extern int dwc_vbus_status(void);
|
||||
extern int get_msc_connect_flag(void);
|
||||
|
|
@ -146,11 +147,19 @@ static int rk2818_get_charge_status(void)
|
|||
{
|
||||
//DBG("gAdcValue[CHN_USB_ADC]=%d\n",gAdcValue[CHN_USB_ADC]);
|
||||
if(gAdcValue[CHN_USB_ADC] > 250) //about 0.5V
|
||||
return 1;
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if((1 == dwc_vbus_status())&& (0 == get_msc_connect_flag()))
|
||||
return 1;
|
||||
{
|
||||
regulator_set_current_limit(pChargeregulator,0,1200000);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
{
|
||||
regulator_set_current_limit(pChargeregulator,0,475000);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void rk2818_get_bat_status(struct rk2818_battery_data *bat)
|
||||
|
|
@ -612,6 +621,13 @@ static int rk2818_battery_probe(struct platform_device *pdev)
|
|||
goto err_battery_failed;
|
||||
}
|
||||
platform_set_drvdata(pdev, data);
|
||||
|
||||
|
||||
pChargeregulator = regulator_get(&pdev->dev, "battery");
|
||||
if(IS_ERR(pChargeregulator))
|
||||
printk(KERN_ERR"fail to get regulator battery\n");
|
||||
else
|
||||
regulator_set_current_limit(pChargeregulator,0,475000);
|
||||
|
||||
INIT_WORK(&data->timer_work, rk2818_battery_timer_work);
|
||||
gBatteryData = data;
|
||||
|
|
|
|||
|
|
@ -156,6 +156,10 @@ config REGULATOR_TPS6507X
|
|||
This driver supports TPS6507X voltage regulator chips. TPS6507X provides
|
||||
three step-down converters and two general-purpose LDO voltage regulators.
|
||||
It supports TI's software based Class-2 SmartReflex implementation.
|
||||
config RK2818_REGULATOR_CHARGE
|
||||
tristate "rk2818 Charger IC"
|
||||
help
|
||||
Say Y to enable support for the current regulators charge on the RK2818.
|
||||
|
||||
config RK2818_REGULATOR_LP8725
|
||||
tristate "rk2818 pmic lp8725"
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o
|
|||
obj-$(CONFIG_REGULATOR_MC13783) += mc13783.o
|
||||
obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o
|
||||
obj-$(CONFIG_RK2818_REGULATOR_LP8725) += rk2818_lp8725.o
|
||||
obj-$(CONFIG_RK2818_REGULATOR_CHARGE) += charge-regulator.o
|
||||
|
||||
obj-$(CONFIG_REGULATOR_TPS65023) += tps65023-regulator.o
|
||||
obj-$(CONFIG_REGULATOR_TPS6507X) += tps6507x-regulator.o
|
||||
|
|
|
|||
180
drivers/regulator/charge-regulator.c
Normal file
180
drivers/regulator/charge-regulator.c
Normal file
|
|
@ -0,0 +1,180 @@
|
|||
/* drivers/regulator/charge-regulator.c
|
||||
*
|
||||
* Copyright (C) 2010 ROCKCHIP, Inc.
|
||||
*
|
||||
* This software is licensed under the terms of the GNU General Public
|
||||
* License version 2, as published by the Free Software Foundation, and
|
||||
* may be copied, distributed, and modified under those terms.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
/*******************************************************************/
|
||||
/* COPYRIGHT (C) ROCK-CHIPS FUZHOU . ALL RIGHTS RESERVED. */
|
||||
/*******************************************************************
|
||||
FILE : charge-regulator.c
|
||||
DESC : charge current change driver
|
||||
AUTHOR : hxy
|
||||
DATE : 2010-09-02
|
||||
NOTES :
|
||||
$LOG: GPIO.C,V $
|
||||
REVISION 0.01
|
||||
********************************************************************/
|
||||
|
||||
|
||||
#include <linux/bug.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/regulator/driver.h>
|
||||
#include <linux/regulator/charge-regulator.h>
|
||||
#include <linux/gpio.h>
|
||||
|
||||
|
||||
#if 0
|
||||
#define DBG(x...) printk(KERN_INFO x)
|
||||
#else
|
||||
#define DBG(x...)
|
||||
#endif
|
||||
|
||||
|
||||
const static int charge_current_map[] = {
|
||||
475, 1200,
|
||||
};
|
||||
|
||||
static int charge_current_is_enabled(struct regulator_dev *dev)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int charge_current_enable(struct regulator_dev *dev)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int charge_current_disable(struct regulator_dev *dev)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int charge_get_current(struct regulator_dev *dev)
|
||||
{
|
||||
const int *current_map = charge_current_map;
|
||||
|
||||
struct charge_platform_data *pdata = rdev_get_drvdata(dev);
|
||||
|
||||
gpio_direction_input(pdata->gpio_charge);
|
||||
|
||||
return gpio_get_value(pdata->gpio_charge) ? current_map[0] *1000:current_map[1]*1000;
|
||||
}
|
||||
|
||||
static int charge_set_current(struct regulator_dev *dev,
|
||||
int min_uA, int max_uA)
|
||||
{
|
||||
printk("enter charge_set_current , max_uA = %d\n",max_uA);
|
||||
struct charge_platform_data *pdata = rdev_get_drvdata(dev);
|
||||
const int *current_map = charge_current_map;
|
||||
int max_mA = max_uA / 1000;
|
||||
printk("charge_set_current:pdata->gpio_charge=%d\n",pdata->gpio_charge);
|
||||
if ( max_mA == current_map[0] )
|
||||
gpio_direction_output(pdata->gpio_charge, GPIO_HIGH);
|
||||
else
|
||||
gpio_direction_output(pdata->gpio_charge, GPIO_LOW);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
static struct regulator_ops charge_current_ops = {
|
||||
.is_enabled = charge_current_is_enabled,
|
||||
.enable = charge_current_enable,
|
||||
.disable = charge_current_disable,
|
||||
.get_current_limit = charge_get_current,
|
||||
.set_current_limit = charge_set_current,
|
||||
};
|
||||
|
||||
static struct regulator_desc chargeregulator= {
|
||||
.name = "charge-regulator",
|
||||
.ops = &charge_current_ops,
|
||||
.type = REGULATOR_CURRENT,
|
||||
};
|
||||
|
||||
|
||||
|
||||
static int __devinit charge_regulator_probe(struct platform_device *pdev)
|
||||
{
|
||||
|
||||
struct charge_platform_data *pdata = pdev->dev.platform_data;
|
||||
struct regulator_dev *rdev;
|
||||
int ret ;
|
||||
printk(KERN_INFO "enter charge regulator\n");
|
||||
#if 0
|
||||
rdev = regulator_register(&chargeregulator, &pdev->dev,
|
||||
pdev->dev.platform_data, pdata);
|
||||
#else
|
||||
rdev = regulator_register(&chargeregulator, &pdev->dev,
|
||||
pdata->init_data, pdata);
|
||||
#endif
|
||||
if (IS_ERR(rdev)) {
|
||||
dev_dbg(&pdev->dev, "couldn't register regulator\n");
|
||||
return PTR_ERR(rdev);
|
||||
}
|
||||
|
||||
ret = gpio_request(pdata->gpio_charge, "charge_current");
|
||||
|
||||
if (ret) {
|
||||
dev_err(&pdev->dev,"failed to request charge gpio\n");
|
||||
goto err_gpio;
|
||||
}
|
||||
|
||||
platform_set_drvdata(pdev, rdev);
|
||||
printk(KERN_INFO "charge_regulator: driver initialized\n");
|
||||
return 0;
|
||||
|
||||
err_gpio:
|
||||
gpio_free(pdata->gpio_charge);
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
static int __devexit charge_regulator_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct charge_platform_data *pdata = pdev->dev.platform_data;
|
||||
struct regulator_dev *rdev = platform_get_drvdata(pdev);
|
||||
|
||||
regulator_unregister(rdev);
|
||||
gpio_free(pdata->gpio_charge);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct platform_driver charge_regulator_driver = {
|
||||
.driver = {
|
||||
.name = "charge-regulator",
|
||||
},
|
||||
.remove = __devexit_p(charge_regulator_remove),
|
||||
};
|
||||
|
||||
|
||||
static int __init charge_regulator_module_init(void)
|
||||
{
|
||||
return platform_driver_probe(&charge_regulator_driver, charge_regulator_probe);
|
||||
}
|
||||
|
||||
static void __exit charge_regulator_module_exit(void)
|
||||
{
|
||||
platform_driver_unregister(&charge_regulator_driver);
|
||||
}
|
||||
|
||||
|
||||
module_init(charge_regulator_module_init);
|
||||
|
||||
module_exit(charge_regulator_module_exit);
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("hxy <hxy@rock-chips.com>");
|
||||
MODULE_DESCRIPTION("charge current change driver");
|
||||
|
||||
30
include/linux/regulator/charge-regulator.h
Normal file
30
include/linux/regulator/charge-regulator.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/* include/linux/regulator/charge-regulator.h
|
||||
*
|
||||
* Copyright (C) 2010 ROCKCHIP, Inc.
|
||||
*
|
||||
* This software is licensed under the terms of the GNU General Public
|
||||
* License version 2, as published by the Free Software Foundation, and
|
||||
* may be copied, distributed, and modified under those terms.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
#ifndef __LINUX_REGULATOR_CHARGE_H
|
||||
|
||||
#define __LINUX_REGULATOR_CHARGE_H
|
||||
|
||||
#include <linux/regulator/machine.h>
|
||||
|
||||
|
||||
struct regulator_init_data;
|
||||
|
||||
struct charge_platform_data {
|
||||
int gpio_charge;
|
||||
struct regulator_init_data *init_data;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
Reference in New Issue
Block a user