@@ -69,16 +69,21 @@ static struct i2c_driver i2c_counter_driver = {
69
69
MODULE_DEVICE_TABLE (i2c , i2c_counter_id );
70
70
71
71
// called by rtcnt_i2c_probe()
72
- static int rtcnt_i2c_create_cdev (struct rtcnt_device_info * dev_info , const char * devname_cnt )
72
+ static int rtcnt_i2c_create_cdev (struct rtcnt_device_info * dev_info , const int dev_side )
73
73
{
74
74
int minor ;
75
75
int alloc_ret = 0 ;
76
76
int cdev_err = 0 ;
77
77
dev_t dev ;
78
78
79
79
/* 空いているメジャー番号を確保する */
80
- alloc_ret = alloc_chrdev_region (& dev , DEV_MINOR , NUM_DEV [ID_DEV_CNT ],
81
- devname_cnt );
80
+ if (dev_side == DEV_LEFT ) {
81
+ alloc_ret = alloc_chrdev_region (& dev , DEV_MINOR , NUM_DEV [ID_DEV_CNT ],
82
+ DEVNAME_CNTL );
83
+ } else if (dev_side == DEV_RIGHT ) {
84
+ alloc_ret = alloc_chrdev_region (& dev , DEV_MINOR , NUM_DEV [ID_DEV_CNT ],
85
+ DEVNAME_CNTR );
86
+ }
82
87
if (alloc_ret != 0 ) {
83
88
printk (KERN_ERR "alloc_chrdev_region = %d\n" , alloc_ret );
84
89
return -1 ;
@@ -103,9 +108,17 @@ static int rtcnt_i2c_create_cdev(struct rtcnt_device_info *dev_info, const char
103
108
104
109
/* このデバイスのクラス登録をする(/sys/class/mydevice/ を作る) */
105
110
#if LINUX_VERSION_CODE < KERNEL_VERSION (6 , 4 , 0 )
106
- dev_info -> device_class = class_create (THIS_MODULE , devname_cnt );
111
+ if (dev_side == DEV_LEFT ) {
112
+ dev_info -> device_class = class_create (THIS_MODULE , DEVNAME_CNTL );
113
+ } else if (dev_side == DEV_RIGHT ) {
114
+ dev_info -> device_class = class_create (THIS_MODULE , DEVNAME_CNTR );
115
+ }
107
116
#else
108
- dev_info -> device_class = class_create (devname_cnt );
117
+ if (dev_side == DEV_LEFT ) {
118
+ dev_info -> device_class = class_create (DEVNAME_CNTL );
119
+ } else if (dev_side == DEV_RIGHT ) {
120
+ dev_info -> device_class = class_create (DEVNAME_CNTR );
121
+ }
109
122
#endif
110
123
111
124
if (IS_ERR (dev_info -> device_class )) {
@@ -120,11 +133,11 @@ static int rtcnt_i2c_create_cdev(struct rtcnt_device_info *dev_info, const char
120
133
minor ++ ) {
121
134
122
135
struct device * dev_ret ;
123
- if (devname_cnt == DEVNAME_CNTL ) {
136
+ if (dev_side == DEV_LEFT ) {
124
137
dev_ret = device_create (dev_info -> device_class , NULL ,
125
138
MKDEV (dev_info -> device_major , minor ),
126
139
NULL , "rtcounter_l%d" , minor );
127
- } else if (devname_cnt == DEVNAME_CNTR ) {
140
+ } else if (dev_side == DEV_RIGHT ) {
128
141
dev_ret = device_create (dev_info -> device_class , NULL ,
129
142
MKDEV (dev_info -> device_major , minor ),
130
143
NULL , "rtcounter_r%d" , minor );
0 commit comments