Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Copyright (C) 2010-2011 RDA Micro <[email protected]>
- * This file belong to RDA micro
- * File: drivers/char/tcc_bt_dev.c
- */
- #include <linux/kernel.h>
- #include <linux/module.h>
- #include <linux/fs.h>
- #include <linux/ioctl.h>
- #include <linux/device.h>
- #include <linux/delay.h>
- #include <linux/gpio.h>
- #define BT_DEV_ON 1
- #define BT_DEV_OFF 0
- #define BT_DEV_MAJOR_NUM 234
- #define BT_DEV_MINOR_NUM 0
- #define DEV_NAME "tcc_bt_dev"
- #define IOCTL_BT_DEV_POWER _IO(BT_DEV_MAJOR_NUM,102)
- #define GPIOWAKE 7
- #define GPIOENABLE 55
- static struct class *bt_dev_class;
- static void RDA_bt_Power_On(void) {
- gpio_set_value(GPIOENABLE, 1);
- msleep(350);
- }
- static void RDA_bt_Power_Off(void) {
- gpio_set_value(GPIOENABLE, 0);
- msleep(350);
- }
- static int tcc_bt_dev_open(struct inode *inode, struct file *file) {
- printk("[## BT ##] tcc_bt_dev_open\n");
- return 0;
- }
- static int tcc_bt_dev_release(struct inode *inode, struct file *file) {
- printk("[## BT ##] tcc_bt_dev_release\n");
- return 0;
- }
- static void tcc_bt_power_control(int on_off) {
- printk("[## BT ##] tcc_bt_power_control input[%d]\n", on_off);
- if (on_off == BT_DEV_ON)
- RDA_bt_Power_On();
- else if (on_off == BT_DEV_OFF)
- RDA_bt_Power_Off();
- else
- printk("[## BT_ERR ##] input_error On[%d] Off[%d]\n", BT_DEV_ON, BT_DEV_OFF);
- }
- static long tcc_bt_dev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) {
- int intarg = *((int*) arg);
- printk("[## BT ##] tcc_bt_dev_ioctl cmd[%d] arg[%d]\n", cmd, intarg);
- switch (cmd) {
- case IOCTL_BT_DEV_POWER:
- printk("[## BT ##] IOCTL_BT_DEV_POWER cmd[%d] parm1[%d]\n", cmd, (int) arg);
- tcc_bt_power_control(intarg);
- break;
- default:
- printk("[## BT ##] tcc_bt_dev_ioctl cmd[%d]\n", cmd);
- break;
- }
- return 0;
- }
- struct file_operations tcc_bt_dev_ops = { .owner = THIS_MODULE, .unlocked_ioctl = tcc_bt_dev_ioctl, .open =
- tcc_bt_dev_open, .release = tcc_bt_dev_release, };
- int init_module(void) {
- int ret;
- printk("[## BT ##] init_module\n");
- gpio_request_one(GPIOENABLE, GPIOF_OUT_INIT_HIGH, "bt_enable");
- gpio_request_one(GPIOWAKE, GPIOF_IN, "bt_wakeup");
- ret = register_chrdev(BT_DEV_MAJOR_NUM, DEV_NAME, &tcc_bt_dev_ops);
- bt_dev_class = class_create(THIS_MODULE, DEV_NAME);
- device_create(bt_dev_class, NULL, MKDEV(BT_DEV_MAJOR_NUM, BT_DEV_MINOR_NUM), NULL, DEV_NAME);
- if (ret < 0) {
- printk("[## BT ##] [%d]fail to register the character device\n", ret);
- return ret;
- }
- return 0;
- }
- void cleanup_module(void) {
- printk("[## BT ##] cleanup_module\n");
- unregister_chrdev(BT_DEV_MAJOR_NUM, DEV_NAME);
- }
- late_initcall( init_module);
- module_exit( cleanup_module);
- MODULE_AUTHOR("Telechips Inc. [email protected]");
- MODULE_DESCRIPTION("TCC_BT_DEV");
- MODULE_LICENSE("GPL");
Advertisement
Add Comment
Please, Sign In to add comment