Commit | Line | Data |
---|---|---|
6fa3eb70 S |
1 | |
2 | #include "accel.h" | |
3 | ||
4 | static struct acc_context *acc_context_obj = NULL; | |
5 | ||
6 | ||
7 | static struct acc_init_info* gsensor_init_list[MAX_CHOOSE_G_NUM]= {0}; //modified | |
8 | static void acc_early_suspend(struct early_suspend *h); | |
9 | static void acc_late_resume(struct early_suspend *h); | |
10 | ||
11 | static void acc_work_func(struct work_struct *work) | |
12 | { | |
13 | ||
14 | struct acc_context *cxt = NULL; | |
15 | int out_size; | |
16 | //hwm_sensor_data sensor_data; | |
17 | int x,y,z,status,div; | |
18 | int64_t nt; | |
19 | struct timespec time; | |
20 | int err, idx; | |
21 | ||
22 | cxt = acc_context_obj; | |
23 | ||
24 | if(NULL == cxt->acc_data.get_data) | |
25 | { | |
26 | ACC_LOG("acc driver not register data path\n"); | |
27 | } | |
28 | ||
29 | ||
30 | time.tv_sec = time.tv_nsec = 0; | |
31 | time = get_monotonic_coarse(); | |
32 | nt = time.tv_sec*1000000000LL+time.tv_nsec; | |
33 | ||
34 | err = cxt->acc_data.get_data(&x,&y,&z,&status); | |
35 | ||
36 | if(err) | |
37 | { | |
38 | ACC_ERR("get acc data fails!!\n" ); | |
39 | goto acc_loop; | |
40 | } | |
41 | else | |
42 | { | |
43 | { | |
44 | if( 0 == x && 0==y | |
45 | && 0 == z) | |
46 | { | |
47 | goto acc_loop; | |
48 | } | |
49 | ||
50 | cxt->drv_data.acc_data.values[0] = x; | |
51 | cxt->drv_data.acc_data.values[1] = y; | |
52 | cxt->drv_data.acc_data.values[2] = z; | |
53 | cxt->drv_data.acc_data.status = status; | |
54 | cxt->drv_data.acc_data.time = nt; | |
55 | ||
56 | } | |
57 | } | |
58 | ||
59 | if(true == cxt->is_first_data_after_enable) | |
60 | { | |
61 | cxt->is_first_data_after_enable = false; | |
62 | //filter -1 value | |
63 | if(ACC_INVALID_VALUE == cxt->drv_data.acc_data.values[0] || | |
64 | ACC_INVALID_VALUE == cxt->drv_data.acc_data.values[1] || | |
65 | ACC_INVALID_VALUE == cxt->drv_data.acc_data.values[2]) | |
66 | { | |
67 | ACC_LOG(" read invalid data \n"); | |
68 | goto acc_loop; | |
69 | ||
70 | } | |
71 | } | |
72 | //report data to input device | |
73 | //printk("new acc work run....\n"); | |
74 | //ACC_LOG("acc data[%d,%d,%d] \n" ,cxt->drv_data.acc_data.values[0], | |
75 | //cxt->drv_data.acc_data.values[1],cxt->drv_data.acc_data.values[2]); | |
76 | ||
77 | acc_data_report(cxt->drv_data.acc_data.values[0], | |
78 | cxt->drv_data.acc_data.values[1],cxt->drv_data.acc_data.values[2], | |
79 | cxt->drv_data.acc_data.status); | |
80 | ||
81 | acc_loop: | |
82 | if(true == cxt->is_polling_run) | |
83 | { | |
84 | mod_timer(&cxt->timer, jiffies + atomic_read(&cxt->delay)/(1000/HZ)); | |
85 | } | |
86 | } | |
87 | ||
88 | static void acc_poll(unsigned long data) | |
89 | { | |
90 | struct acc_context *obj = (struct acc_context *)data; | |
91 | if(obj != NULL) | |
92 | { | |
93 | schedule_work(&obj->report); | |
94 | } | |
95 | } | |
96 | ||
97 | static struct acc_context *acc_context_alloc_object(void) | |
98 | { | |
99 | ||
100 | struct acc_context *obj = kzalloc(sizeof(*obj), GFP_KERNEL); | |
101 | ACC_LOG("acc_context_alloc_object++++\n"); | |
102 | if(!obj) | |
103 | { | |
104 | ACC_ERR("Alloc accel object error!\n"); | |
105 | return NULL; | |
106 | } | |
107 | atomic_set(&obj->delay, 200); /*5Hz*/// set work queue delay time 200ms | |
108 | atomic_set(&obj->wake, 0); | |
109 | INIT_WORK(&obj->report, acc_work_func); | |
110 | init_timer(&obj->timer); | |
111 | obj->timer.expires = jiffies + atomic_read(&obj->delay)/(1000/HZ); | |
112 | obj->timer.function = acc_poll; | |
113 | obj->timer.data = (unsigned long)obj; | |
114 | obj->is_first_data_after_enable = false; | |
115 | obj->is_polling_run = false; | |
116 | mutex_init(&obj->acc_op_mutex); | |
117 | obj->is_batch_enable = false;//for batch mode init | |
118 | ACC_LOG("acc_context_alloc_object----\n"); | |
119 | return obj; | |
120 | } | |
121 | ||
122 | static int acc_real_enable(int enable) | |
123 | { | |
124 | int err =0; | |
125 | struct acc_context *cxt = NULL; | |
126 | cxt = acc_context_obj; | |
127 | if(1==enable) | |
128 | { | |
129 | ||
130 | if(true==cxt->is_active_data || true ==cxt->is_active_nodata) | |
131 | { | |
132 | err = cxt->acc_ctl.enable_nodata(1); | |
133 | if(err) | |
134 | { | |
135 | err = cxt->acc_ctl.enable_nodata(1); | |
136 | if(err) | |
137 | { | |
138 | err = cxt->acc_ctl.enable_nodata(1); | |
139 | if(err) | |
140 | ACC_ERR("acc enable(%d) err 3 timers = %d\n", enable, err); | |
141 | } | |
142 | } | |
143 | ACC_LOG("acc real enable \n" ); | |
144 | } | |
145 | ||
146 | } | |
147 | if(0==enable) | |
148 | { | |
149 | if(false==cxt->is_active_data && false ==cxt->is_active_nodata) | |
150 | { | |
151 | err = cxt->acc_ctl.enable_nodata(0); | |
152 | if(err) | |
153 | { | |
154 | ACC_ERR("acc enable(%d) err = %d\n", enable, err); | |
155 | } | |
156 | ACC_LOG("acc real disable \n" ); | |
157 | } | |
158 | ||
159 | } | |
160 | ||
161 | return err; | |
162 | } | |
163 | static int acc_enable_data(int enable) | |
164 | { | |
165 | struct acc_context *cxt = NULL; | |
166 | int err =0; | |
167 | cxt = acc_context_obj; | |
168 | if(NULL == cxt->acc_ctl.open_report_data) | |
169 | { | |
170 | ACC_ERR("no acc control path\n"); | |
171 | return -1; | |
172 | } | |
173 | ||
174 | if(1 == enable) | |
175 | { | |
176 | ACC_LOG("ACC enable data\n"); | |
177 | cxt->is_active_data =true; | |
178 | cxt->is_first_data_after_enable = true; | |
179 | cxt->acc_ctl.open_report_data(1); | |
180 | if(false == cxt->is_polling_run && cxt->is_batch_enable == false) | |
181 | { | |
182 | if(false == cxt->acc_ctl.is_report_input_direct) | |
183 | { | |
184 | mod_timer(&cxt->timer, jiffies + atomic_read(&cxt->delay)/(1000/HZ)); | |
185 | cxt->is_polling_run = true; | |
186 | } | |
187 | } | |
188 | } | |
189 | if(0 == enable) | |
190 | { | |
191 | ACC_LOG("ACC disable \n"); | |
192 | ||
193 | cxt->is_active_data =false; | |
194 | cxt->acc_ctl.open_report_data(0); | |
195 | if(true == cxt->is_polling_run) | |
196 | { | |
197 | if(false == cxt->acc_ctl.is_report_input_direct) | |
198 | { | |
199 | cxt->is_polling_run = false; | |
200 | del_timer_sync(&cxt->timer); | |
201 | cancel_work_sync(&cxt->report); | |
202 | cxt->drv_data.acc_data.values[0] = ACC_INVALID_VALUE; | |
203 | cxt->drv_data.acc_data.values[1] = ACC_INVALID_VALUE; | |
204 | cxt->drv_data.acc_data.values[2] = ACC_INVALID_VALUE; | |
205 | } | |
206 | } | |
207 | ||
208 | } | |
209 | acc_real_enable(enable); | |
210 | return 0; | |
211 | } | |
212 | ||
213 | ||
214 | ||
215 | int acc_enable_nodata(int enable) | |
216 | { | |
217 | struct acc_context *cxt = NULL; | |
218 | int err =0; | |
219 | cxt = acc_context_obj; | |
220 | if(NULL == cxt->acc_ctl.enable_nodata) | |
221 | { | |
222 | ACC_ERR("acc_enable_nodata:acc ctl path is NULL\n"); | |
223 | return -1; | |
224 | } | |
225 | ||
226 | if(1 == enable) | |
227 | { | |
228 | cxt->is_active_nodata = true; | |
229 | } | |
230 | ||
231 | if(0 == enable) | |
232 | { | |
233 | cxt->is_active_nodata = false; | |
234 | } | |
235 | acc_real_enable(enable); | |
236 | return 0; | |
237 | } | |
238 | ||
239 | ||
240 | static ssize_t acc_show_enable_nodata(struct device* dev, | |
241 | struct device_attribute *attr, char *buf) | |
242 | { | |
243 | int len = 0; | |
244 | ACC_LOG(" not support now\n"); | |
245 | return len; | |
246 | } | |
247 | ||
248 | static ssize_t acc_store_enable_nodata(struct device* dev, struct device_attribute *attr, | |
249 | const char *buf, size_t count) | |
250 | { | |
251 | ACC_LOG("acc_store_enable nodata buf=%s\n",buf); | |
252 | mutex_lock(&acc_context_obj->acc_op_mutex); | |
253 | struct acc_context *cxt = NULL; | |
254 | int err =0; | |
255 | cxt = acc_context_obj; | |
256 | if(NULL == cxt->acc_ctl.enable_nodata) | |
257 | { | |
258 | ACC_LOG("acc_ctl enable nodata NULL\n"); | |
259 | mutex_unlock(&acc_context_obj->acc_op_mutex); | |
260 | return count; | |
261 | } | |
262 | if (!strncmp(buf, "1", 1)) | |
263 | { | |
264 | //cxt->acc_ctl.enable_nodata(1); | |
265 | acc_enable_nodata(1); | |
266 | } | |
267 | else if (!strncmp(buf, "0", 1)) | |
268 | { | |
269 | //cxt->acc_ctl.enable_nodata(0); | |
270 | acc_enable_nodata(0); | |
271 | } | |
272 | else | |
273 | { | |
274 | ACC_ERR(" acc_store enable nodata cmd error !!\n"); | |
275 | } | |
276 | mutex_unlock(&acc_context_obj->acc_op_mutex); | |
277 | } | |
278 | ||
279 | static ssize_t acc_store_active(struct device* dev, struct device_attribute *attr, | |
280 | const char *buf, size_t count) | |
281 | { | |
282 | ACC_LOG("acc_store_active buf=%s\n",buf); | |
283 | mutex_lock(&acc_context_obj->acc_op_mutex); | |
284 | struct acc_context *cxt = NULL; | |
285 | int err =0; | |
286 | cxt = acc_context_obj; | |
287 | if(NULL == cxt->acc_ctl.open_report_data) | |
288 | { | |
289 | ACC_LOG("acc_ctl enable NULL\n"); | |
290 | mutex_unlock(&acc_context_obj->acc_op_mutex); | |
291 | return count; | |
292 | } | |
293 | if (!strncmp(buf, "1", 1)) | |
294 | { | |
295 | // cxt->acc_ctl.enable(1); | |
296 | acc_enable_data(1); | |
297 | ||
298 | } | |
299 | else if (!strncmp(buf, "0", 1)) | |
300 | { | |
301 | ||
302 | //cxt->acc_ctl.enable(0); | |
303 | acc_enable_data(0); | |
304 | } | |
305 | else | |
306 | { | |
307 | ACC_ERR(" acc_store_active error !!\n"); | |
308 | } | |
309 | mutex_unlock(&acc_context_obj->acc_op_mutex); | |
310 | ACC_LOG(" acc_store_active done\n"); | |
311 | return count; | |
312 | } | |
313 | /*----------------------------------------------------------------------------*/ | |
314 | static ssize_t acc_show_active(struct device* dev, | |
315 | struct device_attribute *attr, char *buf) | |
316 | { | |
317 | struct acc_context *cxt = NULL; | |
318 | cxt = acc_context_obj; | |
319 | int div=cxt->acc_data.vender_div; | |
320 | ACC_LOG("acc vender_div value: %d\n", div); | |
321 | return snprintf(buf, PAGE_SIZE, "%d\n", div); | |
322 | } | |
323 | ||
324 | static ssize_t acc_store_delay(struct device* dev, struct device_attribute *attr, | |
325 | const char *buf, size_t count) | |
326 | { | |
327 | mutex_lock(&acc_context_obj->acc_op_mutex); | |
328 | struct acc_context *devobj = (struct acc_context*)dev_get_drvdata(dev); | |
329 | int delay; | |
330 | int mdelay=0; | |
331 | struct acc_context *cxt = NULL; | |
332 | int err =0; | |
333 | cxt = acc_context_obj; | |
334 | if(NULL == cxt->acc_ctl.set_delay) | |
335 | { | |
336 | ACC_LOG("acc_ctl set_delay NULL\n"); | |
337 | mutex_unlock(&acc_context_obj->acc_op_mutex); | |
338 | return count; | |
339 | } | |
340 | ||
341 | if (1 != sscanf(buf, "%d", &delay)) { | |
342 | ACC_ERR("invalid format!!\n"); | |
343 | mutex_unlock(&acc_context_obj->acc_op_mutex); | |
344 | return count; | |
345 | } | |
346 | ||
347 | if(false == cxt->acc_ctl.is_report_input_direct) | |
348 | { | |
349 | mdelay = (int)delay/1000/1000; | |
350 | atomic_set(&acc_context_obj->delay, mdelay); | |
351 | } | |
352 | cxt->acc_ctl.set_delay(delay); | |
353 | ACC_LOG(" acc_delay %d ns\n",delay); | |
354 | mutex_unlock(&acc_context_obj->acc_op_mutex); | |
355 | return count; | |
356 | } | |
357 | ||
358 | static ssize_t acc_show_delay(struct device* dev, | |
359 | struct device_attribute *attr, char *buf) | |
360 | { | |
361 | int len = 0; | |
362 | ACC_LOG(" not support now\n"); | |
363 | return len; | |
364 | } | |
365 | ||
366 | static ssize_t acc_show_sensordevnum(struct device* dev, | |
367 | struct device_attribute *attr, char *buf) | |
368 | { | |
369 | struct acc_context *cxt = NULL; | |
370 | char *devname = NULL; | |
371 | cxt = acc_context_obj; | |
372 | devname = dev_name(&cxt->idev->dev); | |
373 | return snprintf(buf, PAGE_SIZE, "%s\n", devname+5); | |
374 | } | |
375 | ||
376 | ||
377 | static ssize_t acc_store_batch(struct device* dev, struct device_attribute *attr, | |
378 | const char *buf, size_t count) | |
379 | { | |
380 | ACC_LOG("acc_store_batch buf=%s\n",buf); | |
381 | mutex_lock(&acc_context_obj->acc_op_mutex); | |
382 | struct acc_context *cxt = NULL; | |
383 | int err =0; | |
384 | cxt = acc_context_obj; | |
385 | if(cxt->acc_ctl.is_support_batch){ | |
386 | if (!strncmp(buf, "1", 1)) | |
387 | { | |
388 | cxt->is_batch_enable = true; | |
389 | } | |
390 | else if (!strncmp(buf, "0", 1)) | |
391 | { | |
392 | cxt->is_batch_enable = false; | |
393 | } | |
394 | else | |
395 | { | |
396 | ACC_ERR(" acc_store_batch error !!\n"); | |
397 | } | |
398 | }else{ | |
399 | ACC_LOG(" acc_store_batch mot supported\n"); | |
400 | } | |
401 | mutex_unlock(&acc_context_obj->acc_op_mutex); | |
402 | ACC_LOG(" acc_store_batch done: %d\n", cxt->is_batch_enable); | |
403 | return count; | |
404 | ||
405 | } | |
406 | ||
407 | static ssize_t acc_show_batch(struct device* dev, | |
408 | struct device_attribute *attr, char *buf) | |
409 | { | |
410 | return snprintf(buf, PAGE_SIZE, "%d\n", 0); | |
411 | } | |
412 | ||
413 | static ssize_t acc_store_flush(struct device* dev, struct device_attribute *attr, | |
414 | const char *buf, size_t count) | |
415 | { | |
416 | mutex_lock(&acc_context_obj->acc_op_mutex); | |
417 | struct acc_context *devobj = (struct acc_context*)dev_get_drvdata(dev); | |
418 | //do read FIFO data function and report data immediately | |
419 | mutex_unlock(&acc_context_obj->acc_op_mutex); | |
420 | return count; | |
421 | } | |
422 | ||
423 | static ssize_t acc_show_flush(struct device* dev, | |
424 | struct device_attribute *attr, char *buf) | |
425 | { | |
426 | return snprintf(buf, PAGE_SIZE, "%d\n", 0); | |
427 | } | |
428 | ||
429 | static int gsensor_remove(struct platform_device *pdev) | |
430 | { | |
431 | ACC_LOG("gsensor_remove\n"); | |
432 | return 0; | |
433 | } | |
434 | ||
435 | static int gsensor_probe(struct platform_device *pdev) | |
436 | { | |
437 | ACC_LOG("gsensor_probe\n"); | |
438 | return 0; | |
439 | } | |
440 | ||
441 | static struct platform_driver gsensor_driver = { | |
442 | .probe = gsensor_probe, | |
443 | .remove = gsensor_remove, | |
444 | .driver = | |
445 | { | |
446 | .name = "gsensor", | |
447 | } | |
448 | }; | |
449 | ||
450 | static int acc_real_driver_init(void) | |
451 | { | |
452 | int i =0; | |
453 | int err=0; | |
454 | ACC_LOG(" acc_real_driver_init +\n"); | |
455 | for(i = 0; i < MAX_CHOOSE_G_NUM; i++) | |
456 | { | |
457 | ACC_LOG(" i=%d\n",i); | |
458 | if(0 != gsensor_init_list[i]) | |
459 | { | |
460 | ACC_LOG(" acc try to init driver %s\n", gsensor_init_list[i]->name); | |
461 | err = gsensor_init_list[i]->init(); | |
462 | if(0 == err) | |
463 | { | |
464 | ACC_LOG(" acc real driver %s probe ok\n", gsensor_init_list[i]->name); | |
465 | break; | |
466 | } | |
467 | } | |
468 | } | |
469 | ||
470 | if(i == MAX_CHOOSE_G_NUM) | |
471 | { | |
472 | ACC_LOG(" acc_real_driver_init fail\n"); | |
473 | err=-1; | |
474 | } | |
475 | return err; | |
476 | } | |
477 | ||
478 | int acc_driver_add(struct acc_init_info* obj) | |
479 | { | |
480 | int err=0; | |
481 | int i =0; | |
482 | ||
483 | ACC_FUN(); | |
484 | ||
485 | for(i =0; i < MAX_CHOOSE_G_NUM; i++ ) | |
486 | { | |
487 | if(i == 0){ | |
488 | ACC_LOG("register gensor driver for the first time\n"); | |
489 | if(platform_driver_register(&gsensor_driver)) | |
490 | { | |
491 | ACC_ERR("failed to register gensor driver already exist\n"); | |
492 | } | |
493 | } | |
494 | ||
495 | if(NULL == gsensor_init_list[i]) | |
496 | { | |
497 | obj->platform_diver_addr = &gsensor_driver; | |
498 | gsensor_init_list[i] = obj; | |
499 | break; | |
500 | } | |
501 | } | |
502 | if(NULL==gsensor_init_list[i]) | |
503 | { | |
504 | ACC_ERR("ACC driver add err \n"); | |
505 | err=-1; | |
506 | } | |
507 | ||
508 | return err; | |
509 | } | |
510 | EXPORT_SYMBOL_GPL(acc_driver_add); | |
511 | ||
512 | static int acc_misc_init(struct acc_context *cxt) | |
513 | { | |
514 | ||
515 | int err=0; | |
516 | cxt->mdev.minor = MISC_DYNAMIC_MINOR; | |
517 | cxt->mdev.name = ACC_MISC_DEV_NAME; | |
518 | if((err = misc_register(&cxt->mdev))) | |
519 | { | |
520 | ACC_ERR("unable to register acc misc device!!\n"); | |
521 | } | |
522 | //dev_set_drvdata(cxt->mdev.this_device, cxt); | |
523 | return err; | |
524 | } | |
525 | ||
526 | static void acc_input_destroy(struct acc_context *cxt) | |
527 | { | |
528 | struct input_dev *dev = cxt->idev; | |
529 | ||
530 | input_unregister_device(dev); | |
531 | input_free_device(dev); | |
532 | } | |
533 | ||
534 | static int acc_input_init(struct acc_context *cxt) | |
535 | { | |
536 | struct input_dev *dev; | |
537 | int err = 0; | |
538 | ||
539 | dev = input_allocate_device(); | |
540 | if (NULL == dev) | |
541 | return -ENOMEM; | |
542 | ||
543 | dev->name = ACC_INPUTDEV_NAME; | |
544 | ||
545 | input_set_capability(dev, EV_ABS, EVENT_TYPE_ACCEL_X); | |
546 | input_set_capability(dev, EV_ABS, EVENT_TYPE_ACCEL_Y); | |
547 | input_set_capability(dev, EV_ABS, EVENT_TYPE_ACCEL_Z); | |
548 | input_set_capability(dev, EV_ABS, EVENT_TYPE_ACCEL_STATUS); | |
549 | ||
550 | input_set_abs_params(dev, EVENT_TYPE_ACCEL_X, ACC_VALUE_MIN, ACC_VALUE_MAX, 0, 0); | |
551 | input_set_abs_params(dev, EVENT_TYPE_ACCEL_Y, ACC_VALUE_MIN, ACC_VALUE_MAX, 0, 0); | |
552 | input_set_abs_params(dev, EVENT_TYPE_ACCEL_Z, ACC_VALUE_MIN, ACC_VALUE_MAX, 0, 0); | |
553 | input_set_abs_params(dev, EVENT_TYPE_ACCEL_STATUS, ACC_STATUS_MIN, ACC_STATUS_MAX, 0, 0); | |
554 | input_set_drvdata(dev, cxt); | |
555 | ||
556 | err = input_register_device(dev); | |
557 | if (err < 0) { | |
558 | input_free_device(dev); | |
559 | return err; | |
560 | } | |
561 | cxt->idev= dev; | |
562 | ||
563 | return 0; | |
564 | } | |
565 | ||
566 | DEVICE_ATTR(accenablenodata, S_IWUSR | S_IRUGO, acc_show_enable_nodata, acc_store_enable_nodata); | |
567 | DEVICE_ATTR(accactive, S_IWUSR | S_IRUGO, acc_show_active, acc_store_active); | |
568 | DEVICE_ATTR(accdelay, S_IWUSR | S_IRUGO, acc_show_delay, acc_store_delay); | |
569 | DEVICE_ATTR(accbatch, S_IWUSR | S_IRUGO, acc_show_batch, acc_store_batch); | |
570 | DEVICE_ATTR(accflush, S_IWUSR | S_IRUGO, acc_show_flush, acc_store_flush); | |
571 | DEVICE_ATTR(accdevnum, S_IWUSR | S_IRUGO, acc_show_sensordevnum, NULL); | |
572 | ||
573 | static struct attribute *acc_attributes[] = { | |
574 | &dev_attr_accenablenodata.attr, | |
575 | &dev_attr_accactive.attr, | |
576 | &dev_attr_accdelay.attr, | |
577 | &dev_attr_accbatch.attr, | |
578 | &dev_attr_accflush.attr, | |
579 | &dev_attr_accdevnum.attr, | |
580 | NULL | |
581 | }; | |
582 | ||
583 | static struct attribute_group acc_attribute_group = { | |
584 | .attrs = acc_attributes | |
585 | }; | |
586 | ||
587 | int acc_register_data_path(struct acc_data_path *data) | |
588 | { | |
589 | struct acc_context *cxt = NULL; | |
590 | int err =0; | |
591 | cxt = acc_context_obj; | |
592 | cxt->acc_data.get_data = data->get_data; | |
593 | cxt->acc_data.vender_div = data->vender_div; | |
594 | ACC_LOG("acc register data path vender_div: %d\n", cxt->acc_data.vender_div); | |
595 | if(NULL == cxt->acc_data.get_data) | |
596 | { | |
597 | ACC_LOG("acc register data path fail \n"); | |
598 | return -1; | |
599 | } | |
600 | return 0; | |
601 | } | |
602 | ||
603 | int acc_register_control_path(struct acc_control_path *ctl) | |
604 | { | |
605 | struct acc_context *cxt = NULL; | |
606 | int err =0; | |
607 | cxt = acc_context_obj; | |
608 | cxt->acc_ctl.set_delay = ctl->set_delay; | |
609 | cxt->acc_ctl.open_report_data= ctl->open_report_data; | |
610 | cxt->acc_ctl.enable_nodata = ctl->enable_nodata; | |
611 | cxt->acc_ctl.is_support_batch = ctl->is_support_batch; | |
612 | cxt->acc_ctl.is_report_input_direct= ctl->is_report_input_direct; | |
613 | ||
614 | if(NULL==cxt->acc_ctl.set_delay || NULL==cxt->acc_ctl.open_report_data | |
615 | || NULL==cxt->acc_ctl.enable_nodata) | |
616 | { | |
617 | ACC_LOG("acc register control path fail \n"); | |
618 | return -1; | |
619 | } | |
620 | ||
621 | //add misc dev for sensor hal control cmd | |
622 | err = acc_misc_init(acc_context_obj); | |
623 | if(err) | |
624 | { | |
625 | ACC_ERR("unable to register acc misc device!!\n"); | |
626 | return -2; | |
627 | } | |
628 | err = sysfs_create_group(&acc_context_obj->mdev.this_device->kobj, | |
629 | &acc_attribute_group); | |
630 | if (err < 0) | |
631 | { | |
632 | ACC_ERR("unable to create acc attribute file\n"); | |
633 | return -3; | |
634 | } | |
635 | ||
636 | kobject_uevent(&acc_context_obj->mdev.this_device->kobj, KOBJ_ADD); | |
637 | ||
638 | return 0; | |
639 | } | |
640 | ||
641 | int acc_data_report(int x, int y, int z,int status) | |
642 | { | |
643 | //ACC_LOG("+acc_data_report! %d, %d, %d, %d\n",x,y,z,status); | |
644 | struct acc_context *cxt = NULL; | |
645 | int err =0; | |
646 | cxt = acc_context_obj; | |
647 | input_report_abs(cxt->idev, EVENT_TYPE_ACCEL_X, x); | |
648 | input_report_abs(cxt->idev, EVENT_TYPE_ACCEL_Y, y); | |
649 | input_report_abs(cxt->idev, EVENT_TYPE_ACCEL_Z, z); | |
650 | input_report_abs(cxt->idev, EVENT_TYPE_ACCEL_STATUS, status); | |
651 | input_sync(cxt->idev); | |
652 | } | |
653 | ||
654 | static int acc_probe(struct platform_device *pdev) | |
655 | { | |
656 | ||
657 | int err; | |
658 | ACC_LOG("+++++++++++++accel_probe!!\n"); | |
659 | ||
660 | acc_context_obj = acc_context_alloc_object(); | |
661 | if (!acc_context_obj) | |
662 | { | |
663 | err = -ENOMEM; | |
664 | ACC_ERR("unable to allocate devobj!\n"); | |
665 | goto exit_alloc_data_failed; | |
666 | } | |
667 | ||
668 | //init real acceleration driver | |
669 | err = acc_real_driver_init(); | |
670 | if(err) | |
671 | { | |
672 | ACC_ERR("acc real driver init fail\n"); | |
673 | goto real_driver_init_fail; | |
674 | } | |
675 | ||
676 | //init input dev | |
677 | err = acc_input_init(acc_context_obj); | |
678 | if(err) | |
679 | { | |
680 | ACC_ERR("unable to register acc input device!\n"); | |
681 | goto exit_alloc_input_dev_failed; | |
682 | } | |
683 | ||
684 | atomic_set(&(acc_context_obj->early_suspend), 0); | |
685 | acc_context_obj->early_drv.level = EARLY_SUSPEND_LEVEL_STOP_DRAWING - 1, | |
686 | acc_context_obj->early_drv.suspend = acc_early_suspend, | |
687 | acc_context_obj->early_drv.resume = acc_late_resume, | |
688 | register_early_suspend(&acc_context_obj->early_drv); | |
689 | ||
690 | ||
691 | ACC_LOG("----accel_probe OK !!\n"); | |
692 | return 0; | |
693 | ||
694 | exit_hwmsen_create_attr_failed: | |
695 | exit_misc_register_failed: | |
696 | ||
697 | exit_err_sysfs: | |
698 | ||
699 | if (err) | |
700 | { | |
701 | ACC_ERR("sysfs node creation error \n"); | |
702 | acc_input_destroy(acc_context_obj); | |
703 | } | |
704 | ||
705 | real_driver_init_fail: | |
706 | exit_alloc_input_dev_failed: | |
707 | kfree(acc_context_obj); | |
708 | ||
709 | exit_alloc_data_failed: | |
710 | ||
711 | ||
712 | ACC_LOG("----accel_probe fail !!!\n"); | |
713 | return err; | |
714 | } | |
715 | ||
716 | ||
717 | ||
718 | static int acc_remove(struct platform_device *pdev) | |
719 | { | |
720 | ACC_FUN(f); | |
721 | int err=0; | |
722 | input_unregister_device(acc_context_obj->idev); | |
723 | sysfs_remove_group(&acc_context_obj->idev->dev.kobj, | |
724 | &acc_attribute_group); | |
725 | ||
726 | if((err = misc_deregister(&acc_context_obj->mdev))) | |
727 | { | |
728 | ACC_ERR("misc_deregister fail: %d\n", err); | |
729 | } | |
730 | kfree(acc_context_obj); | |
731 | ||
732 | return 0; | |
733 | } | |
734 | ||
735 | static void acc_early_suspend(struct early_suspend *h) | |
736 | { | |
737 | atomic_set(&(acc_context_obj->early_suspend), 1); | |
738 | ACC_LOG(" acc_early_suspend ok------->hwm_obj->early_suspend=%d \n",atomic_read(&(acc_context_obj->early_suspend))); | |
739 | return ; | |
740 | } | |
741 | /*----------------------------------------------------------------------------*/ | |
742 | static void acc_late_resume(struct early_suspend *h) | |
743 | { | |
744 | atomic_set(&(acc_context_obj->early_suspend), 0); | |
745 | ACC_LOG(" acc_late_resume ok------->hwm_obj->early_suspend=%d \n",atomic_read(&(acc_context_obj->early_suspend))); | |
746 | return ; | |
747 | } | |
748 | ||
749 | static int acc_suspend(struct platform_device *dev, pm_message_t state) | |
750 | { | |
751 | return 0; | |
752 | } | |
753 | /*----------------------------------------------------------------------------*/ | |
754 | static int acc_resume(struct platform_device *dev) | |
755 | { | |
756 | return 0; | |
757 | } | |
758 | ||
759 | static struct platform_driver acc_driver = | |
760 | { | |
761 | .probe = acc_probe, | |
762 | .remove = acc_remove, | |
763 | .suspend = acc_suspend, | |
764 | .resume = acc_resume, | |
765 | .driver = | |
766 | { | |
767 | .name = ACC_PL_DEV_NAME, | |
768 | } | |
769 | }; | |
770 | ||
771 | static int __init acc_init(void) | |
772 | { | |
773 | ACC_FUN(); | |
774 | ||
775 | if(platform_driver_register(&acc_driver)) | |
776 | { | |
777 | ACC_ERR("failed to register acc driver\n"); | |
778 | return -ENODEV; | |
779 | } | |
780 | ||
781 | return 0; | |
782 | } | |
783 | ||
784 | static void __exit acc_exit(void) | |
785 | { | |
786 | platform_driver_unregister(&acc_driver); | |
787 | platform_driver_unregister(&gsensor_driver); | |
788 | } | |
789 | ||
790 | module_init(acc_init); | |
791 | module_exit(acc_exit); | |
792 | MODULE_LICENSE("GPL"); | |
793 | MODULE_DESCRIPTION("ACCELEROMETER device driver"); | |
794 | MODULE_AUTHOR("Mediatek"); | |
795 |