aboutsummaryrefslogtreecommitdiff
path: root/drivers/base/meizu-sensors.c
blob: 9f5ccb1179c62bfdfbb8b4d419e003b6a27b58c7 (plain) (blame)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791

#include <linux/module.h>
#include <linux/types.h>
#include <linux/init.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/err.h>
#include <linux/i2c.h>
#include <linux/slab.h>
#include <linux/sysfs.h>
#include "base.h"

#include <linux/meizu-sys.h>
#include <linux/meizu-sensors.h>

//#define MZ_SENSORS_DEBUG 1
#ifdef MZ_SENSORS_DEBUG
#define LOG_TAG_MZ_SENSORS "[mz_sensors]"
#define pr_info(format, arg...)         printk(KERN_EMERG LOG_TAG_MZ_SENSORS format , ## arg)
#define dev_err(dev, format, arg...)    printk(KERN_EMERG LOG_TAG_MZ_SENSORS format , ## arg)
#define dev_info(dev, format, arg...)   printk(KERN_EMERG LOG_TAG_MZ_SENSORS format , ## arg)
#define dev_dbg(dev, format, arg...)    printk(KERN_EMERG LOG_TAG_MZ_SENSORS format , ## arg)
#define dev_warn(dev, format, arg...)   printk(KERN_EMERG LOG_TAG_MZ_SENSORS format , ## arg)
#define dev_notice(dev, format, arg...) printk(KERN_EMERG LOG_TAG_MZ_SENSORS format , ## arg)
#endif

/* -- sensors ops -- */
struct meizu_sensors_table {
	struct device *dev;
	struct meizu_sensors_ops *ops;
	char *name;
	struct device_attribute *attr;
	int attr_cnt;
} meizu_sensors_table[MEIZU_SENSOR_ID_MAX];

static int meizu_sensors_get_ops(struct device *dev,
	struct meizu_sensors_ops **ops)
{
	int i;

	for (i=0; i<MEIZU_SENSOR_ID_MAX; i++) {
		if (meizu_sensors_table[i].dev == dev) {
			*ops = meizu_sensors_table[i].ops;
			dev_dbg(dev, "get sensor(%d)'s ops: %p\n", i, *ops);
			return 0;
		}
	}

	dev_err(dev, "failed to get sensor ops\n");
	return -1;
}

static void meizu_sensors_set_ops(meizu_sensor_id_t id,
				  struct device *dev,
				  struct meizu_sensors_ops *ops)
{
	if (meizu_sensors_table[id].dev == NULL) {
		meizu_sensors_table[id].dev = dev;
		meizu_sensors_table[id].ops = ops;
		dev_dbg(dev, "set sensor(%d) ops: %p\n", id, ops);
		return;
	}

	dev_err(dev, "failed to set sensor(%d) ops\n", id);
	BUG();
}



/* -- sensors sysfs interfaces -- */
/* self test interface */
static ssize_t meizu_sensors_sysfs_get_self_test(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	int ret;
	struct meizu_sensors_ops *ops;

	ret = meizu_sensors_get_ops(dev, &ops);
	if (ret < 0)
		return ret;

	if (ops->self_test) {
		ret = ops->self_test(dev);
	} else {
		dev_err(dev, "sensor has no self test interface\n");
		ret = -ENOSYS;
	}

	dev_info(dev, "self test result: %d\n", ret);

	return sprintf(buf, "%d\n", ret);
}



/* enable interface */
static ssize_t meizu_sensors_sysfs_get_enable(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	int ret;
	int state;
	struct meizu_sensors_ops *ops;

	ret = meizu_sensors_get_ops(dev, &ops);
	if (ret < 0)
		return ret;

	if (ops->get_enable) {
		ret = ops->get_enable(dev, &state);
	} else {
		dev_err(dev, "sensor has no enable interface\n");
		ret = -ENOSYS;
	}

	return sprintf(buf, "%d\n", ret < 0 ? ret : !!state);
}

