blob: 59edcf8a620d37822d1d2162cb0d9c52ccd928c2 [file] [log] [blame]
Thomas Gleixnerabbf94f2018-04-23 00:02:11 +02001// SPDX-License-Identifier: GPL-1.0+
Krzysztof Kozlowski84b21702017-12-25 20:54:32 +01002//
3// Copyright (c) Arnaud Patard <arnaud.patard@rtp-net.org>
4//
5// S3C2410 bluetooth "driver"
Arnaud Patard7fdc7842007-05-09 21:41:03 +01006
7#include <linux/module.h>
8#include <linux/platform_device.h>
9#include <linux/delay.h>
10#include <linux/string.h>
11#include <linux/ctype.h>
12#include <linux/leds.h>
Ben Dooksec976d62009-05-13 22:52:24 +010013#include <linux/gpio.h>
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +010014#include <linux/rfkill.h>
Ben Dooksec976d62009-05-13 22:52:24 +010015
Arnd Bergmannc6ff1322019-09-02 18:37:30 +020016#include "gpio-cfg.h"
17#include "regs-gpio.h"
18#include "gpio-samsung.h"
Kukjin Kim232910d2013-01-02 10:18:58 -080019
20#include "h1940.h"
Arnaud Patard7fdc7842007-05-09 21:41:03 +010021
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +020022#define DRV_NAME "h1940-bt"
Arnaud Patard7fdc7842007-05-09 21:41:03 +010023
Arnaud Patard7fdc7842007-05-09 21:41:03 +010024/* Bluetooth control */
25static void h1940bt_enable(int on)
26{
27 if (on) {
Arnaud Patard7fdc7842007-05-09 21:41:03 +010028 /* Power on the chip */
Vasily Khoruzhick14477092010-09-08 12:39:46 +030029 gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 1);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010030 /* Reset the chip */
31 mdelay(10);
Ben Dooksf4146a62010-05-04 11:23:05 +090032
33 gpio_set_value(S3C2410_GPH(1), 1);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010034 mdelay(10);
Ben Dooksf4146a62010-05-04 11:23:05 +090035 gpio_set_value(S3C2410_GPH(1), 0);
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +020036
Mika Westerbergc673a2b2014-10-31 13:40:58 +020037 h1940_led_blink_set(NULL, GPIO_LED_BLINK, NULL, NULL);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010038 }
39 else {
Ben Dooksf4146a62010-05-04 11:23:05 +090040 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);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010043 mdelay(10);
Vasily Khoruzhick14477092010-09-08 12:39:46 +030044 gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 0);
Vasily Khoruzhick50e2d102011-01-06 21:52:48 +020045
Mika Westerbergc673a2b2014-10-31 13:40:58 +020046 h1940_led_blink_set(NULL, GPIO_LED_NO_BLINK_LOW, NULL, NULL);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010047 }
48}
49
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +010050static int h1940bt_set_block(void *data, bool blocked)
Arnaud Patard7fdc7842007-05-09 21:41:03 +010051{
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +010052 h1940bt_enable(!blocked);
53 return 0;
Arnaud Patard7fdc7842007-05-09 21:41:03 +010054}
55
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +010056static const struct rfkill_ops h1940bt_rfkill_ops = {
57 .set_block = h1940bt_set_block,
58};
Arnaud Patard7fdc7842007-05-09 21:41:03 +010059
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -080060static int h1940bt_probe(struct platform_device *pdev)
Arnaud Patard7fdc7842007-05-09 21:41:03 +010061{
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +010062 struct rfkill *rfk;
63 int ret = 0;
64
Ben Dooksf4146a62010-05-04 11:23:05 +090065 ret = gpio_request(S3C2410_GPH(1), dev_name(&pdev->dev));
66 if (ret) {
Vasily Khoruzhick14477092010-09-08 12:39:46 +030067 dev_err(&pdev->dev, "could not get GPH1\n");
68 return ret;
69 }
70
71 ret = gpio_request(H1940_LATCH_BLUETOOTH_POWER, dev_name(&pdev->dev));
72 if (ret) {
73 gpio_free(S3C2410_GPH(1));
74 dev_err(&pdev->dev, "could not get BT_POWER\n");
Ben Dooksf4146a62010-05-04 11:23:05 +090075 return ret;
76 }
77
Arnaud Patard7fdc7842007-05-09 21:41:03 +010078 /* Configures BT serial port GPIOs */
Ben Dooks40b956f2010-05-04 14:38:49 +090079 s3c_gpio_cfgpin(S3C2410_GPH(0), S3C2410_GPH0_nCTS0);
Vasily Khoruzhick6fc50eaf2010-11-16 18:11:59 +090080 s3c_gpio_setpull(S3C2410_GPH(0), S3C_GPIO_PULL_NONE);
Ben Dooks40b956f2010-05-04 14:38:49 +090081 s3c_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPIO_OUTPUT);
Vasily Khoruzhick6fc50eaf2010-11-16 18:11:59 +090082 s3c_gpio_setpull(S3C2410_GPH(1), S3C_GPIO_PULL_NONE);
Ben Dooks40b956f2010-05-04 14:38:49 +090083 s3c_gpio_cfgpin(S3C2410_GPH(2), S3C2410_GPH2_TXD0);
Vasily Khoruzhick6fc50eaf2010-11-16 18:11:59 +090084 s3c_gpio_setpull(S3C2410_GPH(2), S3C_GPIO_PULL_NONE);
Ben Dooks40b956f2010-05-04 14:38:49 +090085 s3c_gpio_cfgpin(S3C2410_GPH(3), S3C2410_GPH3_RXD0);
Vasily Khoruzhick6fc50eaf2010-11-16 18:11:59 +090086 s3c_gpio_setpull(S3C2410_GPH(3), S3C_GPIO_PULL_NONE);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010087
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +010088 rfk = rfkill_alloc(DRV_NAME, &pdev->dev, RFKILL_TYPE_BLUETOOTH,
89 &h1940bt_rfkill_ops, NULL);
90 if (!rfk) {
91 ret = -ENOMEM;
92 goto err_rfk_alloc;
93 }
Arnaud Patard7fdc7842007-05-09 21:41:03 +010094
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +010095 ret = rfkill_register(rfk);
96 if (ret)
97 goto err_rfkill;
98
99 platform_set_drvdata(pdev, rfk);
100
101 return 0;
102
103err_rfkill:
104 rfkill_destroy(rfk);
105err_rfk_alloc:
106 return ret;
Arnaud Patard7fdc7842007-05-09 21:41:03 +0100107}
108
109static int h1940bt_remove(struct platform_device *pdev)
110{
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +0100111 struct rfkill *rfk = platform_get_drvdata(pdev);
112
113 platform_set_drvdata(pdev, NULL);
Ben Dooksf4146a62010-05-04 11:23:05 +0900114 gpio_free(S3C2410_GPH(1));
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +0100115
116 if (rfk) {
117 rfkill_unregister(rfk);
118 rfkill_destroy(rfk);
119 }
120 rfk = NULL;
121
122 h1940bt_enable(0);
123
Arnaud Patard7fdc7842007-05-09 21:41:03 +0100124 return 0;
125}
126
127
128static struct platform_driver h1940bt_driver = {
129 .driver = {
130 .name = DRV_NAME,
131 },
132 .probe = h1940bt_probe,
133 .remove = h1940bt_remove,
134};
135
Sachin Kamat1fffc8b2012-09-07 06:33:24 +0900136module_platform_driver(h1940bt_driver);
Arnaud Patard7fdc7842007-05-09 21:41:03 +0100137
138MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
139MODULE_DESCRIPTION("Driver for the iPAQ H1940 bluetooth chip");
140MODULE_LICENSE("GPL");