Guest User

Untitled

a guest
May 11th, 2013
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. /*
  2. * Copyright (C) 2010-2011 RDA Micro <[email protected]>
  3. * This file belong to RDA micro
  4. * File: drivers/char/tcc_bt_dev.c
  5. */
  6.  
  7. #include <linux/kernel.h>
  8. #include <linux/module.h>
  9. #include <linux/fs.h>
  10. #include <linux/ioctl.h>
  11. #include <linux/device.h>
  12. #include <linux/delay.h>
  13. #include <linux/gpio.h>
  14.  
  15. #define BT_DEV_ON 1
  16. #define BT_DEV_OFF 0
  17.  
  18. #define BT_DEV_MAJOR_NUM 234
  19. #define BT_DEV_MINOR_NUM 0
  20. #define DEV_NAME "tcc_bt_dev"
  21. #define IOCTL_BT_DEV_POWER _IO(BT_DEV_MAJOR_NUM,102)
  22.  
  23. #define GPIOWAKE 7
  24. #define GPIOENABLE 55
  25. static struct class *bt_dev_class;
  26.  
  27. static void RDA_bt_Power_On(void) {
  28. gpio_set_value(GPIOENABLE, 1);
  29. msleep(350);
  30. }
  31.  
  32. static void RDA_bt_Power_Off(void) {
  33. gpio_set_value(GPIOENABLE, 0);
  34. msleep(350);
  35. }
  36.  
  37. static int tcc_bt_dev_open(struct inode *inode, struct file *file) {
  38. printk("[## BT ##] tcc_bt_dev_open\n");
  39. return 0;
  40. }
  41.  
  42. static int tcc_bt_dev_release(struct inode *inode, struct file *file) {
  43. printk("[## BT ##] tcc_bt_dev_release\n");
  44. return 0;
  45. }
  46.  
  47. static void tcc_bt_power_control(int on_off) {
  48. printk("[## BT ##] tcc_bt_power_control input[%d]\n", on_off);
  49. if (on_off == BT_DEV_ON)
  50. RDA_bt_Power_On();
  51. else if (on_off == BT_DEV_OFF)
  52. RDA_bt_Power_Off();
  53. else
  54. printk("[## BT_ERR ##] input_error On[%d] Off[%d]\n", BT_DEV_ON, BT_DEV_OFF);
  55. }
  56.  
  57. static long tcc_bt_dev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) {
  58. int intarg = *((int*) arg);
  59. printk("[## BT ##] tcc_bt_dev_ioctl cmd[%d] arg[%d]\n", cmd, intarg);
  60.  
  61. switch (cmd) {
  62. case IOCTL_BT_DEV_POWER:
  63. printk("[## BT ##] IOCTL_BT_DEV_POWER cmd[%d] parm1[%d]\n", cmd, (int) arg);
  64. tcc_bt_power_control(intarg);
  65. break;
  66. default:
  67. printk("[## BT ##] tcc_bt_dev_ioctl cmd[%d]\n", cmd);
  68. break;
  69. }
  70.  
  71. return 0;
  72. }
  73.  
  74. struct file_operations tcc_bt_dev_ops = { .owner = THIS_MODULE, .unlocked_ioctl = tcc_bt_dev_ioctl, .open =
  75. tcc_bt_dev_open, .release = tcc_bt_dev_release, };
  76.  
  77. int init_module(void) {
  78. int ret;
  79.  
  80. printk("[## BT ##] init_module\n");
  81.  
  82. gpio_request_one(GPIOENABLE, GPIOF_OUT_INIT_HIGH, "bt_enable");
  83. gpio_request_one(GPIOWAKE, GPIOF_IN, "bt_wakeup");
  84.  
  85. ret = register_chrdev(BT_DEV_MAJOR_NUM, DEV_NAME, &tcc_bt_dev_ops);
  86. bt_dev_class = class_create(THIS_MODULE, DEV_NAME);
  87. device_create(bt_dev_class, NULL, MKDEV(BT_DEV_MAJOR_NUM, BT_DEV_MINOR_NUM), NULL, DEV_NAME);
  88.  
  89. if (ret < 0) {
  90. printk("[## BT ##] [%d]fail to register the character device\n", ret);
  91. return ret;
  92. }
  93.  
  94. return 0;
  95. }
  96.  
  97. void cleanup_module(void) {
  98. printk("[## BT ##] cleanup_module\n");
  99. unregister_chrdev(BT_DEV_MAJOR_NUM, DEV_NAME);
  100. }
  101.  
  102. late_initcall( init_module);
  103. module_exit( cleanup_module);
  104.  
  105. MODULE_AUTHOR("Telechips Inc. [email protected]");
  106. MODULE_DESCRIPTION("TCC_BT_DEV");
  107. MODULE_LICENSE("GPL");
Advertisement
Add Comment
Please, Sign In to add comment