blob: 5b98bfd1df43f576a1e97e5542a791fbd95567a6 [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>
Ben Dooksec976d62009-05-13 22:52:24 +010021
Russell Kinga09e64f2008-08-05 16:14:15 +010022#include <mach/hardware.h>
Kukjin Kim232910d2013-01-02 10:18:58 -080023#include <mach/regs-gpio.h>
24
25#include "h1940.h"
Arnaud Patard7fdc7842007-05-09 21:41:03 +010026
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +020027#define DRV_NAME "h1940-bt"
Arnaud Patard7fdc7842007-05-09 21:41:03 +010028
Arnaud Patard7fdc7842007-05-09 21:41:03 +010029/* Bluetooth control */
30static void h1940bt_enable(int on)
31{
32 if (on) {
Arnaud Patard7fdc7842007-05-09 21:41:03 +010033 /* Power on the chip */
Vasily Khoruzhick14477092010-09-08 12:39:46 +030034 gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 1);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010035 /* Reset the chip */
36 mdelay(10);
Ben Dooksf4146a62010-05-04 11:23:05 +090037
38 gpio_set_value(S3C2410_GPH(1), 1);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010039 mdelay(10);
Ben Dooksf4146a62010-05-04 11:23:05 +090040 gpio_set_value(S3C2410_GPH(1), 0);
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +020041
42 h1940_led_blink_set(-EINVAL, GPIO_LED_BLINK, NULL, NULL);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010043 }
44 else {
Ben Dooksf4146a62010-05-04 11:23:05 +090045 gpio_set_value(S3C2410_GPH(1), 1);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010046 mdelay(10);
Ben Dooksf4146a62010-05-04 11:23:05 +090047 gpio_set_value(S3C2410_GPH(1), 0);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010048 mdelay(10);
Vasily Khoruzhick14477092010-09-08 12:39:46 +030049 gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 0);
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +020050
51 h1940_led_blink_set(-EINVAL, GPIO_LED_NO_BLINK_LOW, NULL, NULL);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010052 }
53}
54
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +010055static int h1940bt_set_block(void *data, bool blocked)
Arnaud Patard7fdc7842007-05-09 21:41:03 +010056{
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +010057 h1940bt_enable(!blocked);
58 return 0;
Arnaud Patard7fdc7842007-05-09 21:41:03 +010059}
60
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +010061static const struct rfkill_ops h1940bt_rfkill_ops = {
62 .set_block = h1940bt_set_block,
63};
Arnaud Patard7fdc7842007-05-09 21:41:03 +010064
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -080065static int h1940bt_probe(struct platform_device *pdev)
Arnaud Patard7fdc7842007-05-09 21:41:03 +010066{
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +010067 struct rfkill *rfk;
68 int ret = 0;
69
Ben Dooksf4146a62010-05-04 11:23:05 +090070 ret = gpio_request(S3C2410_GPH(1), dev_name(&pdev->dev));
71 if (ret) {
Vasily Khoruzhick14477092010-09-08 12:39:46 +030072 dev_err(&pdev->dev, "could not get GPH1\n");
73 return ret;
74 }
75
76 ret = gpio_request(H1940_LATCH_BLUETOOTH_POWER, dev_name(&pdev->dev));
77 if (ret) {
78 gpio_free(S3C2410_GPH(1));
79 dev_err(&pdev->dev, "could not get BT_POWER\n");
Ben Dooksf4146a62010-05-04 11:23:05 +090080 return ret;
81 }
82
Arnaud Patard7fdc7842007-05-09 21:41:03 +010083 /* Configures BT serial port GPIOs */
Ben Dooks40b956f2010-05-04 14:38:49 +090084 s3c_gpio_cfgpin(S3C2410_GPH(0), S3C2410_GPH0_nCTS0);
Vasily Khoruzhick6fc50ea2010-11-16 18:11:59 +090085 s3c_gpio_setpull(S3C2410_GPH(0), S3C_GPIO_PULL_NONE);
Ben Dooks40b956f2010-05-04 14:38:49 +090086 s3c_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPIO_OUTPUT);
Vasily Khoruzhick6fc50ea2010-11-16 18:11:59 +090087 s3c_gpio_setpull(S3C2410_GPH(1), S3C_GPIO_PULL_NONE);
Ben Dooks40b956f2010-05-04 14:38:49 +090088 s3c_gpio_cfgpin(S3C2410_GPH(2), S3C2410_GPH2_TXD0);
Vasily Khoruzhick6fc50ea2010-11-16 18:11:59 +090089 s3c_gpio_setpull(S3C2410_GPH(2), S3C_GPIO_PULL_NONE);
Ben Dooks40b956f2010-05-04 14:38:49 +090090 s3c_gpio_cfgpin(S3C2410_GPH(3), S3C2410_GPH3_RXD0);
Vasily Khoruzhick6fc50ea2010-11-16 18:11:59 +090091 s3c_gpio_setpull(S3C2410_GPH(3), S3C_GPIO_PULL_NONE);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010092
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +010093 rfk = rfkill_alloc(DRV_NAME, &pdev->dev, RFKILL_TYPE_BLUETOOTH,
94 &h1940bt_rfkill_ops, NULL);
95 if (!rfk) {
96 ret = -ENOMEM;
97 goto err_rfk_alloc;
98 }
Arnaud Patard7fdc7842007-05-09 21:41:03 +010099
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +0100100 ret = rfkill_register(rfk);
101 if (ret)
102 goto err_rfkill;
103
104 platform_set_drvdata(pdev, rfk);
105
106 return 0;
107
108err_rfkill:
109 rfkill_destroy(rfk);
110err_rfk_alloc:
111 return ret;
Arnaud Patard7fdc7842007-05-09 21:41:03 +0100112}
113
114static int h1940bt_remove(struct platform_device *pdev)
115{
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +0100116 struct rfkill *rfk = platform_get_drvdata(pdev);
117
118 platform_set_drvdata(pdev, NULL);
Ben Dooksf4146a62010-05-04 11:23:05 +0900119 gpio_free(S3C2410_GPH(1));
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +0100120
121 if (rfk) {
122 rfkill_unregister(rfk);
123 rfkill_destroy(rfk);
124 }
125 rfk = NULL;
126
127 h1940bt_enable(0);
128
Arnaud Patard7fdc7842007-05-09 21:41:03 +0100129 return 0;
130}
131
132
133static struct platform_driver h1940bt_driver = {
134 .driver = {
135 .name = DRV_NAME,
136 },
137 .probe = h1940bt_probe,
138 .remove = h1940bt_remove,
139};
140
Sachin Kamat1fffc8b2012-09-07 06:33:24 +0900141module_platform_driver(h1940bt_driver);
Arnaud Patard7fdc7842007-05-09 21:41:03 +0100142
143MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
144MODULE_DESCRIPTION("Driver for the iPAQ H1940 bluetooth chip");
145MODULE_LICENSE("GPL");