1 #include "mag_factory.h"
3 static int mag_factory_open(struct inode
*inode
, struct file
*file
)
5 file
->private_data
= mag_context_obj
;
7 if (file
->private_data
== NULL
)
9 MAG_ERR("null pointer!!\n");
12 return nonseekable_open(inode
, file
);
15 static int mag_factory_release(struct inode
*inode
, struct file
*file
)
17 file
->private_data
= NULL
;
21 static long mag_factory_unlocked_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
25 struct mag_context
*cxt
= mag_context_obj
;
29 SENSOR_DATA sensor_data
= {0};
31 if (_IOC_DIR(cmd
) & _IOC_READ
)
33 err
= !access_ok(VERIFY_WRITE
, (void __user
*)arg
, _IOC_SIZE(cmd
));
35 else if (_IOC_DIR(cmd
) & _IOC_WRITE
)
37 err
= !access_ok(VERIFY_READ
, (void __user
*)arg
, _IOC_SIZE(cmd
));
42 MAG_ERR("access error: %08X, (%2d, %2d)\n", cmd
, _IOC_DIR(cmd
), _IOC_SIZE(cmd
));
48 case MSENSOR_IOCTL_SENSOR_ENABLE
:
49 if(cxt
->mag_ctl
.m_enable
!= NULL
){
50 err
= cxt
->mag_ctl
.m_enable(1);
53 MAG_ERR("MSENSOR_IOCTL_SENSOR_ENABLE read data fail!\n");
58 case MSENSOR_IOCTL_READ_SENSORDATA
:
59 data
= (void __user
*) arg
;
65 if(cxt
->mag_dev_data
.get_data_m
!= NULL
){
66 err
= cxt
->mag_dev_data
.get_raw_data(&x
, &y
, &z
);
69 MAG_ERR("MSENSOR_IOCTL_READ_SENSORDATA read data fail!\n");
72 sprintf(strbuf
, "%x %x %x", x
, y
, z
);
73 MAG_ERR("MSENSOR_IOCTL_READ_SENSORDATA read data : (%d, %d, %d)!\n", x
, y
, z
);
74 MAG_ERR("MSENSOR_IOCTL_READ_SENSORDATA read strbuf : (%s)!\n", strbuf
);
76 if (copy_to_user(data
, strbuf
, strlen(strbuf
)+1))
82 MAG_ERR("MSENSOR_IOCTL_READ_SENSORDATA NULL!\n");
86 case MSENSOR_IOCTL_READ_FACTORY_SENSORDATA
:
87 data
= (void __user
*) arg
;
93 if(cxt
->mag_dev_data
.get_data_o
!= NULL
){
94 err
= cxt
->mag_dev_data
.get_data_o(&x
, &y
, &z
, &status
);
97 MAG_ERR("MSENSOR_IOCTL_READ_FACTORY_SENSORDATA read data fail!\n");
100 sprintf(strbuf
, "%x %x %x %x %x", x
, y
, z
, status
, 1);
101 MAG_ERR("MSENSOR_IOCTL_READ_FACTORY_SENSORDATA read data : (%d, %d, %d, %d)!\n", x
, y
, z
, status
);
102 if (copy_to_user(data
, strbuf
, strlen(strbuf
)+1))
108 MAG_ERR("MSENSOR_IOCTL_READ_FACTORY_SENSORDATA NULL!\n ");
113 MAG_ERR("unknown IOCTL: 0x%08x\n", cmd
);
122 static struct file_operations mag_factory_fops
= {
123 .open
= mag_factory_open
,
124 .release
= mag_factory_release
,
125 .unlocked_ioctl
= mag_factory_unlocked_ioctl
,
128 static struct miscdevice mag_factory_device
= {
129 .minor
= MISC_DYNAMIC_MINOR
,
131 .fops
= &mag_factory_fops
,
134 int mag_factory_device_init()
137 struct mag_context
*cxt
= mag_context_obj
;
138 if (!cxt
->mag_ctl
.is_use_common_factory
) {
139 MAG_LOG("Node of '/dev/msensor' has already existed!\n");
142 if ((error
= misc_register(&mag_factory_device
)))
144 MAG_ERR("mag_factory_device register failed\n");