static ssize_t meizu_sensors_sysfs_set_enable(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count)
{
	int ret;
	uint16_t state;
	struct meizu_sensors_ops *ops;

	ret = kstrtou16(buf, 10, &state);
	if (ret < 0) {
		dev_err(dev, "kstrtoint error\n");
		return ret;
	}

	ret = meizu_sensors_get_ops(dev, &ops);
	if (ret < 0)
		return ret;

	if (ops->set_enable) {
		ret = ops->set_enable(dev, state);
	} else {
		dev_err(dev, "sensor has no enable interface\n");
		ret = -ENOSYS;
	}

	return ret < 0 ? ret : count;
}



/* calibbias interfaces */
static int meizu_sensors_get_calibbias(struct device *dev, int32_t *bias)
{
	int ret;
	struct meizu_sensors_ops *ops;

	ret = meizu_sensors_get_ops(dev, &ops);
	if (ret < 0)
		return ret;

	if (ops->get_calibbias) {
		ret = ops->get_calibbias(dev, bias);
	} else {
		dev_err(dev, "sensor has no get calibbias interface\n");
		ret = -ENOSYS;
	}

	return ret;
}

static ssize_t meizu_sensors_sysfs_get_x_calibbias(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	int ret;
	int32_t bias[3];

	ret = meizu_sensors_get_calibbias(dev, bias);
	if (ret < 0)
		return ret;

	return sprintf(buf, "%d\n", bias[0]);
}

static ssize_t meizu_sensors_sysfs_get_y_calibbias(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	int ret;
	int32_t bias[3];

	ret = meizu_sensors_get_calibbias(dev, bias);
	if (ret < 0)
		return ret;

	return sprintf(buf, "%d\n", bias[1]);
}

static ssize_t meizu_sensors_sysfs_get_z_calibbias(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	int ret;
	int32_t bias[3];

	ret = meizu_sensors_get_calibbias(dev, bias);
	if (ret < 0)
		return ret;

	return sprintf(buf, "%d\n", bias[2]);
}



/* offset interfaces */
static int meizu_sensors_set_offset(struct device *dev,
	const char *buf, int offset, int axis)
{
	int ret;
	struct meizu_sensors_ops *ops;

	if (buf != NULL) {
		ret = kstrtoint(buf, 10, &offset);
		if (ret < 0) {
			dev_err(dev, "kstrtoint error\n");
			return ret;
		}
	}

	ret = meizu_sensors_get_ops(dev, &ops);
	if (ret < 0)
		return ret;

	if (ops->set_offset) {
		ret = ops->set_offset(dev, offset, axis);
	} else {
		dev_err(dev, "sensor has no set offset interface\n");
		ret = -ENOSYS;
	}

	return ret;
}

static ssize_t meizu_sensors_sysfs_set_x_offset(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count)
{
	int ret;

	ret = meizu_sensors_set_offset(dev, buf, 0, 0);

	return ret < 0 ? ret : count;
}

static ssize_t meizu_sensors_sysfs_set_y_offset(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count)
{
	int ret;

	ret = meizu_sensors_set_offset(dev, buf, 0, 1);

	return ret < 0 ? ret : count;
}

static ssize_t meizu_sensors_sysfs_set_z_offset(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count)
{
	int ret;

	ret = meizu_sensors_set_offset(dev, buf, 0, 2);

	return ret < 0 ? ret : count;
}

static int meizu_sensors_get_offset(struct device *dev,
	int *offset)
{
	int ret;
	struct meizu_sensors_ops *ops;

	ret = meizu_sensors_get_ops(dev, &ops);
	if (ret < 0)
		return ret;

	if (ops->get_offset) {
		ret = ops->get_offset(dev, offset);
	} else {
		dev_err(dev, "sensor has no get offset interface\n");
		ret = -ENOSYS;
	}

	return ret;
}

