blob: 2c126bbca08da168f8c7d4fc76285dd141a27ba3 [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>
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +010020#include <linux/rfkill.h>
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +020021#include <linux/leds.h>
Ben Dooksec976d62009-05-13 22:52:24 +010022
Russell Kinga09e64f2008-08-05 16:14:15 +010023#include <mach/regs-gpio.h>
24#include <mach/hardware.h>
25#include <mach/h1940-latch.h>
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +020026#include <mach/h1940.h>
Arnaud Patard7fdc7842007-05-09 21:41:03 +010027
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +020028#define DRV_NAME "h1940-bt"
Arnaud Patard7fdc7842007-05-09 21:41:03 +010029
Arnaud Patard7fdc7842007-05-09 21:41:03 +010030/* Bluetooth control */
31static void h1940bt_enable(int on)
32{
33 if (on) {
Arnaud Patard7fdc7842007-05-09 21:41:03 +010034 /* Power on the chip */
Vasily Khoruzhick14477092010-09-08 12:39:46 +030035 gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 1);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010036 /* Reset the chip */
37 mdelay(10);
Ben Dooksf4146a62010-05-04 11:23:05 +090038
39 gpio_set_value(S3C2410_GPH(1), 1);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010040 mdelay(10);
Ben Dooksf4146a62010-05-04 11:23:05 +090041 gpio_set_value(S3C2410_GPH(1), 0);
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +020042
43 h1940_led_blink_set(-EINVAL, GPIO_LED_BLINK, NULL, NULL);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010044 }
45 else {
Ben Dooksf4146a62010-05-04 11:23:05 +090046 gpio_set_value(S3C2410_GPH(1), 1);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010047 mdelay(10);
Ben Dooksf4146a62010-05-04 11:23:05 +090048 gpio_set_value(S3C2410_GPH(1), 0);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010049 mdelay(10);
Vasily Khoruzhick14477092010-09-08 12:39:46 +030050 gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 0);
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +020051
52 h1940_led_blink_set(-EINVAL, GPIO_LED_NO_BLINK_LOW, NULL, NULL);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010053 }
54}
55
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +010056static int h1940bt_set_block(void *data, bool blocked)
Arnaud Patard7fdc7842007-05-09 21:41:03 +010057{
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +010058 h1940bt_enable(!blocked);
59 return 0;
Arnaud Patard7fdc7842007-05-09 21:41:03 +010060}
61
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +010062static const struct rfkill_ops h1940bt_rfkill_ops = {
63 .set_block = h1940bt_set_block,
64};
Arnaud Patard7fdc7842007-05-09 21:41:03 +010065
Uwe Kleine-König91a99df2010-02-04 20:56:49 +010066static int __devinit h1940bt_probe(struct platform_device *pdev)
Arnaud Patard7fdc7842007-05-09 21:41:03 +010067{
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +010068 struct rfkill *rfk;
69 int ret = 0;
70
Ben Dooksf4146a62010-05-04 11:23:05 +090071 ret = gpio_request(S3C2410_GPH(1), dev_name(&pdev->dev));
72 if (ret) {
Vasily Khoruzhick14477092010-09-08 12:39:46 +030073 dev_err(&pdev->dev, "could not get GPH1\n");
74 return ret;
75 }
76
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");
Ben Dooksf4146a62010-05-04 11:23:05 +090081 return ret;
82 }
83
Arnaud Patard7fdc7842007-05-09 21:41:03 +010084 /* Configures BT serial port GPIOs */
Ben Dooks40b956f2010-05-04 14:38:49 +090085 s3c_gpio_cfgpin(S3C2410_GPH(0), S3C2410_GPH0_nCTS0);
Vasily Khoruzhick6fc50ea2010-11-16 18:11:59 +090086 s3c_gpio_setpull(S3C2410_GPH(0), S3C_GPIO_PULL_NONE);
Ben Dooks40b956f2010-05-04 14:38:49 +090087 s3c_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPIO_OUTPUT);
Vasily Khoruzhick6fc50ea2010-11-16 18:11:59 +090088 s3c_gpio_setpull(S3C2410_GPH(1), S3C_GPIO_PULL_NONE);
Ben Dooks40b956f2010-05-04 14:38:49 +090089 s3c_gpio_cfgpin(S3C2410_GPH(2), S3C2410_GPH2_TXD0);
Vasily Khoruzhick6fc50ea2010-11-16 18:11:59 +090090 s3c_gpio_setpull(S3C2410_GPH(2), S3C_GPIO_PULL_NONE);
Ben Dooks40b956f2010-05-04 14:38:49 +090091 s3c_gpio_cfgpin(S3C2410_GPH(3), S3C2410_GPH3_RXD0);
Vasily Khoruzhick6fc50ea2010-11-16 18:11:59 +090092 s3c_gpio_setpull(S3C2410_GPH(3), S3C_GPIO_PULL_NONE);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010093
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +010094 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;
99 }
Arnaud Patard7fdc7842007-05-09 21:41:03 +0100100
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +0100101 ret = rfkill_register(rfk);
102 if (ret)
103 goto err_rfkill;
104
105 platform_set_drvdata(pdev, rfk);
106
107 return 0;
108
109err_rfkill:
110 rfkill_destroy(rfk);
111err_rfk_alloc:
112 return ret;
Arnaud Patard7fdc7842007-05-09 21:41:03 +0100113}
114
115static int h1940bt_remove(struct platform_device *pdev)
116{
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +0100117 struct rfkill *rfk = platform_get_drvdata(pdev);
118
119 platform_set_drvdata(pdev, NULL);
Ben Dooksf4146a62010-05-04 11:23:05 +0900120 gpio_free(S3C2410_GPH(1));
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +0100121
122 if (rfk) {
123 rfkill_unregister(rfk);
124 rfkill_destroy(rfk);
125 }
126 rfk = NULL;
127
128 h1940bt_enable(0);
129
Arnaud Patard7fdc7842007-05-09 21:41:03 +0100130 return 0;
131}
132
133
134static struct platform_driver h1940bt_driver = {
135 .driver = {
136 .name = DRV_NAME,
137 },
138 .probe = h1940bt_probe,
139 .remove = h1940bt_remove,
140};
141
142
143static int __init h1940bt_init(void)
144{
145 return platform_driver_register(&h1940bt_driver);
146}
147
148static void __exit h1940bt_exit(void)
149{
150 platform_driver_unregister(&h1940bt_driver);
151}
152
153module_init(h1940bt_init);
154module_exit(h1940bt_exit);
155
156MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
157MODULE_DESCRIPTION("Driver for the iPAQ H1940 bluetooth chip");
158MODULE_LICENSE("GPL");