blob: b4d14b86436727df47dce3bbe0d30db6c7e4e5ad [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
Linus Walleij36437412014-01-14 15:05:22 +010022#include <plat/gpio-cfg.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010023#include <mach/hardware.h>
Kukjin Kim232910d2013-01-02 10:18:58 -080024#include <mach/regs-gpio.h>
Linus Walleijb0161ca2014-01-14 14:24:24 +010025#include <mach/gpio-samsung.h>
Kukjin Kim232910d2013-01-02 10:18:58 -080026
27#include "h1940.h"
Arnaud Patard7fdc7842007-05-09 21:41:03 +010028
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +020029#define DRV_NAME "h1940-bt"
Arnaud Patard7fdc7842007-05-09 21:41:03 +010030
Arnaud Patard7fdc7842007-05-09 21:41:03 +010031/* Bluetooth control */
32static void h1940bt_enable(int on)
33{
34 if (on) {
Arnaud Patard7fdc7842007-05-09 21:41:03 +010035 /* Power on the chip */
Vasily Khoruzhick14477092010-09-08 12:39:46 +030036 gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 1);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010037 /* Reset the chip */
38 mdelay(10);
Ben Dooksf4146a62010-05-04 11:23:05 +090039
40 gpio_set_value(S3C2410_GPH(1), 1);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010041 mdelay(10);
Ben Dooksf4146a62010-05-04 11:23:05 +090042 gpio_set_value(S3C2410_GPH(1), 0);
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +020043
44 h1940_led_blink_set(-EINVAL, GPIO_LED_BLINK, NULL, NULL);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010045 }
46 else {
Ben Dooksf4146a62010-05-04 11:23:05 +090047 gpio_set_value(S3C2410_GPH(1), 1);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010048 mdelay(10);
Ben Dooksf4146a62010-05-04 11:23:05 +090049 gpio_set_value(S3C2410_GPH(1), 0);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010050 mdelay(10);
Vasily Khoruzhick14477092010-09-08 12:39:46 +030051 gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 0);
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +020052
53 h1940_led_blink_set(-EINVAL, GPIO_LED_NO_BLINK_LOW, NULL, NULL);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010054 }
55}
56
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +010057static int h1940bt_set_block(void *data, bool blocked)
Arnaud Patard7fdc7842007-05-09 21:41:03 +010058{
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +010059 h1940bt_enable(!blocked);
60 return 0;
Arnaud Patard7fdc7842007-05-09 21:41:03 +010061}
62
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +010063static const struct rfkill_ops h1940bt_rfkill_ops = {
64 .set_block = h1940bt_set_block,
65};
Arnaud Patard7fdc7842007-05-09 21:41:03 +010066
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -080067static int h1940bt_probe(struct platform_device *pdev)
Arnaud Patard7fdc7842007-05-09 21:41:03 +010068{
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +010069 struct rfkill *rfk;
70 int ret = 0;
71
Ben Dooksf4146a62010-05-04 11:23:05 +090072 ret = gpio_request(S3C2410_GPH(1), dev_name(&pdev->dev));
73 if (ret) {
Vasily Khoruzhick14477092010-09-08 12:39:46 +030074 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");
Ben Dooksf4146a62010-05-04 11:23:05 +090082 return ret;
83 }
84
Arnaud Patard7fdc7842007-05-09 21:41:03 +010085 /* Configures BT serial port GPIOs */
Ben Dooks40b956f2010-05-04 14:38:49 +090086 s3c_gpio_cfgpin(S3C2410_GPH(0), S3C2410_GPH0_nCTS0);
Vasily Khoruzhick6fc50ea2010-11-16 18:11:59 +090087 s3c_gpio_setpull(S3C2410_GPH(0), S3C_GPIO_PULL_NONE);
Ben Dooks40b956f2010-05-04 14:38:49 +090088 s3c_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPIO_OUTPUT);
Vasily Khoruzhick6fc50ea2010-11-16 18:11:59 +090089 s3c_gpio_setpull(S3C2410_GPH(1), S3C_GPIO_PULL_NONE);
Ben Dooks40b956f2010-05-04 14:38:49 +090090 s3c_gpio_cfgpin(S3C2410_GPH(2), S3C2410_GPH2_TXD0);
Vasily Khoruzhick6fc50ea2010-11-16 18:11:59 +090091 s3c_gpio_setpull(S3C2410_GPH(2), S3C_GPIO_PULL_NONE);
Ben Dooks40b956f2010-05-04 14:38:49 +090092 s3c_gpio_cfgpin(S3C2410_GPH(3), S3C2410_GPH3_RXD0);
Vasily Khoruzhick6fc50ea2010-11-16 18:11:59 +090093 s3c_gpio_setpull(S3C2410_GPH(3), S3C_GPIO_PULL_NONE);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010094
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +010095 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 }
Arnaud Patard7fdc7842007-05-09 21:41:03 +0100101
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +0100102 ret = rfkill_register(rfk);
103 if (ret)
104 goto err_rfkill;
105
106 platform_set_drvdata(pdev, rfk);
107
108 return 0;
109
110err_rfkill:
111 rfkill_destroy(rfk);
112err_rfk_alloc:
113 return ret;
Arnaud Patard7fdc7842007-05-09 21:41:03 +0100114}
115
116static int h1940bt_remove(struct platform_device *pdev)
117{
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +0100118 struct rfkill *rfk = platform_get_drvdata(pdev);
119
120 platform_set_drvdata(pdev, NULL);
Ben Dooksf4146a62010-05-04 11:23:05 +0900121 gpio_free(S3C2410_GPH(1));
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +0100122
123 if (rfk) {
124 rfkill_unregister(rfk);
125 rfkill_destroy(rfk);
126 }
127 rfk = NULL;
128
129 h1940bt_enable(0);
130
Arnaud Patard7fdc7842007-05-09 21:41:03 +0100131 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
Sachin Kamat1fffc8b2012-09-07 06:33:24 +0900143module_platform_driver(h1940bt_driver);
Arnaud Patard7fdc7842007-05-09 21:41:03 +0100144
145MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
146MODULE_DESCRIPTION("Driver for the iPAQ H1940 bluetooth chip");
147MODULE_LICENSE("GPL");