[UPSTREAM - RFC] pm_bt_use_regulator_api.patch

Balaji Rao balaji at raobalaji.com
Wed Oct 8 16:11:26 CEST 2008


pm_bt_use_regulator_api.patch

Use regulator API for powering on/off the BT device.
---

 arch/arm/mach-s3c2440/mach-gta02.c    |   11 +++++
 arch/arm/plat-s3c24xx/neo1973_pm_bt.c |   67 +++++++++++++++++++++++++++++----
 2 files changed, 69 insertions(+), 9 deletions(-)


diff --git a/arch/arm/mach-s3c2440/mach-gta02.c b/arch/arm/mach-s3c2440/mach-gta02.c
index 8e22a3f..a472f4a 100644
--- a/arch/arm/mach-s3c2440/mach-gta02.c
+++ b/arch/arm/mach-s3c2440/mach-gta02.c
@@ -82,6 +82,7 @@
 #include <asm/plat-s3c24xx/udc.h>
 #include <asm/plat-s3c24xx/neo1973.h>
 #include <asm/arch-s3c2410/neo1973-pm-gsm.h>
+#include <asm/arch-s3c2410/neo1973-pm-bt.h>
 
 #include <linux/jbt6k74.h>
 
@@ -541,8 +542,16 @@ static struct platform_device gta01_pm_gps_dev = {
 	.name		= "neo1973-pm-gps",
 };
 
+static struct gta01_pm_bt_platform_data gta01_pm_bt_dev_pdata = {
+	.voltage_supply = "BT_3V2",
+};
+
 static struct platform_device gta01_pm_bt_dev = {
 	.name		= "neo1973-pm-bt",
+	.dev		=  {
+
+				.platform_data = &gta01_pm_bt_dev_pdata,
+			},
 };
 
 /* Regulation constraints */
@@ -585,6 +594,8 @@ static void gta02_pcf50633_attach_child_devices(struct device *parent_device)
 	regulator_set_machine_constraints("ldo4", &ldo4_constraint);
 	regulator_set_machine_constraints("ldo5", &ldo5_constraint);
 
+	regulator_set_device_supply("ldo4", &gta01_pm_bt_dev.dev, "BT_3V2");
+
 	gta01_pm_gps_dev.dev.parent = parent_device;
 	gta01_pm_bt_dev.dev.parent = parent_device;
 	platform_device_register(&gta01_pm_bt_dev);
diff --git a/arch/arm/plat-s3c24xx/neo1973_pm_bt.c b/arch/arm/plat-s3c24xx/neo1973_pm_bt.c
index 0c73179..ec99966 100644
--- a/arch/arm/plat-s3c24xx/neo1973_pm_bt.c
+++ b/arch/arm/plat-s3c24xx/neo1973_pm_bt.c
@@ -30,9 +30,15 @@
 #include <linux/pcf50633.h>
 #endif
 
+#include <linux/regulator/consumer.h>
+#include <asm/arch/neo1973-pm-bt.h>
 
 #define DRVMSG "FIC Neo1973 Bluetooth Power Management"
 
+struct gta01_pm_bt_data {
+	struct regulator *regulator;
+};
+
 static ssize_t bt_read(struct device *dev, struct device_attribute *attr,
 		       char *buf)
 {
@@ -85,6 +91,9 @@ out_1:
 static ssize_t bt_write(struct device *dev, struct device_attribute *attr,
 			const char *buf, size_t count)
 {
+	struct gta01_pm_bt_data *bt_data;
+	struct regulator *regulator;
+
 	unsigned long on = simple_strtoul(buf, NULL, 10);
 #ifdef CONFIG_MACH_NEO1973_GTA02
 	unsigned int vol;
@@ -111,14 +120,22 @@ static ssize_t bt_write(struct device *dev, struct device_attribute *attr,
 
 #ifdef CONFIG_MACH_NEO1973_GTA02
 		case MACH_TYPE_NEO1973_GTA02:
+			bt_data = dev_get_drvdata(dev);
+			BUG_ON(!bt_data || !bt_data->regulator);
+			regulator = bt_data->regulator;
+				
 			neo1973_gpb_setpin(GTA02_GPIO_BT_EN, on ? 0 : 1);
-			if (on)
-				pcf50633_voltage_set(gta02_pcf_pdata.pcf,
-					PCF50633_REGULATOR_LDO4, 3200);
-			pcf50633_onoff_set(gta02_pcf_pdata.pcf,
-				PCF50633_REGULATOR_LDO4, on);
-			vol = pcf50633_voltage_get(gta02_pcf_pdata.pcf,
-				PCF50633_REGULATOR_LDO4);
+
+			if (on) {
+				regulator_set_voltage(regulator, 3200000, 3200000);
+				if (!regulator_is_enabled(regulator))
+					regulator_enable(regulator);
+			} else {
+				if (regulator_is_enabled(regulator))
+						regulator_disable(regulator);
+			}
+
+			vol = regulator_get_voltage(regulator);
 			dev_info(dev, "GTA02 Set PCF50633 LDO4 = %d\n", vol);
 			break;
 #endif /* CONFIG_MACH_NEO1973_GTA02 */
@@ -184,6 +201,10 @@ static struct attribute_group gta01_bt_attr_group = {
 
 static int __init gta01_bt_probe(struct platform_device *pdev)
 {
+	struct regulator *regulator;
+	struct gta01_pm_bt_data *bt_data;
+	struct gta01_pm_bt_platform_data *pdata;
+
 	dev_info(&pdev->dev, DRVMSG ": starting\n");
 
 	switch (machine_arch_type) {
@@ -201,9 +222,22 @@ static int __init gta01_bt_probe(struct platform_device *pdev)
 
 #ifdef CONFIG_MACH_NEO1973_GTA02
 	case MACH_TYPE_NEO1973_GTA02:
+		pdata = pdev->dev.platform_data;
+		if (!pdata)
+			return -ENODEV;
+
+		regulator = regulator_get(&pdev->dev, pdata->voltage_supply);
+		if (!regulator)
+			return -ENODEV;
+
+		bt_data = kmalloc(sizeof(*bt_data), GFP_KERNEL);
+		bt_data->regulator = regulator;
+		dev_set_drvdata(&pdev->dev, bt_data);
+
 		/* we make sure that the voltage is off */
-		pcf50633_onoff_set(gta02_pcf_pdata.pcf,
-				     PCF50633_REGULATOR_LDO4, 0);
+		if (regulator_is_enabled(regulator))
+			regulator_disable(regulator);
+
 		/* we pull reset to low to make sure that the chip doesn't
 	 	 * drain power through the reset line */
 		neo1973_gpb_setpin(GTA02_GPIO_BT_EN, 0);
@@ -217,8 +251,23 @@ static int __init gta01_bt_probe(struct platform_device *pdev)
 
 static int gta01_bt_remove(struct platform_device *pdev)
 {
+	struct gta01_pm_bt_data *bt_data;
+	struct regulator *regulator;
+
 	sysfs_remove_group(&pdev->dev.kobj, &gta01_bt_attr_group);
 
+	bt_data = dev_get_drvdata(&pdev->dev);
+	if (!bt_data || !bt_data->regulator)
+		return 0;
+
+	regulator = bt_data->regulator;
+
+	/* Make sure regulator is disabled before calling regulator_put */
+	if (regulator_is_enabled(regulator))
+		regulator_disable(regulator);
+
+	regulator_put(regulator);
+	
 	return 0;
 }
 



More information about the openmoko-kernel mailing list