static ssize_t meizu_sensors_sysfs_get_x_offset(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	int ret;
	int offset[3];

	ret = meizu_sensors_get_offset(dev, offset);
	if (ret < 0)
		return ret;

	return sprintf(buf, "%d\n", offset[0]);
}

static ssize_t meizu_sensors_sysfs_get_y_offset(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	int ret;
	int offset[3];

	ret = meizu_sensors_get_offset(dev, offset);
	if (ret < 0)
		return ret;

	return sprintf(buf, "%d\n", offset[1]);
}

static ssize_t meizu_sensors_sysfs_get_z_offset(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	int ret;
	int offset[3];

	ret = meizu_sensors_get_offset(dev, offset);
	if (ret < 0)
		return ret;

	return sprintf(buf, "%d\n", offset[2]);
}


static int meizu_sensors_create_sysfs_interfaces(struct device *dev,
	struct device_attribute *attributes, int cnt)
{
	int i;
	for (i = 0; i < cnt; i++) {
		if (device_create_file(dev, attributes + i)) {
			/* ignore the fail, the file may created by driver */
			dev_info(dev, "%s has created by sensor driver\n",
				attributes[i].attr.name);
		}
	}
	return 0;

}

static void meizu_sensors_destory_sysfs_interfaces(struct device *dev,
	struct device_attribute *attributes, int cnt)
{
	int i;
	for (i = 0; i < cnt; i++)
		device_remove_file(dev, attributes + i);
}



/* calibrate interfaces */
static ssize_t meizu_sensors_sysfs_get_calibrate(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	int ret;
	struct meizu_sensors_ops *ops;
	int32_t bias[3] = {0,0,0};

	ret = meizu_sensors_get_ops(dev, &ops);
	if (ret < 0)
		return ret;

	if (ops->calibrate) {
		ret = ops->calibrate(dev);
	} else {
		dev_err(dev, "sensor has no calibrate interface\n");
		ret = -ENOSYS;
	}

	if (ret >= 0) {
		/* apply the bias immediately */
		meizu_sensors_get_calibbias(dev, bias);
		meizu_sensors_set_offset(dev, NULL, bias[0], 0);
		meizu_sensors_set_offset(dev, NULL, bias[1], 1);
		meizu_sensors_set_offset(dev, NULL, bias[2], 2);
	}

	return sprintf(buf, "%d\n", ret);
}



static ssize_t meizu_sensors_sysfs_set_calibrate(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count)
{
	int ret;
	uint16_t state;
	struct meizu_sensors_ops *ops;
	int32_t bias[3] = {0,0,0};

	ret = kstrtou16(buf, 10, &state);
	if (ret < 0) {
		dev_err(dev, "kstrtoint error\n");
		return ret;
	}

	if (state != 1) {
		dev_err(dev, "only write 1 is valid\n");
		return -EINVAL;
	}

	ret = meizu_sensors_get_ops(dev, &ops);
	if (ret < 0)
		return ret;

	if (ops->calibrate) {
		ret = ops->calibrate(dev);
	} else {
		dev_err(dev, "sensor has no calibrate interface\n");
		ret = -ENOSYS;
	}

	if (ret >= 0) {
		/* apply the bias immediately */
		meizu_sensors_get_calibbias(dev, bias);
		meizu_sensors_set_offset(dev, NULL, bias[0], 0);
		meizu_sensors_set_offset(dev, NULL, bias[1], 1);
		meizu_sensors_set_offset(dev, NULL, bias[2], 2);
	}
	return ret < 0 ? ret : count;
}



/* raw data interfaces */
static int meizu_sensors_get_raw_data(struct device *dev,
	int *raw)
{
	int ret;
	struct meizu_sensors_ops *ops;

	ret = meizu_sensors_get_ops(dev, &ops);
	if (ret < 0)
		return ret;

	if (ops->get_raw_data) {
		ret = ops->get_raw_data(dev, raw);
	} else {
		dev_err(dev, "sensor has no get offset interface\n");
		ret = -ENOSYS;
	}

	return ret;
}

