ARM: s3c24xx: explicit dependency on <plat/gpio-cfg.h>
[deliverable/linux.git] / arch / arm / mach-s3c24xx / h1940-bluetooth.c
CommitLineData
7fdc7849
AP
1/*
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>
ec976d6e 19#include <linux/gpio.h>
1a71e4ad 20#include <linux/rfkill.h>
ec976d6e 21
36437412 22#include <plat/gpio-cfg.h>
a09e64fb 23#include <mach/hardware.h>
232910d6 24#include <mach/regs-gpio.h>
b0161caa 25#include <mach/gpio-samsung.h>
232910d6
KK
26
27#include "h1940.h"
7fdc7849 28
50e2d10d 29#define DRV_NAME "h1940-bt"
7fdc7849 30
7fdc7849
AP
31/* Bluetooth control */
32static void h1940bt_enable(int on)
33{
34 if (on) {
7fdc7849 35 /* Power on the chip */
14477095 36 gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 1);
7fdc7849
AP
37 /* Reset the chip */
38 mdelay(10);
f4146a65
BD
39
40 gpio_set_value(S3C2410_GPH(1), 1);
7fdc7849 41 mdelay(10);
f4146a65 42 gpio_set_value(S3C2410_GPH(1), 0);
50e2d10d
VK
43
44 h1940_led_blink_set(-EINVAL, GPIO_LED_BLINK, NULL, NULL);
7fdc7849
AP
45 }
46 else {
f4146a65 47 gpio_set_value(S3C2410_GPH(1), 1);
7fdc7849 48 mdelay(10);
f4146a65 49 gpio_set_value(S3C2410_GPH(1), 0);
7fdc7849 50 mdelay(10);
14477095 51 gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 0);
50e2d10d
VK
52
53 h1940_led_blink_set(-EINVAL, GPIO_LED_NO_BLINK_LOW, NULL, NULL);
7fdc7849
AP
54 }
55}
56
1a71e4ad 57static int h1940bt_set_block(void *data, bool blocked)
7fdc7849 58{
1a71e4ad 59 h1940bt_enable(!blocked);
60 return 0;
7fdc7849
AP
61}
62
1a71e4ad 63static const struct rfkill_ops h1940bt_rfkill_ops = {
64 .set_block = h1940bt_set_block,
65};
7fdc7849 66
351a102d 67static int h1940bt_probe(struct platform_device *pdev)
7fdc7849 68{
1a71e4ad 69 struct rfkill *rfk;
70 int ret = 0;
71
f4146a65
BD
72 ret = gpio_request(S3C2410_GPH(1), dev_name(&pdev->dev));
73 if (ret) {
14477095
VK
74 dev_err(&pdev->dev, "could not get GPH1\n");
75 return ret;
76 }
77
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");
f4146a65
BD
82 return ret;
83 }
84
7fdc7849 85 /* Configures BT serial port GPIOs */
40b956f0 86 s3c_gpio_cfgpin(S3C2410_GPH(0), S3C2410_GPH0_nCTS0);
6fc50eaf 87 s3c_gpio_setpull(S3C2410_GPH(0), S3C_GPIO_PULL_NONE);
40b956f0 88 s3c_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPIO_OUTPUT);
6fc50eaf 89 s3c_gpio_setpull(S3C2410_GPH(1), S3C_GPIO_PULL_NONE);
40b956f0 90 s3c_gpio_cfgpin(S3C2410_GPH(2), S3C2410_GPH2_TXD0);
6fc50eaf 91 s3c_gpio_setpull(S3C2410_GPH(2), S3C_GPIO_PULL_NONE);
40b956f0 92 s3c_gpio_cfgpin(S3C2410_GPH(3), S3C2410_GPH3_RXD0);
6fc50eaf 93 s3c_gpio_setpull(S3C2410_GPH(3), S3C_GPIO_PULL_NONE);
7fdc7849 94
1a71e4ad 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;
100 }
101
1a71e4ad 102 ret = rfkill_register(rfk);
103 if (ret)
104 goto err_rfkill;
105
106 platform_set_drvdata(pdev, rfk);
107
108 return 0;
7fdc7849 109
1a71e4ad 110err_rfkill:
111 rfkill_destroy(rfk);
112err_rfk_alloc:
113 return ret;
7fdc7849
AP
114}
115
116static int h1940bt_remove(struct platform_device *pdev)
117{
1a71e4ad 118 struct rfkill *rfk = platform_get_drvdata(pdev);
119
120 platform_set_drvdata(pdev, NULL);
f4146a65 121 gpio_free(S3C2410_GPH(1));
1a71e4ad 122
123 if (rfk) {
124 rfkill_unregister(rfk);
125 rfkill_destroy(rfk);
126 }
127 rfk = NULL;
128
129 h1940bt_enable(0);
130
7fdc7849
AP
131 return 0;
132}
133
134
135static struct platform_driver h1940bt_driver = {
136 .driver = {
137 .name = DRV_NAME,
138 },
139 .probe = h1940bt_probe,
140 .remove = h1940bt_remove,
141};
142
1fffc8b2 143module_platform_driver(h1940bt_driver);
7fdc7849
AP
144
145MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
146MODULE_DESCRIPTION("Driver for the iPAQ H1940 bluetooth chip");
147MODULE_LICENSE("GPL");
This page took 0.53243 seconds and 5 git commands to generate.