Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 1 | /* |
| 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 Dooks | ec976d6 | 2009-05-13 22:52:24 +0100 | [diff] [blame] | 19 | #include <linux/gpio.h> |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 20 | #include <linux/rfkill.h> |
Ben Dooks | ec976d6 | 2009-05-13 22:52:24 +0100 | [diff] [blame] | 21 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 22 | #include <mach/regs-gpio.h> |
| 23 | #include <mach/hardware.h> |
| 24 | #include <mach/h1940-latch.h> |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 25 | |
| 26 | #define DRV_NAME "h1940-bt" |
| 27 | |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 28 | /* Bluetooth control */ |
| 29 | static void h1940bt_enable(int on) |
| 30 | { |
| 31 | if (on) { |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 32 | /* Power on the chip */ |
Vasily Khoruzhick | 1447709 | 2010-09-08 12:39:46 +0300 | [diff] [blame^] | 33 | gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 1); |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 34 | /* Reset the chip */ |
| 35 | mdelay(10); |
Ben Dooks | f4146a6 | 2010-05-04 11:23:05 +0900 | [diff] [blame] | 36 | |
| 37 | gpio_set_value(S3C2410_GPH(1), 1); |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 38 | mdelay(10); |
Ben Dooks | f4146a6 | 2010-05-04 11:23:05 +0900 | [diff] [blame] | 39 | gpio_set_value(S3C2410_GPH(1), 0); |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 40 | } |
| 41 | else { |
Ben Dooks | f4146a6 | 2010-05-04 11:23:05 +0900 | [diff] [blame] | 42 | gpio_set_value(S3C2410_GPH(1), 1); |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 43 | mdelay(10); |
Ben Dooks | f4146a6 | 2010-05-04 11:23:05 +0900 | [diff] [blame] | 44 | gpio_set_value(S3C2410_GPH(1), 0); |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 45 | mdelay(10); |
Vasily Khoruzhick | 1447709 | 2010-09-08 12:39:46 +0300 | [diff] [blame^] | 46 | gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 0); |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 47 | } |
| 48 | } |
| 49 | |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 50 | static int h1940bt_set_block(void *data, bool blocked) |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 51 | { |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 52 | h1940bt_enable(!blocked); |
| 53 | return 0; |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 54 | } |
| 55 | |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 56 | static const struct rfkill_ops h1940bt_rfkill_ops = { |
| 57 | .set_block = h1940bt_set_block, |
| 58 | }; |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 59 | |
Uwe Kleine-König | 91a99df | 2010-02-04 20:56:49 +0100 | [diff] [blame] | 60 | static int __devinit h1940bt_probe(struct platform_device *pdev) |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 61 | { |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 62 | struct rfkill *rfk; |
| 63 | int ret = 0; |
| 64 | |
Ben Dooks | f4146a6 | 2010-05-04 11:23:05 +0900 | [diff] [blame] | 65 | ret = gpio_request(S3C2410_GPH(1), dev_name(&pdev->dev)); |
| 66 | if (ret) { |
Vasily Khoruzhick | 1447709 | 2010-09-08 12:39:46 +0300 | [diff] [blame^] | 67 | 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 Dooks | f4146a6 | 2010-05-04 11:23:05 +0900 | [diff] [blame] | 75 | return ret; |
| 76 | } |
| 77 | |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 78 | /* Configures BT serial port GPIOs */ |
Ben Dooks | 40b956f | 2010-05-04 14:38:49 +0900 | [diff] [blame] | 79 | s3c_gpio_cfgpin(S3C2410_GPH(0), S3C2410_GPH0_nCTS0); |
Ben Dooks | 27da040 | 2010-05-04 13:20:12 +0900 | [diff] [blame] | 80 | s3c_gpio_cfgpull(S3C2410_GPH(0), S3C_GPIO_PULL_NONE); |
Ben Dooks | 40b956f | 2010-05-04 14:38:49 +0900 | [diff] [blame] | 81 | s3c_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPIO_OUTPUT); |
Ben Dooks | 27da040 | 2010-05-04 13:20:12 +0900 | [diff] [blame] | 82 | s3c_gpio_cfgpull(S3C2410_GPH(1), S3C_GPIO_PULL_NONE); |
Ben Dooks | 40b956f | 2010-05-04 14:38:49 +0900 | [diff] [blame] | 83 | s3c_gpio_cfgpin(S3C2410_GPH(2), S3C2410_GPH2_TXD0); |
Ben Dooks | 27da040 | 2010-05-04 13:20:12 +0900 | [diff] [blame] | 84 | s3c_gpio_cfgpull(S3C2410_GPH(2), S3C_GPIO_PULL_NONE); |
Ben Dooks | 40b956f | 2010-05-04 14:38:49 +0900 | [diff] [blame] | 85 | s3c_gpio_cfgpin(S3C2410_GPH(3), S3C2410_GPH3_RXD0); |
Ben Dooks | 27da040 | 2010-05-04 13:20:12 +0900 | [diff] [blame] | 86 | s3c_gpio_cfgpull(S3C2410_GPH(3), S3C_GPIO_PULL_NONE); |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 87 | |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 88 | |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 89 | rfk = rfkill_alloc(DRV_NAME, &pdev->dev, RFKILL_TYPE_BLUETOOTH, |
| 90 | &h1940bt_rfkill_ops, NULL); |
| 91 | if (!rfk) { |
| 92 | ret = -ENOMEM; |
| 93 | goto err_rfk_alloc; |
| 94 | } |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 95 | |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 96 | rfkill_set_led_trigger_name(rfk, "h1940-bluetooth"); |
| 97 | |
| 98 | ret = rfkill_register(rfk); |
| 99 | if (ret) |
| 100 | goto err_rfkill; |
| 101 | |
| 102 | platform_set_drvdata(pdev, rfk); |
| 103 | |
| 104 | return 0; |
| 105 | |
| 106 | err_rfkill: |
| 107 | rfkill_destroy(rfk); |
| 108 | err_rfk_alloc: |
| 109 | return ret; |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | static int h1940bt_remove(struct platform_device *pdev) |
| 113 | { |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 114 | struct rfkill *rfk = platform_get_drvdata(pdev); |
| 115 | |
| 116 | platform_set_drvdata(pdev, NULL); |
Ben Dooks | f4146a6 | 2010-05-04 11:23:05 +0900 | [diff] [blame] | 117 | gpio_free(S3C2410_GPH(1)); |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 118 | |
| 119 | if (rfk) { |
| 120 | rfkill_unregister(rfk); |
| 121 | rfkill_destroy(rfk); |
| 122 | } |
| 123 | rfk = NULL; |
| 124 | |
| 125 | h1940bt_enable(0); |
| 126 | |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | |
| 131 | static struct platform_driver h1940bt_driver = { |
| 132 | .driver = { |
| 133 | .name = DRV_NAME, |
| 134 | }, |
| 135 | .probe = h1940bt_probe, |
| 136 | .remove = h1940bt_remove, |
| 137 | }; |
| 138 | |
| 139 | |
| 140 | static int __init h1940bt_init(void) |
| 141 | { |
| 142 | return platform_driver_register(&h1940bt_driver); |
| 143 | } |
| 144 | |
| 145 | static void __exit h1940bt_exit(void) |
| 146 | { |
| 147 | platform_driver_unregister(&h1940bt_driver); |
| 148 | } |
| 149 | |
| 150 | module_init(h1940bt_init); |
| 151 | module_exit(h1940bt_exit); |
| 152 | |
| 153 | MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>"); |
| 154 | MODULE_DESCRIPTION("Driver for the iPAQ H1940 bluetooth chip"); |
| 155 | MODULE_LICENSE("GPL"); |