static ssize_t meizu_sensors_sysfs_get_x_raw_data(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	int ret;
	int raw[3];

	ret = meizu_sensors_get_raw_data(dev, raw);
	if (ret < 0)
		return ret;

	return sprintf(buf, "%d\n", raw[0]);
}

static ssize_t meizu_sensors_sysfs_get_y_raw_data(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	int ret;
	int raw[3];

	ret = meizu_sensors_get_raw_data(dev, raw);
	if (ret < 0)
		return ret;

	return sprintf(buf, "%d\n", raw[1]);
}

static ssize_t meizu_sensors_sysfs_get_z_raw_data(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	int ret;
	int raw[3];

	ret = meizu_sensors_get_raw_data(dev, raw);
	if (ret < 0)
		return ret;

	return sprintf(buf, "%d\n", raw[2]);
}



/* name and id interfaces */
static ssize_t meizu_sensors_sysfs_get_name(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	int ret;
	struct meizu_sensors_ops *ops;
	char *name;

	ret = meizu_sensors_get_ops(dev, &ops);
	if (ret < 0)
		return ret;

	if (ops->get_name) {
		ret = ops->get_name(dev, &name);
	} else {
		dev_err(dev, "sensor has no name interface\n");
		ret = -ENOSYS;
	}

	return sprintf(buf, "%s\n", ret < 0 ? "NA" : name);
}

static ssize_t meizu_sensors_sysfs_get_id(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	int ret;
	struct meizu_sensors_ops *ops;
	char *id;

	ret = meizu_sensors_get_ops(dev, &ops);
	if (ret < 0)
		return ret;

	if (ops->get_id) {
		ret = ops->get_id(dev, &id);
	} else {
		dev_err(dev, "sensor has no id interface\n");
		ret = -ENOSYS;
	}

	return sprintf(buf, "%s\n", ret < 0 ? "NA" : id);
}


static ssize_t meizu_sensors_sysfs_get_irq_gpio(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	int ret;
	struct meizu_sensors_ops *ops;
	int state = 0;

	ret = meizu_sensors_get_ops(dev, &ops);
	if (ret < 0)
		return ret;

	if (ops->get_irq_gpio) {
		ret = ops->get_irq_gpio(dev, &state);
	} else {
		dev_err(dev, "sensor has no irq_gpio interface\n");
		ret = -ENOSYS;
	}

	if (ret < 0)
		return ret;

	return sprintf(buf, "%d\n", state);
}

/* -- sensor attributes -- */
static struct device_attribute compass_attributes[] = {
	__ATTR(compass_name, S_IRUGO,
		meizu_sensors_sysfs_get_name,
		NULL),
	__ATTR(compass_id, S_IRUGO,
		meizu_sensors_sysfs_get_id,
		NULL),

	__ATTR(compass_self_test, S_IRUGO,
		meizu_sensors_sysfs_get_self_test,
		NULL),
	__ATTR(compass_enable, S_IRUGO|S_IWUGO,
		meizu_sensors_sysfs_get_enable,
		meizu_sensors_sysfs_set_enable),
};

static struct device_attribute acc_attributes[] = {
	__ATTR(acc_name, S_IRUGO,
		meizu_sensors_sysfs_get_name,
		NULL),
	__ATTR(acc_id, S_IRUGO,
		meizu_sensors_sysfs_get_id,
		NULL),

	__ATTR(acc_self_test, S_IRUGO,
		meizu_sensors_sysfs_get_self_test,
		NULL),

	__ATTR(acc_enable, S_IRUGO|S_IWUGO,
		meizu_sensors_sysfs_get_enable,
		meizu_sensors_sysfs_set_enable),

	__ATTR(acc_calibration, S_IRUGO|S_IWUGO,
		meizu_sensors_sysfs_get_calibrate,
		meizu_sensors_sysfs_set_calibrate),

