tracking-2.6.27-rc2-include-path-changes.patch
[kernel.git] / arch / arm / plat-s3c24xx / neo1973_pm_bt.c
1 /*
2  * Bluetooth PM code for the FIC Neo1973 GSM Phone
3  *
4  * (C) 2007 by Openmoko Inc.
5  * Author: Harald Welte <laforge@openmoko.org>
6  * All rights reserved.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation
11  *
12  */
13
14 #include <linux/module.h>
15 #include <linux/init.h>
16 #include <linux/kernel.h>
17 #include <linux/platform_device.h>
18
19 #include <mach/hardware.h>
20 #include <asm/mach-types.h>
21 #include <asm/plat-s3c24xx/neo1973.h>
22
23 #ifdef CONFIG_MACH_NEO1973_GTA01
24 #include <asm/arch/gta01.h>
25 #include <linux/pcf50606.h>
26 #endif
27
28 #ifdef CONFIG_MACH_NEO1973_GTA02
29 #include <asm/arch/gta02.h>
30 #include <linux/pcf50633.h>
31 #endif
32
33
34 #define DRVMSG "FIC Neo1973 Bluetooth Power Management"
35
36 static ssize_t bt_read(struct device *dev, struct device_attribute *attr,
37                        char *buf)
38 {
39         if (!strcmp(attr->attr.name, "power_on")) {
40                 switch (machine_arch_type) {
41
42 #ifdef CONFIG_MACH_NEO1973_GTA01
43                 case MACH_TYPE_NEO1973_GTA01:
44                         if (pcf50606_onoff_get(pcf50606_global,
45                                                 PCF50606_REGULATOR_D1REG) &&
46                             pcf50606_voltage_get(pcf50606_global,
47                                                  PCF50606_REGULATOR_D1REG) == 3100)
48                                 goto out_1;
49                         break;
50 #endif /* CONFIG_MACH_NEO1973_GTA01 */
51
52 #ifdef CONFIG_MACH_NEO1973_GTA02
53                 case MACH_TYPE_NEO1973_GTA02:
54                         if (s3c2410_gpio_getpin(GTA02_GPIO_BT_EN))
55                                 goto out_1;
56                         break;
57 #endif /* CONFIG_MACH_NEO1973_GTA02 */
58
59                 }
60         } else if (!strcmp(attr->attr.name, "reset")) {
61                 switch (machine_arch_type) {
62
63 #ifdef CONFIG_MACH_NEO1973_GTA01
64                 case MACH_TYPE_NEO1973_GTA01:
65                         if (s3c2410_gpio_getpin(GTA01_GPIO_BT_EN) == 0)
66                                 goto out_1;
67                         break;
68 #endif /* CONFIG_MACH_NEO1973_GTA01 */
69
70 #ifdef CONFIG_MACH_NEO1973_GTA02
71                 case MACH_TYPE_NEO1973_GTA02:
72                         if (s3c2410_gpio_getpin(GTA02_GPIO_BT_EN) == 0)
73                                 goto out_1;
74                         break;
75 #endif /* CONFIG_MACH_NEO1973_GTA02 */
76
77                 }
78         }
79
80         return strlcpy(buf, "0\n", 3);
81 out_1:
82         return strlcpy(buf, "1\n", 3);
83 }
84
85 static ssize_t bt_write(struct device *dev, struct device_attribute *attr,
86                         const char *buf, size_t count)
87 {
88         unsigned long on = simple_strtoul(buf, NULL, 10);
89         unsigned int vol;
90
91         if (!strcmp(attr->attr.name, "power_on")) {
92                 switch (machine_arch_type) {
93
94 #ifdef CONFIG_MACH_NEO1973_GTA01
95                 case MACH_TYPE_NEO1973_GTA01:
96                         /* if we are powering up, assert reset, then power,
97                          * then release reset */
98                         if (on) {
99                                 neo1973_gpb_setpin(GTA01_GPIO_BT_EN, 0);
100                                 pcf50606_voltage_set(pcf50606_global,
101                                                      PCF50606_REGULATOR_D1REG,
102                                                      3100);
103                         }
104                         pcf50606_onoff_set(pcf50606_global,
105                                            PCF50606_REGULATOR_D1REG, on);
106                         neo1973_gpb_setpin(GTA01_GPIO_BT_EN, on);
107                         break;
108 #endif /* CONFIG_MACH_NEO1973_GTA01 */
109
110 #ifdef CONFIG_MACH_NEO1973_GTA02
111                 case MACH_TYPE_NEO1973_GTA02:
112                         neo1973_gpb_setpin(GTA02_GPIO_BT_EN, on ? 0 : 1);
113                         if (on)
114                                 pcf50633_voltage_set(pcf50633_global,
115                                         PCF50633_REGULATOR_LDO4, 3200);
116                         pcf50633_onoff_set(pcf50633_global,
117                                 PCF50633_REGULATOR_LDO4, on);
118                         vol = pcf50633_voltage_get(pcf50633_global,
119                                 PCF50633_REGULATOR_LDO4);
120                         dev_info(dev, "GTA02 Set PCF50633 LDO4 = %d\n", vol);
121                         break;
122 #endif /* CONFIG_MACH_NEO1973_GTA02 */
123
124                 }
125         } else if (!strcmp(attr->attr.name, "reset")) {
126                 /* reset is low-active, so we need to invert */
127                 switch (machine_arch_type) {
128
129 #ifdef CONFIG_MACH_NEO1973_GTA01
130                 case MACH_TYPE_NEO1973_GTA01:
131                         neo1973_gpb_setpin(GTA01_GPIO_BT_EN, on ? 0 : 1);
132                         break;
133 #endif /* CONFIG_MACH_NEO1973_GTA01 */
134
135 #ifdef CONFIG_MACH_NEO1973_GTA02
136                 case MACH_TYPE_NEO1973_GTA02:
137                         neo1973_gpb_setpin(GTA02_GPIO_BT_EN, on ? 0 : 1);
138                         break;
139 #endif /* CONFIG_MACH_NEO1973_GTA02 */
140
141                 }
142         }
143
144         return count;
145 }
146
147 static DEVICE_ATTR(power_on, 0644, bt_read, bt_write);
148 static DEVICE_ATTR(reset, 0644, bt_read, bt_write);
149
150 #ifdef CONFIG_PM
151 static int gta01_bt_suspend(struct platform_device *pdev, pm_message_t state)
152 {
153         dev_dbg(&pdev->dev, DRVMSG ": suspending\n");
154         /* FIXME: The PMU should save the PMU status, and the GPIO code should
155          * preserve the GPIO level, so there shouldn't be anything left to do
156          * for us, should there? */
157
158         return 0;
159 }
160
161 static int gta01_bt_resume(struct platform_device *pdev)
162 {
163         dev_dbg(&pdev->dev, DRVMSG ": resuming\n");
164
165         return 0;
166 }
167 #else
168 #define gta01_bt_suspend        NULL
169 #define gta01_bt_resume         NULL
170 #endif
171
172 static struct attribute *gta01_bt_sysfs_entries[] = {
173         &dev_attr_power_on.attr,
174         &dev_attr_reset.attr,
175         NULL
176 };
177
178 static struct attribute_group gta01_bt_attr_group = {
179         .name   = NULL,
180         .attrs  = gta01_bt_sysfs_entries,
181 };
182
183 static int __init gta01_bt_probe(struct platform_device *pdev)
184 {
185         dev_info(&pdev->dev, DRVMSG ": starting\n");
186
187         switch (machine_arch_type) {
188
189 #ifdef CONFIG_MACH_NEO1973_GTA01
190         case MACH_TYPE_NEO1973_GTA01:
191                 /* we make sure that the voltage is off */
192                 pcf50606_onoff_set(pcf50606_global,
193                                    PCF50606_REGULATOR_D1REG, 0);
194                 /* we pull reset to low to make sure that the chip doesn't
195                  * drain power through the reset line */
196                 neo1973_gpb_setpin(GTA01_GPIO_BT_EN, 0);
197                 break;
198 #endif /* CONFIG_MACH_NEO1973_GTA01 */
199
200 #ifdef CONFIG_MACH_NEO1973_GTA02
201         case MACH_TYPE_NEO1973_GTA02:
202                 /* we make sure that the voltage is off */
203                 pcf50633_onoff_set(pcf50633_global,
204                                      PCF50633_REGULATOR_LDO4, 0);
205                 /* we pull reset to low to make sure that the chip doesn't
206                  * drain power through the reset line */
207                 neo1973_gpb_setpin(GTA02_GPIO_BT_EN, 0);
208                 break;
209 #endif /* CONFIG_MACH_NEO1973_GTA02 */
210
211         }
212
213         return sysfs_create_group(&pdev->dev.kobj, &gta01_bt_attr_group);
214 }
215
216 static int gta01_bt_remove(struct platform_device *pdev)
217 {
218         sysfs_remove_group(&pdev->dev.kobj, &gta01_bt_attr_group);
219
220         return 0;
221 }
222
223 static struct platform_driver gta01_bt_driver = {
224         .probe          = gta01_bt_probe,
225         .remove         = gta01_bt_remove,
226         .suspend        = gta01_bt_suspend,
227         .resume         = gta01_bt_resume,
228         .driver         = {
229                 .name           = "neo1973-pm-bt",
230         },
231 };
232
233 static int __devinit gta01_bt_init(void)
234 {
235         return platform_driver_register(&gta01_bt_driver);
236 }
237
238 static void gta01_bt_exit(void)
239 {
240         platform_driver_unregister(&gta01_bt_driver);
241 }
242
243 module_init(gta01_bt_init);
244 module_exit(gta01_bt_exit);
245
246 MODULE_LICENSE("GPL");
247 MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
248 MODULE_DESCRIPTION(DRVMSG);