ext4: fix a race which could leak memory in ext4_groupinfo_create_slab()
[linux-2.6.git] / arch / arm / mach-s3c2410 / h1940-bluetooth.c
blob2c126bbca08da168f8c7d4fc76285dd141a27ba3
1 /*
2 * arch/arm/mach-s3c2410/h1940-bluetooth.c
3 * Copyright (c) Arnaud Patard <arnaud.patard@rtp-net.org>
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.
9 * S3C2410 bluetooth "driver"
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>
19 #include <linux/gpio.h>
20 #include <linux/rfkill.h>
21 #include <linux/leds.h>
23 #include <mach/regs-gpio.h>
24 #include <mach/hardware.h>
25 #include <mach/h1940-latch.h>
26 #include <mach/h1940.h>
28 #define DRV_NAME "h1940-bt"
30 /* Bluetooth control */
31 static void h1940bt_enable(int on)
33 if (on) {
34 /* Power on the chip */
35 gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 1);
36 /* Reset the chip */
37 mdelay(10);
39 gpio_set_value(S3C2410_GPH(1), 1);
40 mdelay(10);
41 gpio_set_value(S3C2410_GPH(1), 0);
43 h1940_led_blink_set(-EINVAL, GPIO_LED_BLINK, NULL, NULL);
45 else {
46 gpio_set_value(S3C2410_GPH(1), 1);
47 mdelay(10);
48 gpio_set_value(S3C2410_GPH(1), 0);
49 mdelay(10);
50 gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 0);
52 h1940_led_blink_set(-EINVAL, GPIO_LED_NO_BLINK_LOW, NULL, NULL);
56 static int h1940bt_set_block(void *data, bool blocked)
58 h1940bt_enable(!blocked);
59 return 0;
62 static const struct rfkill_ops h1940bt_rfkill_ops = {
63 .set_block = h1940bt_set_block,
66 static int __devinit h1940bt_probe(struct platform_device *pdev)
68 struct rfkill *rfk;
69 int ret = 0;
71 ret = gpio_request(S3C2410_GPH(1), dev_name(&pdev->dev));
72 if (ret) {
73 dev_err(&pdev->dev, "could not get GPH1\n");
74 return ret;
77 ret = gpio_request(H1940_LATCH_BLUETOOTH_POWER, dev_name(&pdev->dev));
78 if (ret) {
79 gpio_free(S3C2410_GPH(1));
80 dev_err(&pdev->dev, "could not get BT_POWER\n");
81 return ret;
84 /* Configures BT serial port GPIOs */
85 s3c_gpio_cfgpin(S3C2410_GPH(0), S3C2410_GPH0_nCTS0);
86 s3c_gpio_setpull(S3C2410_GPH(0), S3C_GPIO_PULL_NONE);
87 s3c_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPIO_OUTPUT);
88 s3c_gpio_setpull(S3C2410_GPH(1), S3C_GPIO_PULL_NONE);
89 s3c_gpio_cfgpin(S3C2410_GPH(2), S3C2410_GPH2_TXD0);
90 s3c_gpio_setpull(S3C2410_GPH(2), S3C_GPIO_PULL_NONE);
91 s3c_gpio_cfgpin(S3C2410_GPH(3), S3C2410_GPH3_RXD0);
92 s3c_gpio_setpull(S3C2410_GPH(3), S3C_GPIO_PULL_NONE);
94 rfk = rfkill_alloc(DRV_NAME, &pdev->dev, RFKILL_TYPE_BLUETOOTH,
95 &h1940bt_rfkill_ops, NULL);
96 if (!rfk) {
97 ret = -ENOMEM;
98 goto err_rfk_alloc;
101 ret = rfkill_register(rfk);
102 if (ret)
103 goto err_rfkill;
105 platform_set_drvdata(pdev, rfk);
107 return 0;
109 err_rfkill:
110 rfkill_destroy(rfk);
111 err_rfk_alloc:
112 return ret;
115 static int h1940bt_remove(struct platform_device *pdev)
117 struct rfkill *rfk = platform_get_drvdata(pdev);
119 platform_set_drvdata(pdev, NULL);
120 gpio_free(S3C2410_GPH(1));
122 if (rfk) {
123 rfkill_unregister(rfk);
124 rfkill_destroy(rfk);
126 rfk = NULL;
128 h1940bt_enable(0);
130 return 0;
134 static struct platform_driver h1940bt_driver = {
135 .driver = {
136 .name = DRV_NAME,
138 .probe = h1940bt_probe,
139 .remove = h1940bt_remove,
143 static int __init h1940bt_init(void)
145 return platform_driver_register(&h1940bt_driver);
148 static void __exit h1940bt_exit(void)
150 platform_driver_unregister(&h1940bt_driver);
153 module_init(h1940bt_init);
154 module_exit(h1940bt_exit);
156 MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
157 MODULE_DESCRIPTION("Driver for the iPAQ H1940 bluetooth chip");
158 MODULE_LICENSE("GPL");