2018-04-23 05:02:11 +07:00
|
|
|
// SPDX-License-Identifier: GPL-1.0+
|
2017-12-26 02:54:32 +07:00
|
|
|
//
|
|
|
|
// Copyright (c) Arnaud Patard <arnaud.patard@rtp-net.org>
|
|
|
|
//
|
|
|
|
// S3C2410 bluetooth "driver"
|
2007-05-10 03:41:03 +07:00
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/ctype.h>
|
|
|
|
#include <linux/leds.h>
|
2009-05-14 04:52:24 +07:00
|
|
|
#include <linux/gpio.h>
|
2009-11-17 20:54:59 +07:00
|
|
|
#include <linux/rfkill.h>
|
2009-05-14 04:52:24 +07:00
|
|
|
|
2014-01-14 21:05:22 +07:00
|
|
|
#include <plat/gpio-cfg.h>
|
2008-08-05 22:14:15 +07:00
|
|
|
#include <mach/hardware.h>
|
2013-01-03 01:18:58 +07:00
|
|
|
#include <mach/regs-gpio.h>
|
2014-01-14 20:24:24 +07:00
|
|
|
#include <mach/gpio-samsung.h>
|
2013-01-03 01:18:58 +07:00
|
|
|
|
|
|
|
#include "h1940.h"
|
2007-05-10 03:41:03 +07:00
|
|
|
|
2011-01-07 02:52:48 +07:00
|
|
|
#define DRV_NAME "h1940-bt"
|
2007-05-10 03:41:03 +07:00
|
|
|
|
|
|
|
/* Bluetooth control */
|
|
|
|
static void h1940bt_enable(int on)
|
|
|
|
{
|
|
|
|
if (on) {
|
|
|
|
/* Power on the chip */
|
2010-09-08 16:39:46 +07:00
|
|
|
gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 1);
|
2007-05-10 03:41:03 +07:00
|
|
|
/* Reset the chip */
|
|
|
|
mdelay(10);
|
2010-05-04 09:23:05 +07:00
|
|
|
|
|
|
|
gpio_set_value(S3C2410_GPH(1), 1);
|
2007-05-10 03:41:03 +07:00
|
|
|
mdelay(10);
|
2010-05-04 09:23:05 +07:00
|
|
|
gpio_set_value(S3C2410_GPH(1), 0);
|
2011-01-07 02:52:48 +07:00
|
|
|
|
2014-10-31 18:40:58 +07:00
|
|
|
h1940_led_blink_set(NULL, GPIO_LED_BLINK, NULL, NULL);
|
2007-05-10 03:41:03 +07:00
|
|
|
}
|
|
|
|
else {
|
2010-05-04 09:23:05 +07:00
|
|
|
gpio_set_value(S3C2410_GPH(1), 1);
|
2007-05-10 03:41:03 +07:00
|
|
|
mdelay(10);
|
2010-05-04 09:23:05 +07:00
|
|
|
gpio_set_value(S3C2410_GPH(1), 0);
|
2007-05-10 03:41:03 +07:00
|
|
|
mdelay(10);
|
2010-09-08 16:39:46 +07:00
|
|
|
gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 0);
|
2011-01-07 02:52:48 +07:00
|
|
|
|
2014-10-31 18:40:58 +07:00
|
|
|
h1940_led_blink_set(NULL, GPIO_LED_NO_BLINK_LOW, NULL, NULL);
|
2007-05-10 03:41:03 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-17 20:54:59 +07:00
|
|
|
static int h1940bt_set_block(void *data, bool blocked)
|
2007-05-10 03:41:03 +07:00
|
|
|
{
|
2009-11-17 20:54:59 +07:00
|
|
|
h1940bt_enable(!blocked);
|
|
|
|
return 0;
|
2007-05-10 03:41:03 +07:00
|
|
|
}
|
|
|
|
|
2009-11-17 20:54:59 +07:00
|
|
|
static const struct rfkill_ops h1940bt_rfkill_ops = {
|
|
|
|
.set_block = h1940bt_set_block,
|
|
|
|
};
|
2007-05-10 03:41:03 +07:00
|
|
|
|
2012-12-22 05:02:24 +07:00
|
|
|
static int h1940bt_probe(struct platform_device *pdev)
|
2007-05-10 03:41:03 +07:00
|
|
|
{
|
2009-11-17 20:54:59 +07:00
|
|
|
struct rfkill *rfk;
|
|
|
|
int ret = 0;
|
|
|
|
|
2010-05-04 09:23:05 +07:00
|
|
|
ret = gpio_request(S3C2410_GPH(1), dev_name(&pdev->dev));
|
|
|
|
if (ret) {
|
2010-09-08 16:39:46 +07:00
|
|
|
dev_err(&pdev->dev, "could not get GPH1\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = gpio_request(H1940_LATCH_BLUETOOTH_POWER, dev_name(&pdev->dev));
|
|
|
|
if (ret) {
|
|
|
|
gpio_free(S3C2410_GPH(1));
|
|
|
|
dev_err(&pdev->dev, "could not get BT_POWER\n");
|
2010-05-04 09:23:05 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-05-10 03:41:03 +07:00
|
|
|
/* Configures BT serial port GPIOs */
|
2010-05-04 12:38:49 +07:00
|
|
|
s3c_gpio_cfgpin(S3C2410_GPH(0), S3C2410_GPH0_nCTS0);
|
2010-11-16 16:11:59 +07:00
|
|
|
s3c_gpio_setpull(S3C2410_GPH(0), S3C_GPIO_PULL_NONE);
|
2010-05-04 12:38:49 +07:00
|
|
|
s3c_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPIO_OUTPUT);
|
2010-11-16 16:11:59 +07:00
|
|
|
s3c_gpio_setpull(S3C2410_GPH(1), S3C_GPIO_PULL_NONE);
|
2010-05-04 12:38:49 +07:00
|
|
|
s3c_gpio_cfgpin(S3C2410_GPH(2), S3C2410_GPH2_TXD0);
|
2010-11-16 16:11:59 +07:00
|
|
|
s3c_gpio_setpull(S3C2410_GPH(2), S3C_GPIO_PULL_NONE);
|
2010-05-04 12:38:49 +07:00
|
|
|
s3c_gpio_cfgpin(S3C2410_GPH(3), S3C2410_GPH3_RXD0);
|
2010-11-16 16:11:59 +07:00
|
|
|
s3c_gpio_setpull(S3C2410_GPH(3), S3C_GPIO_PULL_NONE);
|
2007-05-10 03:41:03 +07:00
|
|
|
|
2009-11-17 20:54:59 +07:00
|
|
|
rfk = rfkill_alloc(DRV_NAME, &pdev->dev, RFKILL_TYPE_BLUETOOTH,
|
|
|
|
&h1940bt_rfkill_ops, NULL);
|
|
|
|
if (!rfk) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_rfk_alloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = rfkill_register(rfk);
|
|
|
|
if (ret)
|
|
|
|
goto err_rfkill;
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, rfk);
|
|
|
|
|
|
|
|
return 0;
|
2007-05-10 03:41:03 +07:00
|
|
|
|
2009-11-17 20:54:59 +07:00
|
|
|
err_rfkill:
|
|
|
|
rfkill_destroy(rfk);
|
|
|
|
err_rfk_alloc:
|
|
|
|
return ret;
|
2007-05-10 03:41:03 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int h1940bt_remove(struct platform_device *pdev)
|
|
|
|
{
|
2009-11-17 20:54:59 +07:00
|
|
|
struct rfkill *rfk = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, NULL);
|
2010-05-04 09:23:05 +07:00
|
|
|
gpio_free(S3C2410_GPH(1));
|
2009-11-17 20:54:59 +07:00
|
|
|
|
|
|
|
if (rfk) {
|
|
|
|
rfkill_unregister(rfk);
|
|
|
|
rfkill_destroy(rfk);
|
|
|
|
}
|
|
|
|
rfk = NULL;
|
|
|
|
|
|
|
|
h1940bt_enable(0);
|
|
|
|
|
2007-05-10 03:41:03 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct platform_driver h1940bt_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = DRV_NAME,
|
|
|
|
},
|
|
|
|
.probe = h1940bt_probe,
|
|
|
|
.remove = h1940bt_remove,
|
|
|
|
};
|
|
|
|
|
2012-09-07 04:33:24 +07:00
|
|
|
module_platform_driver(h1940bt_driver);
|
2007-05-10 03:41:03 +07:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
|
|
|
|
MODULE_DESCRIPTION("Driver for the iPAQ H1940 bluetooth chip");
|
|
|
|
MODULE_LICENSE("GPL");
|