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 */ |
| 33 | h1940_latch_control(0, H1940_LATCH_BLUETOOTH_POWER); |
| 34 | /* Reset the chip */ |
| 35 | mdelay(10); |
Ben Dooks | 070276d | 2009-05-17 22:32:23 +0100 | [diff] [blame] | 36 | s3c2410_gpio_setpin(S3C2410_GPH(1), 1); |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 37 | mdelay(10); |
Ben Dooks | 070276d | 2009-05-17 22:32:23 +0100 | [diff] [blame] | 38 | s3c2410_gpio_setpin(S3C2410_GPH(1), 0); |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 39 | } |
| 40 | else { |
Ben Dooks | 070276d | 2009-05-17 22:32:23 +0100 | [diff] [blame] | 41 | s3c2410_gpio_setpin(S3C2410_GPH(1), 1); |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 42 | mdelay(10); |
Ben Dooks | 070276d | 2009-05-17 22:32:23 +0100 | [diff] [blame] | 43 | s3c2410_gpio_setpin(S3C2410_GPH(1), 0); |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 44 | mdelay(10); |
| 45 | h1940_latch_control(H1940_LATCH_BLUETOOTH_POWER, 0); |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 49 | static int h1940bt_set_block(void *data, bool blocked) |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 50 | { |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 51 | h1940bt_enable(!blocked); |
| 52 | return 0; |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 53 | } |
| 54 | |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 55 | static const struct rfkill_ops h1940bt_rfkill_ops = { |
| 56 | .set_block = h1940bt_set_block, |
| 57 | }; |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 58 | |
Uwe Kleine-König | 91a99df | 2010-02-04 20:56:49 +0100 | [diff] [blame] | 59 | static int __devinit h1940bt_probe(struct platform_device *pdev) |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 60 | { |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 61 | struct rfkill *rfk; |
| 62 | int ret = 0; |
| 63 | |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 64 | /* Configures BT serial port GPIOs */ |
Ben Dooks | 070276d | 2009-05-17 22:32:23 +0100 | [diff] [blame] | 65 | s3c2410_gpio_cfgpin(S3C2410_GPH(0), S3C2410_GPH0_nCTS0); |
| 66 | s3c2410_gpio_pullup(S3C2410_GPH(0), 1); |
| 67 | s3c2410_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPIO_OUTPUT); |
| 68 | s3c2410_gpio_pullup(S3C2410_GPH(1), 1); |
| 69 | s3c2410_gpio_cfgpin(S3C2410_GPH(2), S3C2410_GPH2_TXD0); |
| 70 | s3c2410_gpio_pullup(S3C2410_GPH(2), 1); |
| 71 | s3c2410_gpio_cfgpin(S3C2410_GPH(3), S3C2410_GPH3_RXD0); |
| 72 | s3c2410_gpio_pullup(S3C2410_GPH(3), 1); |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 73 | |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 74 | |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 75 | rfk = rfkill_alloc(DRV_NAME, &pdev->dev, RFKILL_TYPE_BLUETOOTH, |
| 76 | &h1940bt_rfkill_ops, NULL); |
| 77 | if (!rfk) { |
| 78 | ret = -ENOMEM; |
| 79 | goto err_rfk_alloc; |
| 80 | } |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 81 | |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 82 | rfkill_set_led_trigger_name(rfk, "h1940-bluetooth"); |
| 83 | |
| 84 | ret = rfkill_register(rfk); |
| 85 | if (ret) |
| 86 | goto err_rfkill; |
| 87 | |
| 88 | platform_set_drvdata(pdev, rfk); |
| 89 | |
| 90 | return 0; |
| 91 | |
| 92 | err_rfkill: |
| 93 | rfkill_destroy(rfk); |
| 94 | err_rfk_alloc: |
| 95 | return ret; |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | static int h1940bt_remove(struct platform_device *pdev) |
| 99 | { |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 100 | struct rfkill *rfk = platform_get_drvdata(pdev); |
| 101 | |
| 102 | platform_set_drvdata(pdev, NULL); |
| 103 | |
| 104 | if (rfk) { |
| 105 | rfkill_unregister(rfk); |
| 106 | rfkill_destroy(rfk); |
| 107 | } |
| 108 | rfk = NULL; |
| 109 | |
| 110 | h1940bt_enable(0); |
| 111 | |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | |
| 116 | static struct platform_driver h1940bt_driver = { |
| 117 | .driver = { |
| 118 | .name = DRV_NAME, |
| 119 | }, |
| 120 | .probe = h1940bt_probe, |
| 121 | .remove = h1940bt_remove, |
| 122 | }; |
| 123 | |
| 124 | |
| 125 | static int __init h1940bt_init(void) |
| 126 | { |
| 127 | return platform_driver_register(&h1940bt_driver); |
| 128 | } |
| 129 | |
| 130 | static void __exit h1940bt_exit(void) |
| 131 | { |
| 132 | platform_driver_unregister(&h1940bt_driver); |
| 133 | } |
| 134 | |
| 135 | module_init(h1940bt_init); |
| 136 | module_exit(h1940bt_exit); |
| 137 | |
| 138 | MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>"); |
| 139 | MODULE_DESCRIPTION("Driver for the iPAQ H1940 bluetooth chip"); |
| 140 | MODULE_LICENSE("GPL"); |