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> |
Linus Walleij | c67d0f2 | 2013-12-06 10:05:49 +0100 | [diff] [blame^] | 21 | #include <linux/platform_data/gpio-samsung-s3c24xx.h> |
Ben Dooks | ec976d6 | 2009-05-13 22:52:24 +0100 | [diff] [blame] | 22 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 23 | #include <mach/hardware.h> |
Kukjin Kim | 232910d | 2013-01-02 10:18:58 -0800 | [diff] [blame] | 24 | #include <mach/regs-gpio.h> |
| 25 | |
| 26 | #include "h1940.h" |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 27 | |
Vasily Khoruzhick | 50e2d10 | 2011-01-06 21:52:48 +0200 | [diff] [blame] | 28 | #define DRV_NAME "h1940-bt" |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 29 | |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 30 | /* Bluetooth control */ |
| 31 | static void h1940bt_enable(int on) |
| 32 | { |
| 33 | if (on) { |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 34 | /* Power on the chip */ |
Vasily Khoruzhick | 1447709 | 2010-09-08 12:39:46 +0300 | [diff] [blame] | 35 | gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 1); |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 36 | /* Reset the chip */ |
| 37 | mdelay(10); |
Ben Dooks | f4146a6 | 2010-05-04 11:23:05 +0900 | [diff] [blame] | 38 | |
| 39 | gpio_set_value(S3C2410_GPH(1), 1); |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 40 | mdelay(10); |
Ben Dooks | f4146a6 | 2010-05-04 11:23:05 +0900 | [diff] [blame] | 41 | gpio_set_value(S3C2410_GPH(1), 0); |
Vasily Khoruzhick | 50e2d10 | 2011-01-06 21:52:48 +0200 | [diff] [blame] | 42 | |
| 43 | h1940_led_blink_set(-EINVAL, GPIO_LED_BLINK, NULL, NULL); |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 44 | } |
| 45 | else { |
Ben Dooks | f4146a6 | 2010-05-04 11:23:05 +0900 | [diff] [blame] | 46 | gpio_set_value(S3C2410_GPH(1), 1); |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 47 | mdelay(10); |
Ben Dooks | f4146a6 | 2010-05-04 11:23:05 +0900 | [diff] [blame] | 48 | gpio_set_value(S3C2410_GPH(1), 0); |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 49 | mdelay(10); |
Vasily Khoruzhick | 1447709 | 2010-09-08 12:39:46 +0300 | [diff] [blame] | 50 | gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 0); |
Vasily Khoruzhick | 50e2d10 | 2011-01-06 21:52:48 +0200 | [diff] [blame] | 51 | |
| 52 | h1940_led_blink_set(-EINVAL, GPIO_LED_NO_BLINK_LOW, NULL, NULL); |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 53 | } |
| 54 | } |
| 55 | |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 56 | static int h1940bt_set_block(void *data, bool blocked) |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 57 | { |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 58 | h1940bt_enable(!blocked); |
| 59 | return 0; |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 60 | } |
| 61 | |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 62 | static const struct rfkill_ops h1940bt_rfkill_ops = { |
| 63 | .set_block = h1940bt_set_block, |
| 64 | }; |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 65 | |
Greg Kroah-Hartman | 351a102 | 2012-12-21 14:02:24 -0800 | [diff] [blame] | 66 | static int h1940bt_probe(struct platform_device *pdev) |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 67 | { |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 68 | struct rfkill *rfk; |
| 69 | int ret = 0; |
| 70 | |
Ben Dooks | f4146a6 | 2010-05-04 11:23:05 +0900 | [diff] [blame] | 71 | ret = gpio_request(S3C2410_GPH(1), dev_name(&pdev->dev)); |
| 72 | if (ret) { |
Vasily Khoruzhick | 1447709 | 2010-09-08 12:39:46 +0300 | [diff] [blame] | 73 | dev_err(&pdev->dev, "could not get GPH1\n"); |
| 74 | return ret; |
| 75 | } |
| 76 | |
| 77 | ret = gpio_request(H1940_LATCH_BLUETOOTH_POWER, dev_name(&pdev->dev)); |
| 78 | if (ret) { |
| 79 | gpio_free(S3C2410_GPH(1)); |
| 80 | dev_err(&pdev->dev, "could not get BT_POWER\n"); |
Ben Dooks | f4146a6 | 2010-05-04 11:23:05 +0900 | [diff] [blame] | 81 | return ret; |
| 82 | } |
| 83 | |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 84 | /* Configures BT serial port GPIOs */ |
Ben Dooks | 40b956f | 2010-05-04 14:38:49 +0900 | [diff] [blame] | 85 | s3c_gpio_cfgpin(S3C2410_GPH(0), S3C2410_GPH0_nCTS0); |
Vasily Khoruzhick | 6fc50ea | 2010-11-16 18:11:59 +0900 | [diff] [blame] | 86 | s3c_gpio_setpull(S3C2410_GPH(0), S3C_GPIO_PULL_NONE); |
Ben Dooks | 40b956f | 2010-05-04 14:38:49 +0900 | [diff] [blame] | 87 | s3c_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPIO_OUTPUT); |
Vasily Khoruzhick | 6fc50ea | 2010-11-16 18:11:59 +0900 | [diff] [blame] | 88 | s3c_gpio_setpull(S3C2410_GPH(1), S3C_GPIO_PULL_NONE); |
Ben Dooks | 40b956f | 2010-05-04 14:38:49 +0900 | [diff] [blame] | 89 | s3c_gpio_cfgpin(S3C2410_GPH(2), S3C2410_GPH2_TXD0); |
Vasily Khoruzhick | 6fc50ea | 2010-11-16 18:11:59 +0900 | [diff] [blame] | 90 | s3c_gpio_setpull(S3C2410_GPH(2), S3C_GPIO_PULL_NONE); |
Ben Dooks | 40b956f | 2010-05-04 14:38:49 +0900 | [diff] [blame] | 91 | s3c_gpio_cfgpin(S3C2410_GPH(3), S3C2410_GPH3_RXD0); |
Vasily Khoruzhick | 6fc50ea | 2010-11-16 18:11:59 +0900 | [diff] [blame] | 92 | s3c_gpio_setpull(S3C2410_GPH(3), S3C_GPIO_PULL_NONE); |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 93 | |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 94 | rfk = rfkill_alloc(DRV_NAME, &pdev->dev, RFKILL_TYPE_BLUETOOTH, |
| 95 | &h1940bt_rfkill_ops, NULL); |
| 96 | if (!rfk) { |
| 97 | ret = -ENOMEM; |
| 98 | goto err_rfk_alloc; |
| 99 | } |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 100 | |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 101 | ret = rfkill_register(rfk); |
| 102 | if (ret) |
| 103 | goto err_rfkill; |
| 104 | |
| 105 | platform_set_drvdata(pdev, rfk); |
| 106 | |
| 107 | return 0; |
| 108 | |
| 109 | err_rfkill: |
| 110 | rfkill_destroy(rfk); |
| 111 | err_rfk_alloc: |
| 112 | return ret; |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | static int h1940bt_remove(struct platform_device *pdev) |
| 116 | { |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 117 | struct rfkill *rfk = platform_get_drvdata(pdev); |
| 118 | |
| 119 | platform_set_drvdata(pdev, NULL); |
Ben Dooks | f4146a6 | 2010-05-04 11:23:05 +0900 | [diff] [blame] | 120 | gpio_free(S3C2410_GPH(1)); |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 121 | |
| 122 | if (rfk) { |
| 123 | rfkill_unregister(rfk); |
| 124 | rfkill_destroy(rfk); |
| 125 | } |
| 126 | rfk = NULL; |
| 127 | |
| 128 | h1940bt_enable(0); |
| 129 | |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | |
| 134 | static struct platform_driver h1940bt_driver = { |
| 135 | .driver = { |
| 136 | .name = DRV_NAME, |
| 137 | }, |
| 138 | .probe = h1940bt_probe, |
| 139 | .remove = h1940bt_remove, |
| 140 | }; |
| 141 | |
Sachin Kamat | 1fffc8b | 2012-09-07 06:33:24 +0900 | [diff] [blame] | 142 | module_platform_driver(h1940bt_driver); |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 143 | |
| 144 | MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>"); |
| 145 | MODULE_DESCRIPTION("Driver for the iPAQ H1940 bluetooth chip"); |
| 146 | MODULE_LICENSE("GPL"); |