ad7cfd8826b9499c0f9b1174e8185a2683df54a5
[openwrt.git] / target / linux / s3c24xx / files-2.6.31 / drivers / misc / gta02_pm_host.c
1 /*
2  * Bluetooth PM code for the FIC gta02 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
22 #include <mach/gta02.h>
23 #include <linux/mfd/pcf50633/gpio.h>
24
25 static ssize_t pm_host_read(struct device *dev, struct device_attribute *attr,
26                             char *buf)
27 {
28         return sprintf(buf, "%d\n",
29                        pcf50633_gpio_get(gta02_pcf, PCF50633_GPO)
30                                                 == PCF50633_GPOCFG_GPOSEL_1);
31 }
32
33 static ssize_t pm_host_write(struct device *dev, struct device_attribute *attr,
34                              const char *buf, size_t count)
35 {
36         unsigned long on = simple_strtoul(buf, NULL, 10);
37         u8 val;
38
39         if (on)
40                 val = PCF50633_GPOCFG_GPOSEL_1;
41         else
42                 val = PCF50633_GPOCFG_GPOSEL_0;
43
44
45         pcf50633_gpio_set(gta02_pcf, PCF50633_GPO, val);
46
47         return count;
48 }
49
50 static DEVICE_ATTR(hostmode, 0644, pm_host_read, pm_host_write);
51
52 static struct attribute *gta02_pm_host_sysfs_entries[] = {
53         &dev_attr_hostmode.attr,
54         NULL
55 };
56
57 static struct attribute_group gta02_pm_host_attr_group = {
58         .name   = NULL,
59         .attrs  = gta02_pm_host_sysfs_entries,
60 };
61
62 static int __init gta02_pm_host_probe(struct platform_device *pdev)
63 {
64         dev_info(&pdev->dev, "starting\n");
65         return sysfs_create_group(&pdev->dev.kobj, &gta02_pm_host_attr_group);
66 }
67
68 static int gta02_pm_host_remove(struct platform_device *pdev)
69 {
70         sysfs_remove_group(&pdev->dev.kobj, &gta02_pm_host_attr_group);
71         return 0;
72 }
73
74 static struct platform_driver gta02_pm_host_driver = {
75         .probe          = gta02_pm_host_probe,
76         .remove         = gta02_pm_host_remove,
77         .driver         = {
78                 .name           = "gta02-pm-host",
79         },
80 };
81
82 static int __devinit gta02_pm_host_init(void)
83 {
84         return platform_driver_register(&gta02_pm_host_driver);
85 }
86
87 static void gta02_pm_host_exit(void)
88 {
89         platform_driver_unregister(&gta02_pm_host_driver);
90 }
91
92 module_init(gta02_pm_host_init);
93 module_exit(gta02_pm_host_exit);
94
95 MODULE_LICENSE("GPL");
96 MODULE_AUTHOR("Andy Green <andy@openmoko.com>");
97 MODULE_DESCRIPTION("Openmoko Freerunner USB Host Power Management");