0001
0002
0003
0004
0005
0006
0007 #include <linux/module.h>
0008 #include <linux/platform_device.h>
0009 #include <linux/delay.h>
0010 #include <linux/string.h>
0011 #include <linux/ctype.h>
0012 #include <linux/leds.h>
0013 #include <linux/gpio.h>
0014 #include <linux/rfkill.h>
0015
0016 #include "gpio-cfg.h"
0017 #include "regs-gpio.h"
0018 #include "gpio-samsung.h"
0019
0020 #include "h1940.h"
0021
0022 #define DRV_NAME "h1940-bt"
0023
0024
0025 static void h1940bt_enable(int on)
0026 {
0027 if (on) {
0028
0029 gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 1);
0030
0031 mdelay(10);
0032
0033 gpio_set_value(S3C2410_GPH(1), 1);
0034 mdelay(10);
0035 gpio_set_value(S3C2410_GPH(1), 0);
0036
0037 h1940_led_blink_set(NULL, GPIO_LED_BLINK, NULL, NULL);
0038 }
0039 else {
0040 gpio_set_value(S3C2410_GPH(1), 1);
0041 mdelay(10);
0042 gpio_set_value(S3C2410_GPH(1), 0);
0043 mdelay(10);
0044 gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 0);
0045
0046 h1940_led_blink_set(NULL, GPIO_LED_NO_BLINK_LOW, NULL, NULL);
0047 }
0048 }
0049
0050 static int h1940bt_set_block(void *data, bool blocked)
0051 {
0052 h1940bt_enable(!blocked);
0053 return 0;
0054 }
0055
0056 static const struct rfkill_ops h1940bt_rfkill_ops = {
0057 .set_block = h1940bt_set_block,
0058 };
0059
0060 static int h1940bt_probe(struct platform_device *pdev)
0061 {
0062 struct rfkill *rfk;
0063 int ret = 0;
0064
0065 ret = gpio_request(S3C2410_GPH(1), dev_name(&pdev->dev));
0066 if (ret) {
0067 dev_err(&pdev->dev, "could not get GPH1\n");
0068 return ret;
0069 }
0070
0071 ret = gpio_request(H1940_LATCH_BLUETOOTH_POWER, dev_name(&pdev->dev));
0072 if (ret) {
0073 gpio_free(S3C2410_GPH(1));
0074 dev_err(&pdev->dev, "could not get BT_POWER\n");
0075 return ret;
0076 }
0077
0078
0079 s3c_gpio_cfgpin(S3C2410_GPH(0), S3C2410_GPH0_nCTS0);
0080 s3c_gpio_setpull(S3C2410_GPH(0), S3C_GPIO_PULL_NONE);
0081 s3c_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPIO_OUTPUT);
0082 s3c_gpio_setpull(S3C2410_GPH(1), S3C_GPIO_PULL_NONE);
0083 s3c_gpio_cfgpin(S3C2410_GPH(2), S3C2410_GPH2_TXD0);
0084 s3c_gpio_setpull(S3C2410_GPH(2), S3C_GPIO_PULL_NONE);
0085 s3c_gpio_cfgpin(S3C2410_GPH(3), S3C2410_GPH3_RXD0);
0086 s3c_gpio_setpull(S3C2410_GPH(3), S3C_GPIO_PULL_NONE);
0087
0088 rfk = rfkill_alloc(DRV_NAME, &pdev->dev, RFKILL_TYPE_BLUETOOTH,
0089 &h1940bt_rfkill_ops, NULL);
0090 if (!rfk) {
0091 ret = -ENOMEM;
0092 goto err_rfk_alloc;
0093 }
0094
0095 ret = rfkill_register(rfk);
0096 if (ret)
0097 goto err_rfkill;
0098
0099 platform_set_drvdata(pdev, rfk);
0100
0101 return 0;
0102
0103 err_rfkill:
0104 rfkill_destroy(rfk);
0105 err_rfk_alloc:
0106 return ret;
0107 }
0108
0109 static int h1940bt_remove(struct platform_device *pdev)
0110 {
0111 struct rfkill *rfk = platform_get_drvdata(pdev);
0112
0113 platform_set_drvdata(pdev, NULL);
0114 gpio_free(S3C2410_GPH(1));
0115
0116 if (rfk) {
0117 rfkill_unregister(rfk);
0118 rfkill_destroy(rfk);
0119 }
0120 rfk = NULL;
0121
0122 h1940bt_enable(0);
0123
0124 return 0;
0125 }
0126
0127
0128 static struct platform_driver h1940bt_driver = {
0129 .driver = {
0130 .name = DRV_NAME,
0131 },
0132 .probe = h1940bt_probe,
0133 .remove = h1940bt_remove,
0134 };
0135
0136 module_platform_driver(h1940bt_driver);
0137
0138 MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
0139 MODULE_DESCRIPTION("Driver for the iPAQ H1940 bluetooth chip");
0140 MODULE_LICENSE("GPL");