	__ATTR(acc_x_calibbias, S_IRUGO,
		meizu_sensors_sysfs_get_x_calibbias,
		NULL),
	__ATTR(acc_y_calibbias, S_IRUGO,
		meizu_sensors_sysfs_get_y_calibbias,
		NULL),
	__ATTR(acc_z_calibbias, S_IRUGO,
		meizu_sensors_sysfs_get_z_calibbias,
		NULL),

	__ATTR(acc_x_offset, S_IRUGO|S_IWUGO,
		meizu_sensors_sysfs_get_x_offset,
		meizu_sensors_sysfs_set_x_offset),
	__ATTR(acc_y_offset, S_IRUGO|S_IWUGO,
		meizu_sensors_sysfs_get_y_offset,
		meizu_sensors_sysfs_set_y_offset),
	__ATTR(acc_z_offset, S_IRUGO|S_IWUGO,
		meizu_sensors_sysfs_get_z_offset,
		meizu_sensors_sysfs_set_z_offset),
};

static struct device_attribute gyr_attributes[] = {
	__ATTR(gyr_name, S_IRUGO,
		meizu_sensors_sysfs_get_name,
		NULL),
	__ATTR(gyr_id, S_IRUGO,
		meizu_sensors_sysfs_get_id,
		NULL),

	__ATTR(gyr_self_test, S_IRUGO,
		meizu_sensors_sysfs_get_self_test,
		NULL),

	__ATTR(gyr_enable, S_IRUGO|S_IWUGO,
		meizu_sensors_sysfs_get_enable,
		meizu_sensors_sysfs_set_enable),
};

static struct device_attribute als_attributes[] = {
	__ATTR(als_name, S_IRUGO,
		meizu_sensors_sysfs_get_name,
		NULL),
	__ATTR(als_id, S_IRUGO,
		meizu_sensors_sysfs_get_id,
		NULL),

	__ATTR(als_enable, S_IRUGO|S_IWUGO,
		meizu_sensors_sysfs_get_enable,
		meizu_sensors_sysfs_set_enable),

	__ATTR(als_data, S_IRUGO,
		meizu_sensors_sysfs_get_x_raw_data,
		NULL),
};

static struct device_attribute ps_attributes[] = {
	__ATTR(ps_name, S_IRUGO,
		meizu_sensors_sysfs_get_name,
		NULL),
	__ATTR(ps_id, S_IRUGO,
		meizu_sensors_sysfs_get_id,
		NULL),

	__ATTR(ps_enable, S_IRUGO|S_IWUGO,
		meizu_sensors_sysfs_get_enable,
		meizu_sensors_sysfs_set_enable),

	__ATTR(ps_calibration, S_IRUGO|S_IWUGO,
		meizu_sensors_sysfs_get_calibrate,
		meizu_sensors_sysfs_set_calibrate),

	__ATTR(ps_data, S_IRUGO,
		meizu_sensors_sysfs_get_x_raw_data,
		NULL),

	__ATTR(ps_calibbias, S_IRUGO,
		meizu_sensors_sysfs_get_x_calibbias,
		NULL),

	__ATTR(ps_offset, S_IRUGO|S_IWUGO,
		meizu_sensors_sysfs_get_x_offset,
		meizu_sensors_sysfs_set_x_offset),

	__ATTR(ps_irq_gpio, S_IRUGO,
		meizu_sensors_sysfs_get_irq_gpio,
		NULL),
};

int meizu_sensor_register(meizu_sensor_id_t id,
			  struct device *dev,
			  struct meizu_sensors_ops *ops)
{
	int ret;

	if (!dev || id >= MEIZU_SENSOR_ID_MAX || id<0)
		return -EINVAL;

	dev_info(dev, "meizu_sensor_register id: %d, name: %s\n",
		id, meizu_sensors_table[id].name);

	ret = meizu_sysfslink_register_name(dev, meizu_sensors_table[id].name);
	if (ret < 0) {
		dev_err(dev, "failed to register sysfs link for sensor.\n");
		return ret;
	}

