blob: 8cdeb14af5929601492a74a593e9322f3a947c91 [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/regs-gpio.h>
23#include <mach/hardware.h>
24#include <mach/h1940-latch.h>
Arnaud Patard7fdc7842007-05-09 21:41:03 +010025
26#define DRV_NAME "h1940-bt"
27
Arnaud Patard7fdc7842007-05-09 21:41:03 +010028/* Bluetooth control */
29static void h1940bt_enable(int on)
30{
31 if (on) {
Arnaud Patard7fdc7842007-05-09 21:41:03 +010032 /* Power on the chip */
33 h1940_latch_control(0, H1940_LATCH_BLUETOOTH_POWER);
34 /* Reset the chip */
35 mdelay(10);
Ben Dooksf4146a62010-05-04 11:23:05 +090036
37 gpio_set_value(S3C2410_GPH(1), 1);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010038 mdelay(10);
Ben Dooksf4146a62010-05-04 11:23:05 +090039 gpio_set_value(S3C2410_GPH(1), 0);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010040 }
41 else {
Ben Dooksf4146a62010-05-04 11:23:05 +090042 gpio_set_value(S3C2410_GPH(1), 1);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010043 mdelay(10);
Ben Dooksf4146a62010-05-04 11:23:05 +090044 gpio_set_value(S3C2410_GPH(1), 0);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010045 mdelay(10);
46 h1940_latch_control(H1940_LATCH_BLUETOOTH_POWER, 0);
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
Uwe Kleine-König91a99df2010-02-04 20:56:49 +010060static int __devinit 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) {
67 dev_err(&pdev->dev, "could not get GPH1\n");\
68 return ret;
69 }
70
Arnaud Patard7fdc7842007-05-09 21:41:03 +010071 /* Configures BT serial port GPIOs */
Ben Dooks40b956f2010-05-04 14:38:49 +090072 s3c_gpio_cfgpin(S3C2410_GPH(0), S3C2410_GPH0_nCTS0);
Ben Dooks27da0402010-05-04 13:20:12 +090073 s3c_gpio_cfgpull(S3C2410_GPH(0), S3C_GPIO_PULL_NONE);
Ben Dooks40b956f2010-05-04 14:38:49 +090074 s3c_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPIO_OUTPUT);
Ben Dooks27da0402010-05-04 13:20:12 +090075 s3c_gpio_cfgpull(S3C2410_GPH(1), S3C_GPIO_PULL_NONE);
Ben Dooks40b956f2010-05-04 14:38:49 +090076 s3c_gpio_cfgpin(S3C2410_GPH(2), S3C2410_GPH2_TXD0);
Ben Dooks27da0402010-05-04 13:20:12 +090077 s3c_gpio_cfgpull(S3C2410_GPH(2), S3C_GPIO_PULL_NONE);
Ben Dooks40b956f2010-05-04 14:38:49 +090078 s3c_gpio_cfgpin(S3C2410_GPH(3), S3C2410_GPH3_RXD0);
Ben Dooks27da0402010-05-04 13:20:12 +090079 s3c_gpio_cfgpull(S3C2410_GPH(3), S3C_GPIO_PULL_NONE);
Arnaud Patard7fdc7842007-05-09 21:41:03 +010080
Arnaud Patard7fdc7842007-05-09 21:41:03 +010081
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +010082 rfk = rfkill_alloc(DRV_NAME, &pdev->dev, RFKILL_TYPE_BLUETOOTH,
83 &h1940bt_rfkill_ops, NULL);
84 if (!rfk) {
85 ret = -ENOMEM;
86 goto err_rfk_alloc;
87 }
Arnaud Patard7fdc7842007-05-09 21:41:03 +010088
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +010089 rfkill_set_led_trigger_name(rfk, "h1940-bluetooth");
90
91 ret = rfkill_register(rfk);
92 if (ret)
93 goto err_rfkill;
94
95 platform_set_drvdata(pdev, rfk);
96
97 return 0;
98
99err_rfkill:
100 rfkill_destroy(rfk);
101err_rfk_alloc:
102 return ret;
Arnaud Patard7fdc7842007-05-09 21:41:03 +0100103}
104
105static int h1940bt_remove(struct platform_device *pdev)
106{
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +0100107 struct rfkill *rfk = platform_get_drvdata(pdev);
108
109 platform_set_drvdata(pdev, NULL);
Ben Dooksf4146a62010-05-04 11:23:05 +0900110 gpio_free(S3C2410_GPH(1));
arnaud.patard@rtp-net.org1a71e4a2009-11-17 14:54:59 +0100111
112 if (rfk) {
113 rfkill_unregister(rfk);
114 rfkill_destroy(rfk);
115 }
116 rfk = NULL;
117
118 h1940bt_enable(0);
119
Arnaud Patard7fdc7842007-05-09 21:41:03 +0100120 return 0;
121}
122
123
124static struct platform_driver h1940bt_driver = {
125 .driver = {
126 .name = DRV_NAME,
127 },
128 .probe = h1940bt_probe,
129 .remove = h1940bt_remove,
130};
131
132
133static int __init h1940bt_init(void)
134{
135 return platform_driver_register(&h1940bt_driver);
136}
137
138static void __exit h1940bt_exit(void)
139{
140 platform_driver_unregister(&h1940bt_driver);
141}
142
143module_init(h1940bt_init);
144module_exit(h1940bt_exit);
145
146MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
147MODULE_DESCRIPTION("Driver for the iPAQ H1940 bluetooth chip");
148MODULE_LICENSE("GPL");