aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/extcon/extcon_class.c12
-rw-r--r--drivers/staging/android/Kconfig3
-rw-r--r--drivers/staging/android/Makefile1
-rw-r--r--drivers/staging/android/switch/Kconfig11
-rw-r--r--drivers/staging/android/switch/Makefile4
-rw-r--r--drivers/staging/android/switch/switch.h53
-rw-r--r--drivers/staging/android/switch/switch_class.c174
-rw-r--r--drivers/staging/android/switch/switch_gpio.c172
8 files changed, 6 insertions, 424 deletions
diff --git a/drivers/extcon/extcon_class.c b/drivers/extcon/extcon_class.c
index 3bc4b8af46cf..dbd3bfba42da 100644
--- a/drivers/extcon/extcon_class.c
+++ b/drivers/extcon/extcon_class.c
@@ -65,9 +65,9 @@ const char *extcon_cable_name[] = {
65}; 65};
66 66
67struct class *extcon_class; 67struct class *extcon_class;
68#if defined(CONFIG_ANDROID) && !defined(CONFIG_ANDROID_SWITCH) 68#if defined(CONFIG_ANDROID)
69static struct class_compat *switch_class; 69static struct class_compat *switch_class;
70#endif /* CONFIG_ANDROID && !defined(CONFIG_ANDROID_SWITCH) */ 70#endif /* CONFIG_ANDROID */
71 71
72static LIST_HEAD(extcon_dev_list); 72static LIST_HEAD(extcon_dev_list);
73static DEFINE_MUTEX(extcon_dev_list_lock); 73static DEFINE_MUTEX(extcon_dev_list_lock);
@@ -532,11 +532,11 @@ static int create_extcon_class(void)
532 return PTR_ERR(extcon_class); 532 return PTR_ERR(extcon_class);
533 extcon_class->dev_attrs = extcon_attrs; 533 extcon_class->dev_attrs = extcon_attrs;
534 534
535#if defined(CONFIG_ANDROID) && !defined(CONFIG_ANDROID_SWITCH) 535#if defined(CONFIG_ANDROID)
536 switch_class = class_compat_register("switch"); 536 switch_class = class_compat_register("switch");
537 if (WARN(!switch_class, "cannot allocate")) 537 if (WARN(!switch_class, "cannot allocate"))
538 return -ENOMEM; 538 return -ENOMEM;
539#endif /* CONFIG_ANDROID && !defined(CONFIG_ANDROID_SWITCH) */ 539#endif /* CONFIG_ANDROID */
540 } 540 }
541 541
542 return 0; 542 return 0;
@@ -749,11 +749,11 @@ int extcon_dev_register(struct extcon_dev *edev, struct device *dev)
749 put_device(edev->dev); 749 put_device(edev->dev);
750 goto err_dev; 750 goto err_dev;
751 } 751 }
752#if defined(CONFIG_ANDROID) && !defined(CONFIG_ANDROID_SWITCH) 752#if defined(CONFIG_ANDROID)
753 if (switch_class) 753 if (switch_class)
754 ret = class_compat_create_link(switch_class, edev->dev, 754 ret = class_compat_create_link(switch_class, edev->dev,
755 dev); 755 dev);
756#endif /* CONFIG_ANDROID && !defined(CONFIG_ANDROID_SWITCH) */ 756#endif /* CONFIG_ANDROID */
757 757
758 spin_lock_init(&edev->lock); 758 spin_lock_init(&edev->lock);
759 759
diff --git a/drivers/staging/android/Kconfig b/drivers/staging/android/Kconfig
index 08a3b1133d29..60dc7108c8b3 100644
--- a/drivers/staging/android/Kconfig
+++ b/drivers/staging/android/Kconfig
@@ -52,8 +52,6 @@ config ANDROID_LOW_MEMORY_KILLER
52 ---help--- 52 ---help---
53 Register processes to be killed when memory is low 53 Register processes to be killed when memory is low
54 54
55source "drivers/staging/android/switch/Kconfig"
56
57config ANDROID_INTF_ALARM 55config ANDROID_INTF_ALARM
58 bool "Android alarm driver" 56 bool "Android alarm driver"
59 depends on RTC_CLASS 57 depends on RTC_CLASS
@@ -79,7 +77,6 @@ config ANDROID_ALARM_OLDDRV_COMPAT
79 Provides preprocessor alias to aid compatability with 77 Provides preprocessor alias to aid compatability with
80 older out-of-tree drivers that use the Android Alarm 78 older out-of-tree drivers that use the Android Alarm
81 in-kernel API. This will be removed eventually. 79 in-kernel API. This will be removed eventually.
82
83endif # if ANDROID 80endif # if ANDROID
84 81
85endmenu 82endmenu
diff --git a/drivers/staging/android/Makefile b/drivers/staging/android/Makefile
index 9b6c9ed91f69..045d17bde524 100644
--- a/drivers/staging/android/Makefile
+++ b/drivers/staging/android/Makefile
@@ -6,6 +6,5 @@ obj-$(CONFIG_ANDROID_RAM_CONSOLE) += ram_console.o
6obj-$(CONFIG_ANDROID_TIMED_OUTPUT) += timed_output.o 6obj-$(CONFIG_ANDROID_TIMED_OUTPUT) += timed_output.o
7obj-$(CONFIG_ANDROID_TIMED_GPIO) += timed_gpio.o 7obj-$(CONFIG_ANDROID_TIMED_GPIO) += timed_gpio.o
8obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER) += lowmemorykiller.o 8obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER) += lowmemorykiller.o
9obj-$(CONFIG_ANDROID_SWITCH) += switch/
10obj-$(CONFIG_ANDROID_INTF_ALARM) += alarm.o 9obj-$(CONFIG_ANDROID_INTF_ALARM) += alarm.o
11obj-$(CONFIG_ANDROID_INTF_ALARM_DEV) += alarm-dev.o 10obj-$(CONFIG_ANDROID_INTF_ALARM_DEV) += alarm-dev.o
diff --git a/drivers/staging/android/switch/Kconfig b/drivers/staging/android/switch/Kconfig
deleted file mode 100644
index 36846f62f4bc..000000000000
--- a/drivers/staging/android/switch/Kconfig
+++ /dev/null
@@ -1,11 +0,0 @@
1menuconfig ANDROID_SWITCH
2 tristate "Android Switch class support"
3 help
4 Say Y here to enable Android switch class support. This allows
5 monitoring switches by userspace via sysfs and uevent.
6
7config ANDROID_SWITCH_GPIO
8 tristate "Android GPIO Switch support"
9 depends on GENERIC_GPIO && ANDROID_SWITCH
10 help
11 Say Y here to enable GPIO based switch support.
diff --git a/drivers/staging/android/switch/Makefile b/drivers/staging/android/switch/Makefile
deleted file mode 100644
index d76bfdcedfaf..000000000000
--- a/drivers/staging/android/switch/Makefile
+++ /dev/null
@@ -1,4 +0,0 @@
1# Android Switch Class Driver
2obj-$(CONFIG_ANDROID_SWITCH) += switch_class.o
3obj-$(CONFIG_ANDROID_SWITCH_GPIO) += switch_gpio.o
4
diff --git a/drivers/staging/android/switch/switch.h b/drivers/staging/android/switch/switch.h
deleted file mode 100644
index 4fcb3109875a..000000000000
--- a/drivers/staging/android/switch/switch.h
+++ /dev/null
@@ -1,53 +0,0 @@
1/*
2 * Switch class driver
3 *
4 * Copyright (C) 2008 Google, Inc.
5 * Author: Mike Lockwood <lockwood@android.com>
6 *
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16*/
17
18#ifndef __LINUX_SWITCH_H__
19#define __LINUX_SWITCH_H__
20
21struct switch_dev {
22 const char *name;
23 struct device *dev;
24 int index;
25 int state;
26
27 ssize_t (*print_name)(struct switch_dev *sdev, char *buf);
28 ssize_t (*print_state)(struct switch_dev *sdev, char *buf);
29};
30
31struct gpio_switch_platform_data {
32 const char *name;
33 unsigned gpio;
34
35 /* if NULL, switch_dev.name will be printed */
36 const char *name_on;
37 const char *name_off;
38 /* if NULL, "0" or "1" will be printed */
39 const char *state_on;
40 const char *state_off;
41};
42
43extern int switch_dev_register(struct switch_dev *sdev);
44extern void switch_dev_unregister(struct switch_dev *sdev);
45
46static inline int switch_get_state(struct switch_dev *sdev)
47{
48 return sdev->state;
49}
50
51extern void switch_set_state(struct switch_dev *sdev, int state);
52
53#endif /* __LINUX_SWITCH_H__ */
diff --git a/drivers/staging/android/switch/switch_class.c b/drivers/staging/android/switch/switch_class.c
deleted file mode 100644
index 74680446fc66..000000000000
--- a/drivers/staging/android/switch/switch_class.c
+++ /dev/null
@@ -1,174 +0,0 @@
1/*
2 * switch_class.c
3 *
4 * Copyright (C) 2008 Google, Inc.
5 * Author: Mike Lockwood <lockwood@android.com>
6 *
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16*/
17
18#include <linux/module.h>
19#include <linux/types.h>
20#include <linux/init.h>
21#include <linux/device.h>
22#include <linux/fs.h>
23#include <linux/err.h>
24#include "switch.h"
25
26struct class *switch_class;
27static atomic_t device_count;
28
29static ssize_t state_show(struct device *dev, struct device_attribute *attr,
30 char *buf)
31{
32 struct switch_dev *sdev = (struct switch_dev *)
33 dev_get_drvdata(dev);
34
35 if (sdev->print_state) {
36 int ret = sdev->print_state(sdev, buf);
37 if (ret >= 0)
38 return ret;
39 }
40 return sprintf(buf, "%d\n", sdev->state);
41}
42
43static ssize_t name_show(struct device *dev, struct device_attribute *attr,
44 char *buf)
45{
46 struct switch_dev *sdev = (struct switch_dev *)
47 dev_get_drvdata(dev);
48
49 if (sdev->print_name) {
50 int ret = sdev->print_name(sdev, buf);
51 if (ret >= 0)
52 return ret;
53 }
54 return sprintf(buf, "%s\n", sdev->name);
55}
56
57static DEVICE_ATTR(state, S_IRUGO | S_IWUSR, state_show, NULL);
58static DEVICE_ATTR(name, S_IRUGO | S_IWUSR, name_show, NULL);
59
60void switch_set_state(struct switch_dev *sdev, int state)
61{
62 char name_buf[120];
63 char state_buf[120];
64 char *prop_buf;
65 char *envp[3];
66 int env_offset = 0;
67 int length;
68
69 if (sdev->state != state) {
70 sdev->state = state;
71
72 prop_buf = (char *)get_zeroed_page(GFP_KERNEL);
73 if (prop_buf) {
74 length = name_show(sdev->dev, NULL, prop_buf);
75 if (length > 0) {
76 if (prop_buf[length - 1] == '\n')
77 prop_buf[length - 1] = 0;
78 snprintf(name_buf, sizeof(name_buf),
79 "SWITCH_NAME=%s", prop_buf);
80 envp[env_offset++] = name_buf;
81 }
82 length = state_show(sdev->dev, NULL, prop_buf);
83 if (length > 0) {
84 if (prop_buf[length - 1] == '\n')
85 prop_buf[length - 1] = 0;
86 snprintf(state_buf, sizeof(state_buf),
87 "SWITCH_STATE=%s", prop_buf);
88 envp[env_offset++] = state_buf;
89 }
90 envp[env_offset] = NULL;
91 kobject_uevent_env(&sdev->dev->kobj, KOBJ_CHANGE, envp);
92 free_page((unsigned long)prop_buf);
93 } else {
94 printk(KERN_ERR "out of memory in switch_set_state\n");
95 kobject_uevent(&sdev->dev->kobj, KOBJ_CHANGE);
96 }
97 }
98}
99EXPORT_SYMBOL_GPL(switch_set_state);
100
101static int create_switch_class(void)
102{
103 if (!switch_class) {
104 switch_class = class_create(THIS_MODULE, "switch");
105 if (IS_ERR(switch_class))
106 return PTR_ERR(switch_class);
107 atomic_set(&device_count, 0);
108 }
109
110 return 0;
111}
112
113int switch_dev_register(struct switch_dev *sdev)
114{
115 int ret;
116
117 if (!switch_class) {
118 ret = create_switch_class();
119 if (ret < 0)
120 return ret;
121 }
122
123 sdev->index = atomic_inc_return(&device_count);
124 sdev->dev = device_create(switch_class, NULL,
125 MKDEV(0, sdev->index), NULL, sdev->name);
126 if (IS_ERR(sdev->dev))
127 return PTR_ERR(sdev->dev);
128
129 ret = device_create_file(sdev->dev, &dev_attr_state);
130 if (ret < 0)
131 goto err_create_file_1;
132 ret = device_create_file(sdev->dev, &dev_attr_name);
133 if (ret < 0)
134 goto err_create_file_2;
135
136 dev_set_drvdata(sdev->dev, sdev);
137 sdev->state = 0;
138 return 0;
139
140err_create_file_2:
141 device_remove_file(sdev->dev, &dev_attr_state);
142err_create_file_1:
143 device_destroy(switch_class, MKDEV(0, sdev->index));
144 printk(KERN_ERR "switch: Failed to register driver %s\n", sdev->name);
145
146 return ret;
147}
148EXPORT_SYMBOL_GPL(switch_dev_register);
149
150void switch_dev_unregister(struct switch_dev *sdev)
151{
152 device_remove_file(sdev->dev, &dev_attr_name);
153 device_remove_file(sdev->dev, &dev_attr_state);
154 device_destroy(switch_class, MKDEV(0, sdev->index));
155 dev_set_drvdata(sdev->dev, NULL);
156}
157EXPORT_SYMBOL_GPL(switch_dev_unregister);
158
159static int __init switch_class_init(void)
160{
161 return create_switch_class();
162}
163
164static void __exit switch_class_exit(void)
165{
166 class_destroy(switch_class);
167}
168
169module_init(switch_class_init);
170module_exit(switch_class_exit);
171
172MODULE_AUTHOR("Mike Lockwood <lockwood@android.com>");
173MODULE_DESCRIPTION("Switch class driver");
174MODULE_LICENSE("GPL");
diff --git a/drivers/staging/android/switch/switch_gpio.c b/drivers/staging/android/switch/switch_gpio.c
deleted file mode 100644
index 38b2c2f6004e..000000000000
--- a/drivers/staging/android/switch/switch_gpio.c
+++ /dev/null
@@ -1,172 +0,0 @@
1/*
2 * switch_gpio.c
3 *
4 * Copyright (C) 2008 Google, Inc.
5 * Author: Mike Lockwood <lockwood@android.com>
6 *
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16*/
17
18#include <linux/module.h>
19#include <linux/kernel.h>
20#include <linux/init.h>
21#include <linux/interrupt.h>
22#include <linux/platform_device.h>
23#include <linux/slab.h>
24#include <linux/workqueue.h>
25#include <linux/gpio.h>
26#include "switch.h"
27
28struct gpio_switch_data {
29 struct switch_dev sdev;
30 unsigned gpio;
31 const char *name_on;
32 const char *name_off;
33 const char *state_on;
34 const char *state_off;
35 int irq;
36 struct work_struct work;
37};
38
39static void gpio_switch_work(struct work_struct *work)
40{
41 int state;
42 struct gpio_switch_data *data =
43 container_of(work, struct gpio_switch_data, work);
44
45 state = gpio_get_value(data->gpio);
46 switch_set_state(&data->sdev, state);
47}
48
49static irqreturn_t gpio_irq_handler(int irq, void *dev_id)
50{
51 struct gpio_switch_data *switch_data =
52 (struct gpio_switch_data *)dev_id;
53
54 schedule_work(&switch_data->work);
55 return IRQ_HANDLED;
56}
57
58static ssize_t switch_gpio_print_state(struct switch_dev *sdev, char *buf)
59{
60 struct gpio_switch_data *switch_data =
61 container_of(sdev, struct gpio_switch_data, sdev);
62 const char *state;
63 if (switch_get_state(sdev))
64 state = switch_data->state_on;
65 else
66 state = switch_data->state_off;
67
68 if (state)
69 return sprintf(buf, "%s\n", state);
70 return -1;
71}
72
73static int gpio_switch_probe(struct platform_device *pdev)
74{
75 struct gpio_switch_platform_data *pdata = pdev->dev.platform_data;
76 struct gpio_switch_data *switch_data;
77 int ret = 0;
78
79 if (!pdata)
80 return -EBUSY;
81
82 switch_data = kzalloc(sizeof(struct gpio_switch_data), GFP_KERNEL);
83 if (!switch_data)
84 return -ENOMEM;
85
86 switch_data->sdev.name = pdata->name;
87 switch_data->gpio = pdata->gpio;
88 switch_data->name_on = pdata->name_on;
89 switch_data->name_off = pdata->name_off;
90 switch_data->state_on = pdata->state_on;
91 switch_data->state_off = pdata->state_off;
92 switch_data->sdev.print_state = switch_gpio_print_state;
93
94 ret = switch_dev_register(&switch_data->sdev);
95 if (ret < 0)
96 goto err_switch_dev_register;
97
98 ret = gpio_request(switch_data->gpio, pdev->name);
99 if (ret < 0)
100 goto err_request_gpio;
101
102 ret = gpio_direction_input(switch_data->gpio);
103 if (ret < 0)
104 goto err_set_gpio_input;
105
106 INIT_WORK(&switch_data->work, gpio_switch_work);
107
108 switch_data->irq = gpio_to_irq(switch_data->gpio);
109 if (switch_data->irq < 0) {
110 ret = switch_data->irq;
111 goto err_detect_irq_num_failed;
112 }
113
114 ret = request_irq(switch_data->irq, gpio_irq_handler,
115 IRQF_TRIGGER_LOW, pdev->name, switch_data);
116 if (ret < 0)
117 goto err_request_irq;
118
119 /* Perform initial detection */
120 gpio_switch_work(&switch_data->work);
121
122 return 0;
123
124err_request_irq:
125err_detect_irq_num_failed:
126err_set_gpio_input:
127 gpio_free(switch_data->gpio);
128err_request_gpio:
129 switch_dev_unregister(&switch_data->sdev);
130err_switch_dev_register:
131 kfree(switch_data);
132
133 return ret;
134}
135
136static int __devexit gpio_switch_remove(struct platform_device *pdev)
137{
138 struct gpio_switch_data *switch_data = platform_get_drvdata(pdev);
139
140 cancel_work_sync(&switch_data->work);
141 gpio_free(switch_data->gpio);
142 switch_dev_unregister(&switch_data->sdev);
143 kfree(switch_data);
144
145 return 0;
146}
147
148static struct platform_driver gpio_switch_driver = {
149 .probe = gpio_switch_probe,
150 .remove = __devexit_p(gpio_switch_remove),
151 .driver = {
152 .name = "switch-gpio",
153 .owner = THIS_MODULE,
154 },
155};
156
157static int __init gpio_switch_init(void)
158{
159 return platform_driver_register(&gpio_switch_driver);
160}
161
162static void __exit gpio_switch_exit(void)
163{
164 platform_driver_unregister(&gpio_switch_driver);
165}
166
167module_init(gpio_switch_init);
168module_exit(gpio_switch_exit);
169
170MODULE_AUTHOR("Mike Lockwood <lockwood@android.com>");
171MODULE_DESCRIPTION("GPIO Switch driver");
172MODULE_LICENSE("GPL");