1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
| #include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/err.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include <asm/uaccess.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include "ft5x06_ts.h"
extern int init_wrapper(void);
extern void exit_wrapper(void);
#define module_PRINT_ERR (1U << 0)
#define module_PRINT_WARNING (1U << 1)
#define module_PRINT_INFO (1U << 2)
#define module_PRINT_DEBUG (1U << 3)
#ifndef DEFAULT_DEV_NAME
#define DEFAULT_DEV_NAME "ft5x0x_ts"
#endif
#ifndef DEFAULT_DEV_ADAP
#define DEFAULT_DEV_ADAP 255
#endif
#ifndef DEFAULT_DEV_ADDR
#define DEFAULT_DEV_ADDR 0x38
#endif
#define pr_module(debug_level_mask, args...) \
do { \
if (debug_mask & module_PRINT_##debug_level_mask) { \
printk(KERN_##debug_level_mask "[module_driver] "args); \
} \
} while (0)
static int debug_mask = module_PRINT_ERR | \
module_PRINT_INFO | \
module_PRINT_WARNING | module_PRINT_DEBUG ;
module_param_named(debug_mask, debug_mask, int, S_IRUGO | S_IWUSR | S_IWGRP);
static u8 local_device_adap = DEFAULT_DEV_ADAP;
module_param_named(adap, local_device_adap, byte, S_IRUGO | S_IWUSR | S_IWGRP);
MODULE_PARM_DESC(adap, "Set the i2c adapter of device.");
static u8 local_device_addr = DEFAULT_DEV_ADDR;
module_param_named(addr, local_device_addr, byte, S_IRUGO | S_IWUSR | S_IWGRP);
MODULE_PARM_DESC(addr, "Set the address of device.");
static struct i2c_client *this_client = NULL;
static struct MODULE_DRIVER_INFO {
struct i2c_board_info *this_device_info;
void(*prepare_func)(void);
} module_driver_info = {
.this_device_info = &ft5x0x_device_info,
.prepare_func = ft5x06_touchpad_setup
};
static int __init module_driver_init(void)
{
/* int rc; */
struct i2c_adapter *i2c_adap;
pr_module(INFO,"Enter in %s\n", __func__);
/* Init GPIOs */
if(module_driver_info.prepare_func)
(*module_driver_info.prepare_func)();
/* Add device driver. */
init_wrapper();
module_driver_info.this_device_info->addr = local_device_addr;
/* Add i2c device to platform */
i2c_adap = i2c_get_adapter(local_device_adap);
if (NULL == i2c_adap)
{
pr_module(ERR, "%s: i2c_get_adapter for %d failed\n", __func__, local_device_adap);
goto error_adapter;
}
this_client = i2c_new_device(i2c_adap, module_driver_info.this_device_info);
if (NULL == this_client)
{
pr_module(ERR, "%s: i2c_new_device for %s failed\n", __func__, module_driver_info.this_device_info->type);
goto error_device;
}
pr_module(INFO, "%s: this_client:%p, addr:%#x\n", __func__, this_client, this_client->addr);
i2c_put_adapter(i2c_adap);
return 0;
error_device:
i2c_put_adapter(i2c_adap);
error_adapter:
exit_wrapper();
return -1;
}
static void __exit module_driver_exit(void)
{
pr_module(INFO,"Enter in %s\n", __func__);
exit_wrapper();
i2c_unregister_device(this_client);
}
module_init(module_driver_init);
module_exit(module_driver_exit);
MODULE_AUTHOR("zhiqiang.xu<zhiqiang.xu@phicomm.com.cn>");
MODULE_DESCRIPTION("i2c device module driver");
MODULE_LICENSE("GPL v2");
|