Merge tag 'locks-v3.16-2' of git://git.samba.org/jlayton/linux
[linux/fpc-iii.git] / arch / arm / mach-s3c24xx / h1940-bluetooth.c
blobb4d14b86436727df47dce3bbe0d30db6c7e4e5ad
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>
22 #include <plat/gpio-cfg.h>
23 #include <mach/hardware.h>
24 #include <mach/regs-gpio.h>
25 #include <mach/gpio-samsung.h>
27 #include "h1940.h"
29 #define DRV_NAME "h1940-bt"
31 /* Bluetooth control */
32 static void h1940bt_enable(int on)
34 if (on) {
35 /* Power on the chip */
36 gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 1);
37 /* Reset the chip */
38 mdelay(10);
40 gpio_set_value(S3C2410_GPH(1), 1);
41 mdelay(10);
42 gpio_set_value(S3C2410_GPH(1), 0);
44 h1940_led_blink_set(-EINVAL, GPIO_LED_BLINK, NULL, NULL);
46 else {
47 gpio_set_value(S3C2410_GPH(1), 1);
48 mdelay(10);
49 gpio_set_value(S3C2410_GPH(1), 0);
50 mdelay(10);
51 gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 0);
53 h1940_led_blink_set(-EINVAL, GPIO_LED_NO_BLINK_LOW, NULL, NULL);
57 static int h1940bt_set_block(void *data, bool blocked)
59 h1940bt_enable(!blocked);
60 return 0;
63 static const struct rfkill_ops h1940bt_rfkill_ops = {
64 .set_block = h1940bt_set_block,
67 static int h1940bt_probe(struct platform_device *pdev)
69 struct rfkill *rfk;
70 int ret = 0;
72 ret = gpio_request(S3C2410_GPH(1), dev_name(&pdev->dev));
73 if (ret) {
74 dev_err(&pdev->dev, "could not get GPH1\n");
75 return ret;
78 ret = gpio_request(H1940_LATCH_BLUETOOTH_POWER, dev_name(&pdev->dev));
79 if (ret) {
80 gpio_free(S3C2410_GPH(1));
81 dev_err(&pdev->dev, "could not get BT_POWER\n");
82 return ret;
85 /* Configures BT serial port GPIOs */
86 s3c_gpio_cfgpin(S3C2410_GPH(0), S3C2410_GPH0_nCTS0);
87 s3c_gpio_setpull(S3C2410_GPH(0), S3C_GPIO_PULL_NONE);
88 s3c_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPIO_OUTPUT);
89 s3c_gpio_setpull(S3C2410_GPH(1), S3C_GPIO_PULL_NONE);
90 s3c_gpio_cfgpin(S3C2410_GPH(2), S3C2410_GPH2_TXD0);
91 s3c_gpio_setpull(S3C2410_GPH(2), S3C_GPIO_PULL_NONE);
92 s3c_gpio_cfgpin(S3C2410_GPH(3), S3C2410_GPH3_RXD0);
93 s3c_gpio_setpull(S3C2410_GPH(3), S3C_GPIO_PULL_NONE);
95 rfk = rfkill_alloc(DRV_NAME, &pdev->dev, RFKILL_TYPE_BLUETOOTH,
96 &h1940bt_rfkill_ops, NULL);
97 if (!rfk) {
98 ret = -ENOMEM;
99 goto err_rfk_alloc;
102 ret = rfkill_register(rfk);
103 if (ret)
104 goto err_rfkill;
106 platform_set_drvdata(pdev, rfk);
108 return 0;
110 err_rfkill:
111 rfkill_destroy(rfk);
112 err_rfk_alloc:
113 return ret;
116 static int h1940bt_remove(struct platform_device *pdev)
118 struct rfkill *rfk = platform_get_drvdata(pdev);
120 platform_set_drvdata(pdev, NULL);
121 gpio_free(S3C2410_GPH(1));
123 if (rfk) {
124 rfkill_unregister(rfk);
125 rfkill_destroy(rfk);
127 rfk = NULL;
129 h1940bt_enable(0);
131 return 0;
135 static struct platform_driver h1940bt_driver = {
136 .driver = {
137 .name = DRV_NAME,
139 .probe = h1940bt_probe,
140 .remove = h1940bt_remove,
143 module_platform_driver(h1940bt_driver);
145 MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
146 MODULE_DESCRIPTION("Driver for the iPAQ H1940 bluetooth chip");
147 MODULE_LICENSE("GPL");