Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
h1940-bluetooth.c
Go to the documentation of this file.
1 /*
2  * arch/arm/mach-s3c2410/h1940-bluetooth.c
3  * Copyright (c) Arnaud Patard <[email protected]>
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>
19 #include <linux/gpio.h>
20 #include <linux/rfkill.h>
21 
22 #include <mach/regs-gpio.h>
23 #include <mach/hardware.h>
24 #include <mach/h1940-latch.h>
25 #include <mach/h1940.h>
26 
27 #define DRV_NAME "h1940-bt"
28 
29 /* Bluetooth control */
30 static void h1940bt_enable(int on)
31 {
32  if (on) {
33  /* Power on the chip */
35  /* Reset the chip */
36  mdelay(10);
37 
39  mdelay(10);
41 
43  }
44  else {
46  mdelay(10);
48  mdelay(10);
50 
52  }
53 }
54 
55 static int h1940bt_set_block(void *data, bool blocked)
56 {
57  h1940bt_enable(!blocked);
58  return 0;
59 }
60 
61 static const struct rfkill_ops h1940bt_rfkill_ops = {
62  .set_block = h1940bt_set_block,
63 };
64 
65 static int __devinit h1940bt_probe(struct platform_device *pdev)
66 {
67  struct rfkill *rfk;
68  int ret = 0;
69 
70  ret = gpio_request(S3C2410_GPH(1), dev_name(&pdev->dev));
71  if (ret) {
72  dev_err(&pdev->dev, "could not get GPH1\n");
73  return ret;
74  }
75 
76  ret = gpio_request(H1940_LATCH_BLUETOOTH_POWER, dev_name(&pdev->dev));
77  if (ret) {
79  dev_err(&pdev->dev, "could not get BT_POWER\n");
80  return ret;
81  }
82 
83  /* Configures BT serial port GPIOs */
92 
94  &h1940bt_rfkill_ops, NULL);
95  if (!rfk) {
96  ret = -ENOMEM;
97  goto err_rfk_alloc;
98  }
99 
100  ret = rfkill_register(rfk);
101  if (ret)
102  goto err_rfkill;
103 
104  platform_set_drvdata(pdev, rfk);
105 
106  return 0;
107 
108 err_rfkill:
109  rfkill_destroy(rfk);
110 err_rfk_alloc:
111  return ret;
112 }
113 
114 static int h1940bt_remove(struct platform_device *pdev)
115 {
116  struct rfkill *rfk = platform_get_drvdata(pdev);
117 
118  platform_set_drvdata(pdev, NULL);
120 
121  if (rfk) {
122  rfkill_unregister(rfk);
123  rfkill_destroy(rfk);
124  }
125  rfk = NULL;
126 
127  h1940bt_enable(0);
128 
129  return 0;
130 }
131 
132 
133 static struct platform_driver h1940bt_driver = {
134  .driver = {
135  .name = DRV_NAME,
136  },
137  .probe = h1940bt_probe,
138  .remove = h1940bt_remove,
139 };
140 
141 module_platform_driver(h1940bt_driver);
142 
143 MODULE_AUTHOR("Arnaud Patard <[email protected]>");
144 MODULE_DESCRIPTION("Driver for the iPAQ H1940 bluetooth chip");
145 MODULE_LICENSE("GPL");