Thomas Gleixner | abbf94f | 2018-04-23 00:02:11 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-1.0+ |
Krzysztof Kozlowski | 84b2170 | 2017-12-25 20:54:32 +0100 | [diff] [blame] | 2 | // |
| 3 | // Copyright (c) Arnaud Patard <arnaud.patard@rtp-net.org> |
| 4 | // |
| 5 | // S3C2410 bluetooth "driver" |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 6 | |
| 7 | #include <linux/module.h> |
| 8 | #include <linux/platform_device.h> |
| 9 | #include <linux/delay.h> |
| 10 | #include <linux/string.h> |
| 11 | #include <linux/ctype.h> |
| 12 | #include <linux/leds.h> |
Ben Dooks | ec976d6 | 2009-05-13 22:52:24 +0100 | [diff] [blame] | 13 | #include <linux/gpio.h> |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 14 | #include <linux/rfkill.h> |
Ben Dooks | ec976d6 | 2009-05-13 22:52:24 +0100 | [diff] [blame] | 15 | |
Arnd Bergmann | c6ff132 | 2019-09-02 18:37:30 +0200 | [diff] [blame] | 16 | #include "gpio-cfg.h" |
| 17 | #include "regs-gpio.h" |
| 18 | #include "gpio-samsung.h" |
Kukjin Kim | 232910d | 2013-01-02 10:18:58 -0800 | [diff] [blame] | 19 | |
| 20 | #include "h1940.h" |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 21 | |
Vasily Khoruzhick | 50e2d10 | 2011-01-06 21:52:48 +0200 | [diff] [blame] | 22 | #define DRV_NAME "h1940-bt" |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 23 | |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 24 | /* Bluetooth control */ |
| 25 | static void h1940bt_enable(int on) |
| 26 | { |
| 27 | if (on) { |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 28 | /* Power on the chip */ |
Vasily Khoruzhick | 1447709 | 2010-09-08 12:39:46 +0300 | [diff] [blame] | 29 | gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 1); |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 30 | /* Reset the chip */ |
| 31 | mdelay(10); |
Ben Dooks | f4146a6 | 2010-05-04 11:23:05 +0900 | [diff] [blame] | 32 | |
| 33 | gpio_set_value(S3C2410_GPH(1), 1); |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 34 | mdelay(10); |
Ben Dooks | f4146a6 | 2010-05-04 11:23:05 +0900 | [diff] [blame] | 35 | gpio_set_value(S3C2410_GPH(1), 0); |
Vasily Khoruzhick | 50e2d10 | 2011-01-06 21:52:48 +0200 | [diff] [blame] | 36 | |
Mika Westerberg | c673a2b | 2014-10-31 13:40:58 +0200 | [diff] [blame] | 37 | h1940_led_blink_set(NULL, GPIO_LED_BLINK, NULL, NULL); |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 38 | } |
| 39 | else { |
Ben Dooks | f4146a6 | 2010-05-04 11:23:05 +0900 | [diff] [blame] | 40 | gpio_set_value(S3C2410_GPH(1), 1); |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 41 | mdelay(10); |
Ben Dooks | f4146a6 | 2010-05-04 11:23:05 +0900 | [diff] [blame] | 42 | gpio_set_value(S3C2410_GPH(1), 0); |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 43 | mdelay(10); |
Vasily Khoruzhick | 1447709 | 2010-09-08 12:39:46 +0300 | [diff] [blame] | 44 | gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 0); |
Vasily Khoruzhick | 50e2d10 | 2011-01-06 21:52:48 +0200 | [diff] [blame] | 45 | |
Mika Westerberg | c673a2b | 2014-10-31 13:40:58 +0200 | [diff] [blame] | 46 | h1940_led_blink_set(NULL, GPIO_LED_NO_BLINK_LOW, NULL, NULL); |
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 | |
Greg Kroah-Hartman | 351a102 | 2012-12-21 14:02:24 -0800 | [diff] [blame] | 60 | static int 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); |
Vasily Khoruzhick | 6fc50eaf | 2010-11-16 18:11:59 +0900 | [diff] [blame] | 80 | s3c_gpio_setpull(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); |
Vasily Khoruzhick | 6fc50eaf | 2010-11-16 18:11:59 +0900 | [diff] [blame] | 82 | s3c_gpio_setpull(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); |
Vasily Khoruzhick | 6fc50eaf | 2010-11-16 18:11:59 +0900 | [diff] [blame] | 84 | s3c_gpio_setpull(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); |
Vasily Khoruzhick | 6fc50eaf | 2010-11-16 18:11:59 +0900 | [diff] [blame] | 86 | s3c_gpio_setpull(S3C2410_GPH(3), S3C_GPIO_PULL_NONE); |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 87 | |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 88 | rfk = rfkill_alloc(DRV_NAME, &pdev->dev, RFKILL_TYPE_BLUETOOTH, |
| 89 | &h1940bt_rfkill_ops, NULL); |
| 90 | if (!rfk) { |
| 91 | ret = -ENOMEM; |
| 92 | goto err_rfk_alloc; |
| 93 | } |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 94 | |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 95 | ret = rfkill_register(rfk); |
| 96 | if (ret) |
| 97 | goto err_rfkill; |
| 98 | |
| 99 | platform_set_drvdata(pdev, rfk); |
| 100 | |
| 101 | return 0; |
| 102 | |
| 103 | err_rfkill: |
| 104 | rfkill_destroy(rfk); |
| 105 | err_rfk_alloc: |
| 106 | return ret; |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | static int h1940bt_remove(struct platform_device *pdev) |
| 110 | { |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 111 | struct rfkill *rfk = platform_get_drvdata(pdev); |
| 112 | |
| 113 | platform_set_drvdata(pdev, NULL); |
Ben Dooks | f4146a6 | 2010-05-04 11:23:05 +0900 | [diff] [blame] | 114 | gpio_free(S3C2410_GPH(1)); |
arnaud.patard@rtp-net.org | 1a71e4a | 2009-11-17 14:54:59 +0100 | [diff] [blame] | 115 | |
| 116 | if (rfk) { |
| 117 | rfkill_unregister(rfk); |
| 118 | rfkill_destroy(rfk); |
| 119 | } |
| 120 | rfk = NULL; |
| 121 | |
| 122 | h1940bt_enable(0); |
| 123 | |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | |
| 128 | static struct platform_driver h1940bt_driver = { |
| 129 | .driver = { |
| 130 | .name = DRV_NAME, |
| 131 | }, |
| 132 | .probe = h1940bt_probe, |
| 133 | .remove = h1940bt_remove, |
| 134 | }; |
| 135 | |
Sachin Kamat | 1fffc8b | 2012-09-07 06:33:24 +0900 | [diff] [blame] | 136 | module_platform_driver(h1940bt_driver); |
Arnaud Patard | 7fdc784 | 2007-05-09 21:41:03 +0100 | [diff] [blame] | 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"); |