h1940-bluetooth.c 3.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * arch/arm/mach-s3c2410/h1940-bluetooth.c
 * Copyright (c) Arnaud Patard <arnaud.patard@rtp-net.org>
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file COPYING in the main directory of this archive for
 * more details.
 *
 *	    S3C2410 bluetooth "driver"
 *
 */

#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>
19
#include <linux/gpio.h>
20
#include <linux/rfkill.h>
21

22 23 24
#include <mach/regs-gpio.h>
#include <mach/hardware.h>
#include <mach/h1940-latch.h>
25
#include <mach/h1940.h>
26

27
#define DRV_NAME "h1940-bt"
28 29 30 31 32 33

/* Bluetooth control */
static void h1940bt_enable(int on)
{
	if (on) {
		/* Power on the chip */
34
		gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 1);
35 36
		/* Reset the chip */
		mdelay(10);
37 38

		gpio_set_value(S3C2410_GPH(1), 1);
39
		mdelay(10);
40
		gpio_set_value(S3C2410_GPH(1), 0);
41 42

		h1940_led_blink_set(-EINVAL, GPIO_LED_BLINK, NULL, NULL);
43 44
	}
	else {
45
		gpio_set_value(S3C2410_GPH(1), 1);
46
		mdelay(10);
47
		gpio_set_value(S3C2410_GPH(1), 0);
48
		mdelay(10);
49
		gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 0);
50 51

		h1940_led_blink_set(-EINVAL, GPIO_LED_NO_BLINK_LOW, NULL, NULL);
52 53 54
	}
}

55
static int h1940bt_set_block(void *data, bool blocked)
56
{
57 58
	h1940bt_enable(!blocked);
	return 0;
59 60
}

61 62 63
static const struct rfkill_ops h1940bt_rfkill_ops = {
	.set_block = h1940bt_set_block,
};
64

65
static int __devinit h1940bt_probe(struct platform_device *pdev)
66
{
67 68 69
	struct rfkill *rfk;
	int ret = 0;

70 71
	ret = gpio_request(S3C2410_GPH(1), dev_name(&pdev->dev));
	if (ret) {
72 73 74 75 76 77 78 79
		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");
80 81 82
		return ret;
	}

83
	/* Configures BT serial port GPIOs */
84
	s3c_gpio_cfgpin(S3C2410_GPH(0), S3C2410_GPH0_nCTS0);
85
	s3c_gpio_setpull(S3C2410_GPH(0), S3C_GPIO_PULL_NONE);
86
	s3c_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPIO_OUTPUT);
87
	s3c_gpio_setpull(S3C2410_GPH(1), S3C_GPIO_PULL_NONE);
88
	s3c_gpio_cfgpin(S3C2410_GPH(2), S3C2410_GPH2_TXD0);
89
	s3c_gpio_setpull(S3C2410_GPH(2), S3C_GPIO_PULL_NONE);
90
	s3c_gpio_cfgpin(S3C2410_GPH(3), S3C2410_GPH3_RXD0);
91
	s3c_gpio_setpull(S3C2410_GPH(3), S3C_GPIO_PULL_NONE);
92

93 94 95 96 97 98 99 100 101 102 103 104 105 106
	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;
107

108 109 110 111
err_rfkill:
	rfkill_destroy(rfk);
err_rfk_alloc:
	return ret;
112 113 114 115
}

static int h1940bt_remove(struct platform_device *pdev)
{
116 117 118
	struct rfkill *rfk = platform_get_drvdata(pdev);

	platform_set_drvdata(pdev, NULL);
119
	gpio_free(S3C2410_GPH(1));
120 121 122 123 124 125 126 127 128

	if (rfk) {
		rfkill_unregister(rfk);
		rfkill_destroy(rfk);
	}
	rfk = NULL;

	h1940bt_enable(0);

129 130 131 132 133 134 135 136 137 138 139 140
	return 0;
}


static struct platform_driver h1940bt_driver = {
	.driver		= {
		.name	= DRV_NAME,
	},
	.probe		= h1940bt_probe,
	.remove		= h1940bt_remove,
};

141
module_platform_driver(h1940bt_driver);
142 143 144 145

MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
MODULE_DESCRIPTION("Driver for the iPAQ H1940 bluetooth chip");
MODULE_LICENSE("GPL");