5 static struct mag_context
*mag_context_obj
= NULL
;
7 static struct mag_init_info
* msensor_init_list
[MAX_CHOOSE_G_NUM
]= {0}; //modified
9 static void mag_early_suspend(struct early_suspend
*h
);
10 static void mag_late_resume(struct early_suspend
*h
);
12 static void mag_work_func(struct work_struct
*work
)
15 struct mag_context
*cxt
= NULL
;
17 hwm_sensor_data sensor_data
;
23 cxt
= mag_context_obj
;
24 memset(&sensor_data
, 0, sizeof(sensor_data
));
25 time
.tv_sec
= time
.tv_nsec
= 0;
26 time
= get_monotonic_coarse();
27 nt
= time
.tv_sec
*1000000000LL+time
.tv_nsec
;
29 for(i
= 0; i
< MAX_M_V_SENSOR
; i
++)
31 if (NULL
== cxt
->drv_obj
[i
])
33 //MAG_LOG("%d driver not atteched\n",i);
37 if((0 == cxt
->drv_obj
[i
]->polling
) || !(cxt
->active_data_sensor
&(0x01<<i
)))
39 MAG_LOG("mag_type(%d) polling(%d) enabled(%d)\n",i
, cxt
->drv_obj
[i
]->polling
,cxt
->active_data_sensor
);
43 err
= cxt
->drv_obj
[i
]->mag_operate(cxt
->drv_obj
[i
]->self
,OP_MAG_GET_DATA
, NULL
, 0,
44 &sensor_data
, sizeof(hwm_sensor_data
), &out_size
);
48 MAG_ERR("get %d data fails!!\n" ,i
);
54 if( 0 == sensor_data
.values
[0] && 0==sensor_data
.values
[1]
55 && 0 == sensor_data
.values
[2])
57 MAG_ERR("data is zero.\n" );
61 cxt
->drv_data
[i
].mag_data
.values
[0] = sensor_data
.values
[0];
62 cxt
->drv_data
[i
].mag_data
.values
[1] = sensor_data
.values
[1];
63 cxt
->drv_data
[i
].mag_data
.values
[2] = sensor_data
.values
[2];
64 cxt
->drv_data
[i
].mag_data
.status
= sensor_data
.status
;
65 cxt
->drv_data
[i
].mag_data
.time
= nt
;
69 if(true == cxt
->is_first_data_after_enable
)
71 cxt
->is_first_data_after_enable
= false;
73 if(MAG_INVALID_VALUE
== cxt
->drv_data
[i
].mag_data
.values
[0] ||
74 MAG_INVALID_VALUE
== cxt
->drv_data
[i
].mag_data
.values
[1] ||
75 MAG_INVALID_VALUE
== cxt
->drv_data
[i
].mag_data
.values
[2])
77 MAG_LOG(" read invalid data \n");
83 if(ID_M_V_MAGNETIC
==i
)
85 mag_data_report(MAGNETIC
,cxt
->drv_data
[i
].mag_data
.values
[0],
86 cxt
->drv_data
[i
].mag_data
.values
[1],
87 cxt
->drv_data
[i
].mag_data
.values
[2],
88 cxt
->drv_data
[i
].mag_data
.status
);
90 MAG_LOG("mag_type(%d) data[%d,%d,%d] \n" ,i
,cxt
->drv_data
[i
].mag_data
.values
[0],
91 cxt
->drv_data
[i
].mag_data
.values
[1],cxt
->drv_data
[i
].mag_data
.values
[2]);
94 if(ID_M_V_ORIENTATION
==i
)
96 mag_data_report(ORIENTATION
,cxt
->drv_data
[i
].mag_data
.values
[0],
97 cxt
->drv_data
[i
].mag_data
.values
[1],
98 cxt
->drv_data
[i
].mag_data
.values
[2],
99 cxt
->drv_data
[i
].mag_data
.status
);
101 MAG_LOG("mag_type(%d) data[%d,%d,%d] \n" ,i
,cxt
->drv_data
[i
].mag_data
.values
[0],
102 cxt
->drv_data
[i
].mag_data
.values
[1],cxt
->drv_data
[i
].mag_data
.values
[2]);
108 //report data to input device
109 //printk("new mag work run....\n");
111 if(true == cxt
->is_polling_run
)
113 mod_timer(&cxt
->timer
, jiffies
+ atomic_read(&cxt
->delay
)/(1000/HZ
));
117 static void mag_poll(unsigned long data
)
119 struct mag_context
*obj
= (struct mag_context
*)data
;
122 schedule_work(&obj
->report
);
126 static struct mag_context
*mag_context_alloc_object(void)
129 struct mag_context
*obj
= kzalloc(sizeof(*obj
), GFP_KERNEL
);
130 MAG_LOG("mag_context_alloc_object++++\n");
133 MAG_ERR("Alloc magel object error!\n");
136 atomic_set(&obj
->delay
, 200); /*5Hz*/// set work queue delay time
200ms
137 atomic_set(&obj
->wake
, 0);
138 INIT_WORK(&obj
->report
, mag_work_func
);
139 init_timer(&obj
->timer
);
140 obj
->timer
.expires
= jiffies
+ atomic_read(&obj
->delay
)/(1000/HZ
);
141 obj
->timer
.function
= mag_poll
;
142 obj
->timer
.data
= (unsigned long)obj
;
143 obj
->is_first_data_after_enable
= false;
144 obj
->is_polling_run
= false;
145 obj
->active_data_sensor
= 0;
146 obj
->active_nodata_sensor
= 0;
147 obj
->is_batch_enable
= false;
148 mutex_init(&obj
->mag_op_mutex
);
149 MAG_LOG("mag_context_alloc_object----\n");
152 static int mag_enable_data(int handle
,int enable
)
154 struct mag_context
*cxt
= NULL
;
156 cxt
= mag_context_obj
;
157 if(NULL
== cxt
->drv_obj
[handle
])
159 MAG_ERR("no real mag driver\n");
165 MAG_LOG("MAG(%d) enable \n",handle
);
166 cxt
->is_first_data_after_enable
= true;
167 cxt
->active_data_sensor
|= 1<<handle
;
169 if(ID_M_V_ORIENTATION
== handle
)
171 cxt
->mag_ctl
.o_enable(1);
172 cxt
->mag_ctl
.o_open_report_data(1);
174 if(ID_M_V_MAGNETIC
== handle
)
176 cxt
->mag_ctl
.m_enable(1);
177 cxt
->mag_ctl
.m_open_report_data(1);
180 if((0!=cxt
->active_data_sensor
) && (false == cxt
->is_polling_run
)&&(false == cxt
->is_batch_enable
))
182 if(false == cxt
->mag_ctl
.is_report_input_direct
)
184 MAG_LOG("MAG(%d) mod timer \n",handle
);
185 mod_timer(&cxt
->timer
, jiffies
+ atomic_read(&cxt
->delay
)/(1000/HZ
));
186 cxt
->is_polling_run
= true;
194 MAG_LOG("MAG(%d) disable \n",handle
);
195 cxt
->active_data_sensor
&= ~(1<<handle
);
196 if(ID_M_V_ORIENTATION
== handle
)
198 cxt
->mag_ctl
.o_enable(0);
199 cxt
->mag_ctl
.o_open_report_data(0);
201 if(ID_M_V_MAGNETIC
== handle
)
203 cxt
->mag_ctl
.m_enable(0);
204 cxt
->mag_ctl
.m_open_report_data(0);
207 if(0 == cxt
->active_data_sensor
&& true == cxt
->is_polling_run
)
209 if(false == cxt
->mag_ctl
.is_report_input_direct
)
211 MAG_LOG("MAG(%d) del timer \n",handle
);
212 cxt
->is_polling_run
= false;
213 del_timer_sync(&cxt
->timer
);
214 cancel_work_sync(&cxt
->report
);
215 cxt
->drv_data
[handle
].mag_data
.values
[0] = MAG_INVALID_VALUE
;
216 cxt
->drv_data
[handle
].mag_data
.values
[1] = MAG_INVALID_VALUE
;
217 cxt
->drv_data
[handle
].mag_data
.values
[2] = MAG_INVALID_VALUE
;
223 //mag_real_enable(handle,enable);
227 static int m_enable_data(int en
)
230 err
=mag_enable_data(ID_M_V_MAGNETIC
,en
);
233 static int o_enable_data(int en
)
236 err
=mag_enable_data(ID_M_V_ORIENTATION
,en
);
241 static int m_set_delay(u64 delay)//ns
244 m_delay = (int)delay/1000/1000;
246 if(NULL == mag_context_obj->drv_obj[ID_M_V_MAGNETIC])
248 MAG_ERR("no real mag driver\n");
251 if(mag_context_obj->drv_obj[ID_M_V_MAGNETIC]->mag_operate(mag_context_obj->drv_obj[ID_M_V_MAGNETIC]->self, OP_MAG_DELAY, &m_delay,sizeof(int), NULL, 0, NULL) != 0)
253 MAG_ERR("mag sensor_operate set delay function error \r\n");
256 atomic_set(&mag_context_obj->delay, m_delay);
257 MAG_LOG(" mag_delay %d ms\n",m_delay);
261 static int o_set_delay(u64 delay)//ns
264 m_delay = (int)delay/1000/1000;
266 if(NULL == mag_context_obj->drv_obj[ID_M_V_ORIENTATION])
268 MAG_ERR("no real mag odriver\n");
272 if(mag_context_obj->drv_obj[ID_M_V_ORIENTATION]->mag_operate(mag_context_obj->drv_obj[ID_M_V_ORIENTATION]->self, OP_MAG_DELAY, &m_delay,sizeof(int), NULL, 0, NULL) != 0)
274 MAG_ERR("mag osensor_operate set delay function error \r\n");
276 atomic_set(&mag_context_obj->delay, m_delay);
277 MAG_LOG(" mag_odelay %d ms\n",m_delay);
283 /*----------------------------------------------------------------------------*/
284 static ssize_t
mag_show_magdev(struct device
* dev
,
285 struct device_attribute
*attr
, char *buf
)
288 printk("sensor test: mag function!\n");
291 /*----------------------------------------------------------------------------*/
293 static ssize_t
mag_store_oactive(struct device
* dev
, struct device_attribute
*attr
,
294 const char *buf
, size_t count
)
296 MAG_LOG("mag_store_oactive buf=%s\n",buf
);
297 mutex_lock(&mag_context_obj
->mag_op_mutex
);
298 struct mag_context
*cxt
= NULL
;
300 cxt
= mag_context_obj
;
301 if(NULL
== cxt
->mag_ctl
.o_enable
)
303 mutex_unlock(&mag_context_obj
->mag_op_mutex
);
304 MAG_LOG("mag_ctl o-enable NULL\n");
308 if (!strncmp(buf
, "1", 1))
310 mag_enable_data(ID_M_V_ORIENTATION
,1);
311 //cxt->mag_ctl.o_enable(1);
313 else if (!strncmp(buf
, "0", 1))
315 mag_enable_data(ID_M_V_ORIENTATION
,0);
316 //cxt->mag_ctl.o_enable(0);
320 MAG_ERR(" mag_store_oactive error !!\n");
322 mutex_unlock(&mag_context_obj
->mag_op_mutex
);
323 MAG_LOG(" mag_store_oactive done\n");
326 /*----------------------------------------------------------------------------*/
327 static ssize_t
mag_show_oactive(struct device
* dev
,
328 struct device_attribute
*attr
, char *buf
)
330 struct mag_context
*cxt
= NULL
;
331 cxt
= mag_context_obj
;
333 int div
= cxt
->mag_dev_data
.div_o
;
334 ACC_LOG("acc mag_dev_data o_div value: %d\n", div
);
335 return snprintf(buf
, PAGE_SIZE
, "%d\n", div
);
339 static ssize_t
mag_store_active(struct device
* dev
, struct device_attribute
*attr
,
340 const char *buf
, size_t count
)
342 MAG_LOG("mag_store_active buf=%s\n",buf
);
343 mutex_lock(&mag_context_obj
->mag_op_mutex
);
344 struct mag_context
*cxt
= NULL
;
346 cxt
= mag_context_obj
;
347 if(NULL
== cxt
->mag_ctl
.m_enable
)
349 mutex_unlock(&mag_context_obj
->mag_op_mutex
);
350 MAG_LOG("mag_ctl path is NULL\n");
354 if (!strncmp(buf
, "1", 1))
356 mag_enable_data(ID_M_V_MAGNETIC
,1);
357 //cxt->mag_ctl.m_enable(1);
359 else if (!strncmp(buf
, "0", 1))
361 mag_enable_data(ID_M_V_MAGNETIC
,0);
362 //cxt->mag_ctl.m_enable(0);
366 MAG_ERR(" mag_store_active error !!\n");
368 mutex_unlock(&mag_context_obj
->mag_op_mutex
);
369 MAG_LOG(" mag_store_active done\n");
372 /*----------------------------------------------------------------------------*/
373 static ssize_t
mag_show_active(struct device
* dev
,
374 struct device_attribute
*attr
, char *buf
)
376 struct mag_context
*cxt
= NULL
;
377 cxt
= mag_context_obj
;
379 int div
= cxt
->mag_dev_data
.div_m
;
380 ACC_LOG("acc mag_dev_data m_div value: %d\n", div
);
381 return snprintf(buf
, PAGE_SIZE
, "%d\n", div
);
384 static ssize_t
mag_store_odelay(struct device
* dev
, struct device_attribute
*attr
,
385 const char *buf
, size_t count
)
387 mutex_lock(&mag_context_obj
->mag_op_mutex
);
388 struct mag_context
*devobj
= (struct mag_context
*)dev_get_drvdata(dev
);
391 struct mag_context
*cxt
= NULL
;
393 cxt
= mag_context_obj
;
394 if(NULL
== cxt
->mag_ctl
.o_set_delay
)
396 mutex_unlock(&mag_context_obj
->mag_op_mutex
);
397 MAG_LOG("mag_ctl o_delay NULL\n");
401 MAG_LOG(" mag_odelay ++ \n");
404 if (1 != sscanf(buf
, "%d", &delay
)) {
405 mutex_unlock(&mag_context_obj
->mag_op_mutex
);
406 MAG_ERR("invalid format!!\n");
409 if(false == cxt
->mag_ctl
.is_report_input_direct
)
411 mdelay
= (int)delay
/1000/1000;
412 atomic_set(&mag_context_obj
->delay
, mdelay
);
414 cxt
->mag_ctl
.o_set_delay(delay
);
415 mutex_unlock(&mag_context_obj
->mag_op_mutex
);
416 MAG_LOG(" mag_odelay %d ns done\n",delay
);
420 static ssize_t
mag_show_odelay(struct device
* dev
,
421 struct device_attribute
*attr
, char *buf
)
424 MAG_LOG(" not support now\n");
428 static ssize_t
mag_store_delay(struct device
* dev
, struct device_attribute
*attr
,
429 const char *buf
, size_t count
)
431 mutex_lock(&mag_context_obj
->mag_op_mutex
);
432 struct mag_context
*devobj
= (struct mag_context
*)dev_get_drvdata(dev
);
435 struct mag_context
*cxt
= NULL
;
437 cxt
= mag_context_obj
;
438 if(NULL
== cxt
->mag_ctl
.m_set_delay
)
440 mutex_unlock(&mag_context_obj
->mag_op_mutex
);
441 MAG_LOG("mag_ctl m_delay NULL\n");
445 MAG_LOG(" mag_delay ++ \n");
447 if (1 != sscanf(buf
, "%d", &delay
)) {
448 mutex_unlock(&mag_context_obj
->mag_op_mutex
);
449 MAG_ERR("invalid format!!\n");
452 if(false == cxt
->mag_ctl
.is_report_input_direct
)
454 mdelay
= (int)delay
/1000/1000;
455 atomic_set(&mag_context_obj
->delay
, mdelay
);
457 cxt
->mag_ctl
.m_set_delay(delay
);
458 mutex_unlock(&mag_context_obj
->mag_op_mutex
);
459 MAG_LOG(" mag_delay %d ns done\n",delay
);
463 static ssize_t
mag_show_delay(struct device
* dev
,
464 struct device_attribute
*attr
, char *buf
)
467 MAG_LOG(" not support now\n");
471 static ssize_t
mag_store_batch(struct device
* dev
, struct device_attribute
*attr
,
472 const char *buf
, size_t count
)
474 MAG_LOG("mag_store_batch buf=%s\n",buf
);
475 mutex_lock(&mag_context_obj
->mag_op_mutex
);
476 struct mag_context
*cxt
= NULL
;
478 cxt
= mag_context_obj
;
479 if(cxt
->mag_ctl
.is_support_batch
){
480 if (!strncmp(buf
, "1", 1))
482 cxt
->is_batch_enable
= true;
484 else if (!strncmp(buf
, "0", 1))
486 cxt
->is_batch_enable
= false;
490 MAG_ERR(" mag_store_batch error !!\n");
493 MAG_LOG(" mag_store_batch not supported\n");
495 mutex_unlock(&mag_context_obj
->mag_op_mutex
);
496 MAG_LOG(" mag_store_batch done: %d\n", cxt
->is_batch_enable
);
501 static ssize_t
mag_show_batch(struct device
* dev
,
502 struct device_attribute
*attr
, char *buf
)
505 MAG_LOG(" not support now\n");
509 static ssize_t
mag_store_flush(struct device
* dev
, struct device_attribute
*attr
,
510 const char *buf
, size_t count
)
514 static ssize_t
mag_show_sensordevnum(struct device
* dev
,
515 struct device_attribute
*attr
, char *buf
)
517 struct mag_context
*cxt
= NULL
;
518 char *devname
= NULL
;
519 cxt
= mag_context_obj
;
520 devname
= dev_name(&cxt
->idev
->dev
);
522 return snprintf(buf
, PAGE_SIZE
, "%s\n", devname
+5);
526 static ssize_t
mag_show_flush(struct device
* dev
,
527 struct device_attribute
*attr
, char *buf
)
530 MAG_LOG(" not support now\n");
534 static ssize_t
mag_store_obatch(struct device
* dev
, struct device_attribute
*attr
,
535 const char *buf
, size_t count
)
537 MAG_LOG("mag_store_obatch buf=%s\n",buf
);
538 mutex_lock(&mag_context_obj
->mag_op_mutex
);
539 struct mag_context
*cxt
= NULL
;
541 cxt
= mag_context_obj
;
542 if(cxt
->mag_ctl
.is_support_batch
){
543 if (!strncmp(buf
, "1", 1))
545 cxt
->is_batch_enable
= true;
547 else if (!strncmp(buf
, "0", 1))
549 cxt
->is_batch_enable
= false;
553 MAG_ERR(" mag_store_obatch error !!\n");
556 MAG_LOG(" mag_store_obatch not supported\n");
558 mutex_unlock(&mag_context_obj
->mag_op_mutex
);
559 MAG_LOG(" mag_store_obatch done: %d\n", cxt
->is_batch_enable
);
565 static ssize_t
mag_show_obatch(struct device
* dev
,
566 struct device_attribute
*attr
, char *buf
)
569 MAG_LOG(" not support now\n");
573 static ssize_t
mag_store_oflush(struct device
* dev
, struct device_attribute
*attr
,
574 const char *buf
, size_t count
)
580 static ssize_t
mag_show_oflush(struct device
* dev
,
581 struct device_attribute
*attr
, char *buf
)
584 MAG_LOG(" not support now\n");
589 int mag_attach(int sensor
,struct mag_drv_obj
*obj
)
593 //mag_context_obj->drv_obj[sensor] = obj;
594 mag_context_obj
->drv_obj
[sensor
] = kzalloc(sizeof(struct mag_drv_obj
), GFP_KERNEL
);
595 if(mag_context_obj
->drv_obj
[sensor
] == NULL
)
598 MAG_ERR(" mag attatch alloc fail \n");
602 memcpy(mag_context_obj
->drv_obj
[sensor
], obj
, sizeof(*obj
));
603 if(NULL
== mag_context_obj
->drv_obj
[sensor
])
606 MAG_ERR(" mag attatch fail \n");
610 /*----------------------------------------------------------------------------*/
611 EXPORT_SYMBOL_GPL(mag_attach
);
614 static int msensor_remove(struct platform_device
*pdev
)
616 MAG_LOG("msensor_remove\n");
620 static int msensor_probe(struct platform_device
*pdev
)
622 MAG_LOG("msensor_probe\n");
626 static struct platform_driver msensor_driver
= {
627 .probe
= msensor_probe
,
628 .remove
= msensor_remove
,
635 static int mag_real_driver_init(void)
639 MAG_LOG(" mag_real_driver_init +\n");
640 for(i
= 0; i
< MAX_CHOOSE_G_NUM
; i
++)
642 MAG_LOG(" i=%d\n",i
);
643 if(0 != msensor_init_list
[i
])
645 MAG_LOG(" mag try to init driver %s\n", msensor_init_list
[i
]->name
);
646 err
= msensor_init_list
[i
]->init();
649 MAG_LOG(" mag real driver %s probe ok\n", msensor_init_list
[i
]->name
);
655 if(i
== MAX_CHOOSE_G_NUM
)
657 MAG_LOG(" mag_real_driver_init fail\n");
663 int mag_driver_add(struct mag_init_info
* obj
)
670 for(i
=0; i
< MAX_CHOOSE_G_NUM
; i
++ )
673 MAG_LOG("register mensor driver for the first time\n");
674 if(platform_driver_register(&msensor_driver
))
676 MAG_ERR("failed to register msensor driver already exist\n");
679 if(NULL
== msensor_init_list
[i
])
681 obj
->platform_diver_addr
= &msensor_driver
;
682 msensor_init_list
[i
] = obj
;
686 if(NULL
==msensor_init_list
[i
])
688 MAG_ERR("MAG driver add err \n");
694 EXPORT_SYMBOL_GPL(mag_driver_add
);
696 static int mag_misc_init(struct mag_context
*cxt
)
700 cxt
->mdev
.minor
= MISC_DYNAMIC_MINOR
;
701 cxt
->mdev
.name
= MAG_MISC_DEV_NAME
;
703 if((err
= misc_register(&cxt
->mdev
)))
705 MAG_ERR("unable to register mag misc device!!\n");
710 static void mag_input_destroy(struct mag_context
*cxt
)
712 struct input_dev
*dev
= cxt
->idev
;
714 input_unregister_device(dev
);
715 input_free_device(dev
);
718 static int mag_input_init(struct mag_context
*cxt
)
720 struct input_dev
*dev
;
723 dev
= input_allocate_device();
727 dev
->name
= MAG_INPUTDEV_NAME
;
729 input_set_capability(dev
, EV_ABS
, EVENT_TYPE_MAGEL_X
);
730 input_set_capability(dev
, EV_ABS
, EVENT_TYPE_MAGEL_Y
);
731 input_set_capability(dev
, EV_ABS
, EVENT_TYPE_MAGEL_Z
);
732 input_set_capability(dev
, EV_ABS
, EVENT_TYPE_MAGEL_STATUS
);
734 input_set_capability(dev
, EV_ABS
, EVENT_TYPE_O_X
);
735 input_set_capability(dev
, EV_ABS
, EVENT_TYPE_O_Y
);
736 input_set_capability(dev
, EV_ABS
, EVENT_TYPE_O_Z
);
737 input_set_capability(dev
, EV_ABS
, EVENT_TYPE_O_STATUS
);
739 input_set_abs_params(dev
, EVENT_TYPE_MAGEL_X
, MAG_VALUE_MIN
, MAG_VALUE_MAX
, 0, 0);
740 input_set_abs_params(dev
, EVENT_TYPE_MAGEL_Y
, MAG_VALUE_MIN
, MAG_VALUE_MAX
, 0, 0);
741 input_set_abs_params(dev
, EVENT_TYPE_MAGEL_Z
, MAG_VALUE_MIN
, MAG_VALUE_MAX
, 0, 0);
742 input_set_abs_params(dev
, EVENT_TYPE_MAGEL_STATUS
, MAG_STATUS_MIN
, MAG_STATUS_MAX
, 0, 0);
744 input_set_abs_params(dev
, EVENT_TYPE_O_X
, MAG_VALUE_MIN
, MAG_VALUE_MAX
, 0, 0);
745 input_set_abs_params(dev
, EVENT_TYPE_O_Y
, MAG_VALUE_MIN
, MAG_VALUE_MAX
, 0, 0);
746 input_set_abs_params(dev
, EVENT_TYPE_O_Z
, MAG_VALUE_MIN
, MAG_VALUE_MAX
, 0, 0);
747 input_set_abs_params(dev
, EVENT_TYPE_O_STATUS
, MAG_STATUS_MIN
, MAG_STATUS_MAX
, 0, 0);
749 input_set_drvdata(dev
, cxt
);
751 err
= input_register_device(dev
);
753 input_free_device(dev
);
761 DEVICE_ATTR(magdev
, S_IWUSR
| S_IRUGO
, mag_show_magdev
, NULL
);
762 DEVICE_ATTR(magactive
, S_IWUSR
| S_IRUGO
, mag_show_active
, mag_store_active
);
763 DEVICE_ATTR(magdelay
, S_IWUSR
| S_IRUGO
, mag_show_delay
, mag_store_delay
);
764 DEVICE_ATTR(magoactive
, S_IWUSR
| S_IRUGO
, mag_show_oactive
, mag_store_oactive
);
765 DEVICE_ATTR(magodelay
, S_IWUSR
| S_IRUGO
, mag_show_odelay
, mag_store_odelay
);
766 DEVICE_ATTR(magbatch
, S_IWUSR
| S_IRUGO
, mag_show_batch
, mag_store_batch
);
767 DEVICE_ATTR(magflush
, S_IWUSR
| S_IRUGO
, mag_show_flush
, mag_store_flush
);
768 DEVICE_ATTR(magobatch
, S_IWUSR
| S_IRUGO
, mag_show_obatch
, mag_store_obatch
);
769 DEVICE_ATTR(magoflush
, S_IWUSR
| S_IRUGO
, mag_show_oflush
, mag_store_oflush
);
770 DEVICE_ATTR(magdevnum
, S_IWUSR
| S_IRUGO
, mag_show_sensordevnum
, NULL
);
772 static struct attribute
*mag_attributes
[] = {
773 &dev_attr_magdev
.attr
,
774 &dev_attr_magactive
.attr
,
775 &dev_attr_magdelay
.attr
,
776 &dev_attr_magbatch
.attr
,
777 &dev_attr_magflush
.attr
,
778 &dev_attr_magoactive
.attr
,
779 &dev_attr_magodelay
.attr
,
780 &dev_attr_magobatch
.attr
,
781 &dev_attr_magoflush
.attr
,
782 &dev_attr_magdevnum
.attr
,
786 static struct attribute_group mag_attribute_group
= {
787 .attrs
= mag_attributes
791 int mag_register_data_path(struct mag_data_path
*data
)
793 struct mag_context
*cxt
= NULL
;
795 cxt
= mag_context_obj
;
796 cxt
->mag_dev_data
.div_m
= data
->div_m
;
797 cxt
->mag_dev_data
.div_o
= data
->div_o
;
798 MAG_LOG("mag register data path div_o: %d\n", cxt
->mag_dev_data
.div_o
);
799 MAG_LOG("mag register data path div_m: %d\n", cxt
->mag_dev_data
.div_m
);
804 int mag_register_control_path(struct mag_control_path
*ctl
)
806 struct mag_context
*cxt
= NULL
;
808 cxt
= mag_context_obj
;
810 cxt
->mag_ctl
.m_set_delay
= ctl
->m_set_delay
;
811 cxt
->mag_ctl
.m_enable
= ctl
->m_enable
;
812 cxt
->mag_ctl
.m_open_report_data
= ctl
->m_open_report_data
;
813 cxt
->mag_ctl
.o_set_delay
= ctl
->o_set_delay
;
814 cxt
->mag_ctl
.o_open_report_data
= ctl
->o_open_report_data
;
815 cxt
->mag_ctl
.o_enable
= ctl
->o_enable
;
816 cxt
->mag_ctl
.is_report_input_direct
= ctl
->is_report_input_direct
;
817 cxt
->mag_ctl
.is_support_batch
= ctl
->is_support_batch
;
819 if(NULL
==cxt
->mag_ctl
.m_set_delay
|| NULL
==cxt
->mag_ctl
.m_enable
820 || NULL
==cxt
->mag_ctl
.m_open_report_data
821 || NULL
==cxt
->mag_ctl
.o_set_delay
|| NULL
==cxt
->mag_ctl
.o_open_report_data
822 || NULL
==cxt
->mag_ctl
.o_enable
)
824 MAG_LOG("mag register control path fail \n");
828 //add misc dev for sensor hal control cmd
829 err
= mag_misc_init(mag_context_obj
);
832 MAG_ERR("unable to register acc misc device!!\n");
835 err
= sysfs_create_group(&mag_context_obj
->mdev
.this_device
->kobj
,
836 &mag_attribute_group
);
839 MAG_ERR("unable to create acc attribute file\n");
843 kobject_uevent(&mag_context_obj
->mdev
.this_device
->kobj
, KOBJ_ADD
);
848 int mag_data_report(MAG_TYPE type
,int x
, int y
, int z
, int status
)
850 //MAG_LOG("update!valus: %d, %d, %d, %d\n" , x, y, z, status);
851 struct acc_context
*cxt
= NULL
;
853 cxt
= mag_context_obj
;
856 input_report_abs(cxt
->idev
, EVENT_TYPE_MAGEL_STATUS
, status
);
857 input_report_abs(cxt
->idev
, EVENT_TYPE_MAGEL_X
, x
);
858 input_report_abs(cxt
->idev
, EVENT_TYPE_MAGEL_Y
, y
);
859 input_report_abs(cxt
->idev
, EVENT_TYPE_MAGEL_Z
, z
);
860 input_sync(cxt
->idev
);
862 if(ORIENTATION
==type
)
864 input_report_abs(cxt
->idev
, EVENT_TYPE_O_STATUS
, status
);
865 input_report_abs(cxt
->idev
, EVENT_TYPE_O_X
, x
);
866 input_report_abs(cxt
->idev
, EVENT_TYPE_O_Y
, y
);
867 input_report_abs(cxt
->idev
, EVENT_TYPE_O_Z
, z
);
868 input_sync(cxt
->idev
);
874 static int mag_probe(struct platform_device
*pdev
)
878 MAG_LOG("+++++++++++++mag_probe!!\n");
879 mag_context_obj
= mag_context_alloc_object();
880 if (!mag_context_obj
)
883 MAG_ERR("unable to allocate devobj!\n");
884 goto exit_alloc_data_failed
;
887 //init real mageleration driver
888 err
= mag_real_driver_init();
891 goto mag_real_driver_init_fail
;
892 MAG_ERR("mag_real_driver_init fail\n");
895 err
= mag_input_init(mag_context_obj
);
898 MAG_ERR("unable to register mag input device!\n");
899 goto exit_alloc_input_dev_failed
;
902 atomic_set(&(mag_context_obj
->early_suspend
), 0);
903 mag_context_obj
->early_drv
.level
= EARLY_SUSPEND_LEVEL_STOP_DRAWING
- 1,
904 mag_context_obj
->early_drv
.suspend
= mag_early_suspend
,
905 mag_context_obj
->early_drv
.resume
= mag_late_resume
,
906 register_early_suspend(&mag_context_obj
->early_drv
);
908 MAG_LOG("----magel_probe OK !!\n");
911 exit_hwmsen_create_attr_failed
:
912 exit_misc_register_failed
:
918 MAG_ERR("sysfs node creation error \n");
919 mag_input_destroy(mag_context_obj
);
922 mag_real_driver_init_fail
:
923 exit_alloc_input_dev_failed
:
924 kfree(mag_context_obj
);
926 exit_alloc_data_failed
:
928 MAG_LOG("----magel_probe fail !!!\n");
934 static int mag_remove(struct platform_device
*pdev
)
938 input_unregister_device(mag_context_obj
->idev
);
939 sysfs_remove_group(&mag_context_obj
->idev
->dev
.kobj
,
940 &mag_attribute_group
);
942 if((err
= misc_deregister(&mag_context_obj
->mdev
)))
944 MAG_ERR("misc_deregister fail: %d\n", err
);
946 kfree(mag_context_obj
);
951 static void mag_early_suspend(struct early_suspend
*h
)
953 atomic_set(&(mag_context_obj
->early_suspend
), 1);
954 MAG_LOG(" mag_context_obj ok------->hwm_obj->early_suspend=%d \n",atomic_read(&(mag_context_obj
->early_suspend
)));
957 /*----------------------------------------------------------------------------*/
958 static void mag_late_resume(struct early_suspend
*h
)
960 atomic_set(&(mag_context_obj
->early_suspend
), 0);
961 MAG_LOG(" mag_context_obj ok------->hwm_obj->early_suspend=%d \n",atomic_read(&(mag_context_obj
->early_suspend
)));
965 static int mag_suspend(struct platform_device
*dev
, pm_message_t state
)
969 /*----------------------------------------------------------------------------*/
970 static int mag_resume(struct platform_device
*dev
)
975 static struct platform_driver mag_driver
=
978 .remove
= mag_remove
,
979 .suspend
= mag_suspend
,
980 .resume
= mag_resume
,
983 .name
= MAG_PL_DEV_NAME
,
987 static int __init
mag_init(void)
991 if(platform_driver_register(&mag_driver
))
993 MAG_ERR("failed to register mag driver\n");
1000 static void __exit
mag_exit(void)
1002 platform_driver_unregister(&mag_driver
);
1003 platform_driver_unregister(&msensor_driver
);
1006 module_init(mag_init
);
1007 module_exit(mag_exit
);
1008 MODULE_LICENSE("GPL");
1009 MODULE_DESCRIPTION("MAGELEROMETER device driver");
1010 MODULE_AUTHOR("Mediatek");