	if (ops == NULL) {
		/* if ops is NULL, it means we dont need to create sysfs */
		dev_info(dev, "no sensor callback.\n");
		return 0;
	}

	ret = meizu_sensors_create_sysfs_interfaces(dev,
		meizu_sensors_table[id].attr, meizu_sensors_table[id].attr_cnt);
	if (ret < 0) {
		dev_err(dev, "failed to create_sysfs for sensor (%d).\n", id);
		goto unregister_sysfslink;
	}

	meizu_sensors_set_ops(id, dev, ops);

	return 0;

unregister_sysfslink:
#if 0 /* bug in meizu_sysfslink_unregister */
	meizu_sysfslink_unregister(dev);
#endif
	return ret;

}


void meizu_sensor_unregister(meizu_sensor_id_t id,
			  struct device *dev,
			  struct meizu_sensors_ops *ops)
{
	int ret;
	struct meizu_sensors_ops *tmp_ops;

	if (!dev || !ops || id >= MEIZU_SENSOR_ID_MAX || id<0)
		return;

	dev_info(dev, "meizu_sensor_unregister id: %d, name: %s\n",
		id, meizu_sensors_table[id].name);

	ret = meizu_sensors_get_ops(dev, &tmp_ops);
	if (ret < 0)
		return;

	if (tmp_ops != ops) {
		return;
	}

#if 0 /* bug in meizu_sysfslink_unregister */
	meizu_sysfslink_unregister(dev);
#endif

	meizu_sensors_destory_sysfs_interfaces(dev,
		meizu_sensors_table[id].attr, meizu_sensors_table[id].attr_cnt);
}

static int __init meizu_sensors_init(void)
{
	meizu_sensors_table[MEIZU_SENSOR_ID_ACC].name = "acc";
	meizu_sensors_table[MEIZU_SENSOR_ID_ACC].attr = acc_attributes;
	meizu_sensors_table[MEIZU_SENSOR_ID_ACC].attr_cnt = ARRAY_SIZE(acc_attributes);

	meizu_sensors_table[MEIZU_SENSOR_ID_GYR].name = "gyr";
	meizu_sensors_table[MEIZU_SENSOR_ID_GYR].attr = gyr_attributes;
	meizu_sensors_table[MEIZU_SENSOR_ID_GYR].attr_cnt = ARRAY_SIZE(gyr_attributes);

	meizu_sensors_table[MEIZU_SENSOR_ID_COMPASS].name = "compass";
	meizu_sensors_table[MEIZU_SENSOR_ID_COMPASS].attr = compass_attributes;
	meizu_sensors_table[MEIZU_SENSOR_ID_COMPASS].attr_cnt = ARRAY_SIZE(compass_attributes);

	meizu_sensors_table[MEIZU_SENSOR_ID_ALS].name = "als";
	meizu_sensors_table[MEIZU_SENSOR_ID_ALS].attr = als_attributes;
	meizu_sensors_table[MEIZU_SENSOR_ID_ALS].attr_cnt = ARRAY_SIZE(als_attributes);

	meizu_sensors_table[MEIZU_SENSOR_ID_PS].name = "ps";
	meizu_sensors_table[MEIZU_SENSOR_ID_PS].attr = ps_attributes;
	meizu_sensors_table[MEIZU_SENSOR_ID_PS].attr_cnt = ARRAY_SIZE(ps_attributes);

	pr_info("meizu_sensors_init done\n");

	return 0;
}

static void __exit meizu_sensors_exit(void)
{
	return;
}

subsys_initcall(meizu_sensors_init);
module_exit(meizu_sensors_exit);

MODULE_DESCRIPTION("Meizu technology sensors sysfs interfaces");
MODULE_AUTHOR("Zhang Jiajing <zhangjiajing@meizu.com>");
MODULE_LICENSE("GPL");