blob: 5aabf117cbb01742fac3e340374c471e2fb60755 [file] [log] [blame]
Arnaud Patard7fdc7842007-05-09 21:41:03 +01001/*
2 * arch/arm/mach-s3c2410/h1940-bluetooth.c
3 * Copyright (c) Arnaud Patard <arnaud.patard@rtp-net.org>
4 *
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file COPYING in the main directory of this archive for
7 * more details.
8 *
9 * S3C2410 bluetooth "driver"
10 *
11 */
12
13#include <linux/module.h>
14#include <linux/platform_device.h>
15#include <linux/delay.h>
16#include <linux/string.h>
17#include <linux/ctype.h>
18#include <linux/leds.h>
Ben Dooksec976d62009-05-13 22:52:24 +010019#include <linux/gpio.h>
20
Russell Kinga09e64f2008-08-05 16:14:15 +010021#include <mach/regs-gpio.h>
22#include <mach/hardware.h>
23#include <mach/h1940-latch.h>
Arnaud Patard7fdc7842007-05-09 21:41:03 +010024
25#define DRV_NAME "h1940-bt"
26
27#ifdef CONFIG_LEDS_H1940
28DEFINE_LED_TRIGGER(bt_led_trigger);
29#endif
30
31static int state;
32
33/* Bluetooth control */
34static void h1940bt_enable(int on)
35{
36 if (on) {
37#ifdef CONFIG_LEDS_H1940
38 /* flashing Blue */
39 led_trigger_event(bt_led_trigger, LED_HALF);
40#endif
41
42 /* Power on the chip */
43 h1940_latch_control(0, H1940_LATCH_BLUETOOTH_POWER);
44 /* Reset the chip */
45 mdelay(10);
Ben Dooks070276d2009-05-17 22:32:23 +010046 s3c2410_gpio_setpin(S3C2410_GPH(1), 1);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010047 mdelay(10);
Ben Dooks070276d2009-05-17 22:32:23 +010048 s3c2410_gpio_setpin(S3C2410_GPH(1), 0);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010049
50 state = 1;
51 }
52 else {
53#ifdef CONFIG_LEDS_H1940
54 led_trigger_event(bt_led_trigger, 0);
55#endif
56
Ben Dooks070276d2009-05-17 22:32:23 +010057 s3c2410_gpio_setpin(S3C2410_GPH(1), 1);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010058 mdelay(10);
Ben Dooks070276d2009-05-17 22:32:23 +010059 s3c2410_gpio_setpin(S3C2410_GPH(1), 0);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010060 mdelay(10);
61 h1940_latch_control(H1940_LATCH_BLUETOOTH_POWER, 0);
62
63 state = 0;
64 }
65}
66
67static ssize_t h1940bt_show(struct device *dev, struct device_attribute *attr, char *buf)
68{
69 return snprintf(buf, PAGE_SIZE, "%d\n", state);
70}
71
72static ssize_t h1940bt_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
73{
74 int new_state;
75 char *endp;
76
77 new_state = simple_strtoul(buf, &endp, 0);
78 if (*endp && !isspace(*endp))
79 return -EINVAL;
80
81 h1940bt_enable(new_state);
82
83 return count;
84}
85static DEVICE_ATTR(enable, 0644,
86 h1940bt_show,
87 h1940bt_store);
88
89static int __init h1940bt_probe(struct platform_device *pdev)
90{
91 /* Configures BT serial port GPIOs */
Ben Dooks070276d2009-05-17 22:32:23 +010092 s3c2410_gpio_cfgpin(S3C2410_GPH(0), S3C2410_GPH0_nCTS0);
93 s3c2410_gpio_pullup(S3C2410_GPH(0), 1);
94 s3c2410_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPIO_OUTPUT);
95 s3c2410_gpio_pullup(S3C2410_GPH(1), 1);
96 s3c2410_gpio_cfgpin(S3C2410_GPH(2), S3C2410_GPH2_TXD0);
97 s3c2410_gpio_pullup(S3C2410_GPH(2), 1);
98 s3c2410_gpio_cfgpin(S3C2410_GPH(3), S3C2410_GPH3_RXD0);
99 s3c2410_gpio_pullup(S3C2410_GPH(3), 1);
Arnaud Patard7fdc7842007-05-09 21:41:03 +0100100
101#ifdef CONFIG_LEDS_H1940
102 led_trigger_register_simple("h1940-bluetooth", &bt_led_trigger);
103#endif
104
105 /* disable BT by default */
106 h1940bt_enable(0);
107
108 return device_create_file(&pdev->dev, &dev_attr_enable);
109}
110
111static int h1940bt_remove(struct platform_device *pdev)
112{
113#ifdef CONFIG_LEDS_H1940
114 led_trigger_unregister_simple(bt_led_trigger);
115#endif
116 return 0;
117}
118
119
120static struct platform_driver h1940bt_driver = {
121 .driver = {
122 .name = DRV_NAME,
123 },
124 .probe = h1940bt_probe,
125 .remove = h1940bt_remove,
126};
127
128
129static int __init h1940bt_init(void)
130{
131 return platform_driver_register(&h1940bt_driver);
132}
133
134static void __exit h1940bt_exit(void)
135{
136 platform_driver_unregister(&h1940bt_driver);
137}
138
139module_init(h1940bt_init);
140module_exit(h1940bt_exit);
141
142MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
143MODULE_DESCRIPTION("Driver for the iPAQ H1940 bluetooth chip");
144MODULE_LICENSE("GPL");