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
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
|
/*++
* linux/sound/soc/codecs/wmt_fm34.c
* WonderMedia echo cancellation driver
*
* Copyright c 2010 WonderMedia Technologies, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* WonderMedia Technologies, Inc.
* 4F, 533, Chung-Cheng Road, Hsin-Tien, Taipei 231, R.O.C
--*/
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/pm.h>
#include <linux/i2c.h>
#include <linux/version.h>
#include <linux/slab.h>
#include <linux/workqueue.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/fs.h>
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/mm.h>
#include <linux/kdev_t.h>
#include <asm/page.h>
#include <linux/cdev.h>
#include <linux/device.h>
#include <linux/gpio.h>
#include <mach/wmt_iomux.h>
#define FM34_DEVID 0x501a
#define FM34_I2C_BUS_NR 4
#define FM34_CTRL_NAME "wmt_echo"
static int fm34_ctrl_major = 0;
static struct cdev fm34_ctrl_dev;
static struct class *fm34_ctrl_class;
// FM34 control interface commands
#define FM34_CMD_ECHO _IOWR('E', 0x01, int)
#define FM34_CMD_BYPASS _IOWR('E', 0x02, int)
#define FM34_CMD_INCALL_MAIN_MIC _IOWR('E', 0x04, int)
#define FM34_CMD_INCALL_HEADSET_MIC _IOWR('E', 0x08, int)
#define FM34_CMD_CAPTURE_MAIN_MIC _IOWR('E', 0x10, int)
#define FM34_CMD_CAPTURE_HEADSET_MIC _IOWR('E', 0x20, int)
enum FM34_MODE_TYPE {
FM34_MODE_ECHO,
FM34_MODE_BYPASS,
FM34_MODE_MAX,
};
enum FM34_MIC_SOURCE {
FM34_INCALL_MIC_MAIN,
FM34_INCALL_MIC_HEADSET,
FM34_CAPTURE_MIC_MAIN,
FM34_CAPTURE_MIC_HEADSET,
FM34_MIC_MAX,
};
extern int wmt_getsyspara(char *varname, unsigned char *varval, int *varlen);
struct fm34_ctrl_gpo {
int enable;
int gpio;
int active;
};
static struct fm34_ctrl_gpo fm34_reset;
static struct fm34_ctrl_gpo fm34_powerdown;
static struct fm34_ctrl_gpo fm34_bypass;
struct fm34 {
int (*read_dev)(struct fm34 *fm34,
const u8 wdata[], int wsize,
u8 rdata[], int rsize);
int (*write_dev)(struct fm34 *fm34, const u8 wdata[], int wsize);
void *control_data;
struct device *dev;
struct delayed_work delaywork;
};
static struct fm34 *fm34_context;
static enum FM34_MODE_TYPE fm_mode = FM34_MODE_MAX;
static enum FM34_MIC_SOURCE fm_mic = FM34_MIC_MAX;
static const u8 wmt_fm34_incall_main_mic[] = {
0xFC, 0xF3, 0x3B, 0x22, 0xC0, 0x00, 0x04,
0xFC, 0xF3, 0x3B, 0x22, 0xC1, 0x00, 0x04,
0xFC, 0xF3, 0x3B, 0x22, 0xC2, 0x00, 0x03,
0xFC, 0xF3, 0x3B, 0x22, 0xC3, 0x00, 0x03,
0xFC, 0xF3, 0x3B, 0x22, 0xC6, 0x00, 0x0C,
0xFC, 0xF3, 0x3B, 0x22, 0xC7, 0x00, 0x0C,
0xFC, 0xF3, 0x3B, 0x22, 0xC8, 0x00, 0x2C,
0xFC, 0xF3, 0x3B, 0x22, 0xD2, 0x12, 0x94,
0xFC, 0xF3, 0x3B, 0x22, 0xEE, 0x00, 0x00,
0xFC, 0xF3, 0x3B, 0x22, 0xF2, 0x00, 0x40,
0xFC, 0xF3, 0x3B, 0x22, 0xF6, 0x00, 0x03,
0xFC, 0xF3, 0x3B, 0x22, 0xF8, 0x80, 0x05,
0xFC, 0xF3, 0x3B, 0x22, 0xF9, 0x20, 0xFF,
0xFC, 0xF3, 0x3B, 0x22, 0xFA, 0x22, 0x8B,
0xFC, 0xF3, 0x3B, 0x23, 0x01, 0x00, 0x00,
0xFC, 0xF3, 0x3B, 0x23, 0x02, 0x01, 0x01,
0xFC, 0xF3, 0x3B, 0x23, 0x03, 0x09, 0x01,
0xFC, 0xF3, 0x3B, 0x23, 0x04, 0x03, 0x1E,
0xFC, 0xF3, 0x3B, 0x23, 0x05, 0x00, 0x01,
0xFC, 0xF3, 0x3B, 0x23, 0x07, 0xF0, 0xF0,
0xFC, 0xF3, 0x3B, 0x23, 0x08, 0x08, 0x00,
0xFC, 0xF3, 0x3B, 0x23, 0x0A, 0x1B, 0x00,
0xFC, 0xF3, 0x3B, 0x23, 0x0C, 0x04, 0x00,
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, 0x00, 0x18,
0xFC, 0xF3, 0x3B, 0x23, 0x10, 0x48, 0x90,
0xFC, 0xF3, 0x3B, 0x23, 0x2F, 0x01, 0x40,
0xFC, 0xF3, 0x3B, 0x23, 0x32, 0x00, 0x30,
0xFC, 0xF3, 0x3B, 0x23, 0x33, 0x00, 0x0C,
0xFC, 0xF3, 0x3B, 0x23, 0x37, 0x00, 0x02,
0xFC, 0xF3, 0x3B, 0x23, 0x39, 0x00, 0x01,
0xFC, 0xF3, 0x3B, 0x22, 0xFB, 0x00, 0x00
};
static const u8 wmt_fm34_incall_headset_mic[] = {
0xFC, 0xF3, 0x3B, 0x22, 0xC0, 0x00, 0x04,
0xFC, 0xF3, 0x3B, 0x22, 0xC1, 0x00, 0x04,
0xFC, 0xF3, 0x3B, 0x22, 0xC2, 0x00, 0x03,
0xFC, 0xF3, 0x3B, 0x22, 0xC3, 0x00, 0x03,
0xFC, 0xF3, 0x3B, 0x22, 0xC6, 0x00, 0x0C,
0xFC, 0xF3, 0x3B, 0x22, 0xC7, 0x00, 0x0C,
0xFC, 0xF3, 0x3B, 0x22, 0xC8, 0x00, 0x2C,
0xFC, 0xF3, 0x3B, 0x22, 0xD2, 0x12, 0x94,
0xFC, 0xF3, 0x3B, 0x22, 0xEE, 0x00, 0x00,
0xFC, 0xF3, 0x3B, 0x22, 0xF2, 0x00, 0x40,
0xFC, 0xF3, 0x3B, 0x22, 0xF6, 0x00, 0x03,
0xFC, 0xF3, 0x3B, 0x22, 0xF8, 0x80, 0x05,
0xFC, 0xF3, 0x3B, 0x22, 0xF9, 0x20, 0xFF,
0xFC, 0xF3, 0x3B, 0x22, 0xFA, 0x22, 0x8B,
0xFC, 0xF3, 0x3B, 0x23, 0x01, 0x00, 0x00,
0xFC, 0xF3, 0x3B, 0x23, 0x02, 0x01, 0x01,
0xFC, 0xF3, 0x3B, 0x23, 0x03, 0x09, 0x01,
0xFC, 0xF3, 0x3B, 0x23, 0x04, 0x03, 0x1E,
0xFC, 0xF3, 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0xF3, 0x3B, 0x23, 0xD5, 0x70, 0x00,
0xFC, 0xF3, 0x3B, 0x23, 0xED, 0x0A, 0x00,
0xFC, 0xF3, 0x3B, 0x23, 0xEE, 0x10, 0x00,
0xFC, 0xF3, 0x3B, 0x23, 0x28, 0x7F, 0xFF,
0xFC, 0xF3, 0x3B, 0x22, 0xF1, 0xD0, 0x00,
0xFC, 0xF3, 0x3B, 0x22, 0xFB, 0x00, 0x00
};
static int fm34_check_functionality(struct fm34 *fm34)
{
u8 rdata1, rdata2;
int devid = 0;
const u8 wdata1[] = {
0xFC, 0xF3, 0x27, 0x37, 0xFF
};
const u8 wdata2[] = {
0xFC, 0xF3, 0x60, 0x25
};
const u8 wdata3[] = {
0xFC, 0xF3, 0x60, 0x26
};
if (fm34->write_dev(fm34, wdata1, sizeof(wdata1)))
return 0;
if (fm34->read_dev(fm34, wdata2, sizeof(wdata2), &rdata1, 1) ||
fm34->read_dev(fm34, wdata3, sizeof(wdata3), &rdata2, 1))
return 0;
devid = (rdata2 << 8) | rdata1;
printk("-->fm34_check_functionality: %x\n", devid);
if (devid == FM34_DEVID)
return 1;
return 0;
}
static int fm34_i2c_write(struct fm34 *fm34, const u8 wdata[], int wsize)
{
int ret;
struct i2c_client *i2c = fm34->control_data;
struct i2c_msg xfer[1];
/*
* [MSG1]: fill the register address data
* fill the data Tx buffer
*/
xfer[0].addr = i2c->addr;
xfer[0].flags = 0 ;
xfer[0].flags &= ~(I2C_M_RD);
xfer[0].buf = (__u8 *)wdata;
xfer[0].len = wsize;
/* i2c_transfer returns number of messages transferred */
ret = i2c_transfer(i2c->adapter, xfer, ARRAY_SIZE(xfer));
if (ret != ARRAY_SIZE(xfer)) {
pr_err("fm34_i2c_write err[%d]\n", ret);
if (ret < 0)
return ret;
else
return -EIO;
} else
return 0;
}
static int fm34_i2c_read(struct fm34 *fm34,
const u8 wdata[], int wsize,
u8 rdata[], int rsize)
{
int ret;
struct i2c_client *i2c = fm34->control_data;
struct i2c_msg xfer[2];
/* [MSG1] fill the register address data */
xfer[0].addr = i2c->addr;
xfer[0].flags = 2; /* Read the register val */
xfer[0].buf = (__u8 *)wdata;
xfer[0].len = wsize;
/* [MSG2] fill the data rx buffer */
xfer[1].addr = i2c->addr;
xfer[1].flags = I2C_M_RD; /* Read the register val */
xfer[1].len = rsize; /* only n bytes */
xfer[1].buf = rdata;
/* i2c_transfer returns number of messages transferred */
ret = i2c_transfer(i2c->adapter, xfer, ARRAY_SIZE(xfer));
if (ret != ARRAY_SIZE(xfer)) {
pr_err("vt1603_i2c_read err[%d]\n", ret);
if (ret < 0)
return ret;
else
return -EIO;
} else {
return 0;
}
}
static void fm34_timing_init(void)
{
// pwdn high to power up fm34 module
if (fm34_powerdown.enable) {
gpio_set_value_cansleep(fm34_powerdown.gpio, !!fm34_powerdown.active);
msleep(100);
}
// reset fm34 module
if (fm34_reset.enable) {
gpio_set_value_cansleep(fm34_reset.gpio, !!fm34_reset.active);
msleep(10);
gpio_set_value_cansleep(fm34_reset.gpio, !fm34_reset.active);
msleep(10);
gpio_set_value_cansleep(fm34_reset.gpio, !!fm34_reset.active);
msleep(100);
}
// disable fm34 bypass
if (fm34_bypass.enable) {
gpio_set_value_cansleep(fm34_bypass.gpio, !!fm34_bypass.active);
}
}
static void fm34_do_work(struct work_struct *work)
{
struct fm34 *fm34 = container_of(work, struct fm34, delaywork.work);
fm34_timing_init();
if (fm34_check_functionality(fm34) == 0) {
pr_err("fm34_check_functionality: wrong device id\n");
}
fm34->write_dev(fm34, wmt_fm34_incall_main_mic, sizeof(wmt_fm34_incall_main_mic));
//fm_mode = FM34_MODE_ECHO;
fm_mic = FM34_INCALL_MIC_MAIN;
}
static int __devinit fm34_i2c_probe(struct i2c_client *i2c,
const struct i2c_device_id *id)
{
struct fm34 *fm34;
int ret;
if (i2c_check_functionality(i2c->adapter, I2C_FUNC_I2C) == 0) {
pr_err("i2c_check_functionality: can't talk I2C?\n");
return -EIO;
}
fm34 = kzalloc(sizeof(struct fm34), GFP_KERNEL);
if (fm34 == NULL)
return -ENOMEM;
fm34->dev = &i2c->dev;
fm34->control_data = i2c;
fm34->read_dev = fm34_i2c_read;
fm34->write_dev = fm34_i2c_write;
i2c_set_clientdata(i2c, fm34);
dev_set_drvdata(fm34->dev, fm34);
INIT_DELAYED_WORK(&fm34->delaywork, fm34_do_work);
if (fm34_powerdown.enable && gpio_is_valid(fm34_powerdown.gpio)) {
ret = gpio_request(fm34_powerdown.gpio, "FM34-powerdown");
if (ret < 0){
dev_warn(fm34->dev, "cann't register fm34_powerdown.gpio-%d\n", fm34_powerdown.gpio);
fm34_powerdown.enable = 0;
}
else
gpio_direction_output(fm34_powerdown.gpio, 0);
}
if (fm34_reset.enable && gpio_is_valid(fm34_reset.gpio)) {
ret = gpio_request(fm34_reset.gpio, "FM34-reset");
if (ret < 0) {
dev_warn(fm34->dev, "cann't register fm34_reset.gpio-%d\n", fm34_reset.gpio);
fm34_reset.enable = 0;
}
else
gpio_direction_output(fm34_reset.gpio, 0);
}
if (fm34_bypass.enable && gpio_is_valid(fm34_bypass.gpio)) {
ret = gpio_request(fm34_bypass.gpio, "FM34-bypass");
if (ret < 0) {
dev_warn(fm34->dev, "cann't register fm34_bypass.gpio-%d\n", fm34_bypass.gpio);
fm34_bypass.enable = 0;
}
else
gpio_direction_output(fm34_bypass.gpio, 0);
}
fm34_timing_init();
if (fm34_check_functionality(fm34) == 0) {
pr_err("fm34_check_functionality: wrong device id\n");
return -EIO;
}
fm34_context = fm34;
/* write the firmware to device */
fm34->write_dev(fm34, wmt_fm34_incall_main_mic, sizeof(wmt_fm34_incall_main_mic));
fm_mode = FM34_MODE_ECHO; // default is echo mode
fm_mic = FM34_INCALL_MIC_MAIN;
return 0;
}
static int __devexit fm34_i2c_remove(struct i2c_client *i2c)
{
struct fm34 *fm34 = i2c_get_clientdata(i2c);
if (fm34_powerdown.enable) {
gpio_free(fm34_powerdown.gpio);
}
if (fm34_reset.enable) {
gpio_free(fm34_reset.gpio);
}
if (fm34_bypass.enable) {
gpio_free(fm34_bypass.gpio);
}
kfree(fm34);
return 0;
}
static int fm34_suspend(struct i2c_client *i2c, pm_message_t mesg)
{
struct fm34 *fm34 = i2c_get_clientdata(i2c);
cancel_delayed_work_sync(&fm34->delaywork);
return 0;
}
static int fm34_resume(struct i2c_client *i2c)
{
struct fm34 *fm34 = i2c_get_clientdata(i2c);
schedule_delayed_work(&fm34->delaywork, msecs_to_jiffies(2000));
return 0;
}
static const struct i2c_device_id fm34_i2c_id[] = {
{ "wmt-fm34", 0 },
{ },
};
MODULE_DEVICE_TABLE(i2c, fm34_i2c_id);
static struct i2c_driver fm34_i2c_driver = {
.driver = {
.name = "wmt-fm34",
.owner = THIS_MODULE,
},
.probe = fm34_i2c_probe,
.remove = __devexit_p(fm34_i2c_remove),
.suspend = fm34_suspend,
.resume = fm34_resume,
.id_table = fm34_i2c_id,
};
static struct i2c_board_info fm34_i2c_board_info = {
I2C_BOARD_INFO("wmt-fm34", 0xc0>>1),
};
static int fm34_ctrl_open (struct inode *inode, struct file *filp)
{
printk("%s %d\n", __func__, __LINE__);
return 0;
}
static int fm34_ctrl_release(struct inode *inode, struct file *filp)
{
printk("%s %d\n", __func__, __LINE__);
return 0;
}
static ssize_t fm34_ctrl_read(struct file *filp, char __user *buf, size_t size, loff_t *offp)
{
printk("%s %d\n", __func__, __LINE__);
return size;
}
static long fm34_ctrl_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
const u8 echo[] = { 0xFC, 0xF3, 0x3B, 0x23, 0x00, 0x00, 0x00 };
const u8 bypass[] = { 0xFC, 0xF3, 0x3B, 0x23, 0x00, 0x00, 0x01 };
//const u8 main_mic[] = { 0xFC, 0xF3, 0x3B, 0x23, 0x0a, 0x1a, 0x00 };
//const u8 headset_mic[] = { 0xFC, 0xF3, 0x3B, 0x23, 0x0a, 0x1b, 0x00 };
switch (cmd) {
case FM34_CMD_ECHO:
if (fm_mode != FM34_MODE_ECHO) {
printk("FM34 cmd: echo\n");
if (fm34_context->write_dev(fm34_context, echo, sizeof(echo)))
return -EIO;
fm_mode = FM34_MODE_ECHO;
}
break;
case FM34_CMD_BYPASS:
if (fm_mode != FM34_MODE_BYPASS) {
printk("FM34 cmd: bypass\n");
if (fm34_context->write_dev(fm34_context, bypass, sizeof(bypass)))
return -EIO;
fm_mode = FM34_MODE_BYPASS;
}
break;
case FM34_CMD_INCALL_MAIN_MIC:
if (fm_mic != FM34_INCALL_MIC_MAIN) {
printk("FM34 cmd: incall main-mic\n");
if (fm34_reset.enable) {
gpio_set_value_cansleep(fm34_reset.gpio, !fm34_reset.active);
msleep(20);
gpio_set_value_cansleep(fm34_reset.gpio, !!fm34_reset.active);
msleep(20);
}
if (fm34_context->write_dev(fm34_context, wmt_fm34_incall_main_mic, sizeof(wmt_fm34_incall_main_mic)))
return -EIO;
fm_mic = FM34_INCALL_MIC_MAIN;
}
break;
case FM34_CMD_INCALL_HEADSET_MIC:
if (fm_mic != FM34_INCALL_MIC_HEADSET) {
printk("FM34 cmd: incall headset-mic\n");
if (fm34_reset.enable) {
gpio_set_value_cansleep(fm34_reset.gpio, !fm34_reset.active);
msleep(20);
gpio_set_value_cansleep(fm34_reset.gpio, !!fm34_reset.active);
msleep(20);
}
if (fm34_context->write_dev(fm34_context, wmt_fm34_incall_headset_mic, sizeof(wmt_fm34_incall_headset_mic)))
return -EIO;
fm_mic = FM34_INCALL_MIC_HEADSET;
}
break;
case FM34_CMD_CAPTURE_MAIN_MIC:
if (fm_mic != FM34_CMD_CAPTURE_MAIN_MIC) {
printk("FM34 cmd: capture main-mic\n");
if (fm34_reset.enable) {
gpio_set_value_cansleep(fm34_reset.gpio, !fm34_reset.active);
msleep(20);
gpio_set_value_cansleep(fm34_reset.gpio, !!fm34_reset.active);
msleep(20);
}
if (fm34_context->write_dev(fm34_context, wmt_fm34_capture_main_mic, sizeof(wmt_fm34_capture_main_mic)))
return -EIO;
fm_mic = FM34_CMD_CAPTURE_MAIN_MIC;
}
break;
case FM34_CMD_CAPTURE_HEADSET_MIC:
if (fm_mic != FM34_CMD_CAPTURE_HEADSET_MIC) {
printk("FM34 cmd: capture headset-mic\n");
if (fm34_reset.enable) {
gpio_set_value_cansleep(fm34_reset.gpio, !fm34_reset.active);
msleep(20);
gpio_set_value_cansleep(fm34_reset.gpio, !!fm34_reset.active);
msleep(20);
}
if (fm34_context->write_dev(fm34_context, wmt_fm34_capture_headset_mic, sizeof(wmt_fm34_capture_headset_mic)))
return -EIO;
fm_mic = FM34_CMD_CAPTURE_HEADSET_MIC;
}
break;
default:
printk(KERN_ERR "FM34: Not support cmd[%d]\n", cmd);
break;
}
return 0;
}
static struct file_operations fm34_ctrl_ops = {
.owner = THIS_MODULE,
.open = fm34_ctrl_open,
.release = fm34_ctrl_release,
.read = fm34_ctrl_read,
.unlocked_ioctl = fm34_ctrl_ioctl,
};
static int fm34_ctrl_setup_cdev(struct cdev *dev, int minor, struct file_operations *fops)
{
int ret, devno = MKDEV(fm34_ctrl_major, minor);
cdev_init(dev, fops);
dev->owner = THIS_MODULE;
dev->ops = fops;
ret = cdev_add(dev, devno, 1);
if (ret)
printk(KERN_ERR "Error %d adding wmt_echo %d", ret, minor);
return ret;
}
static int __init fm34_init(void)
{
int ret = -1;
int len = 64;
char buf[64];
dev_t dev;
struct i2c_adapter *adapter;
struct i2c_client *client;
ret = wmt_getsyspara("wmt.echo.cancellation", buf, &len);
if (ret == 0) {
sscanf(buf, "fm34:[%d:%d:%d]:[%d:%d:%d]:[%d:%d:%d]",
&fm34_powerdown.enable, &fm34_powerdown.gpio, &fm34_powerdown.active,
&fm34_reset.enable, &fm34_reset.gpio, &fm34_reset.active,
&fm34_bypass.enable, &fm34_bypass.gpio, &fm34_bypass.active);
}
else {
fm34_reset.enable = 0;
fm34_powerdown.enable = 0;
fm34_bypass.enable = 0;
}
ret = alloc_chrdev_region(&dev, 0, 1, FM34_CTRL_NAME);
if (ret == 0)
fm34_ctrl_major = MAJOR(dev);
else
printk(KERN_ERR "fm34: alloc_chrdev_region failed!\n");
ret = fm34_ctrl_setup_cdev(&fm34_ctrl_dev, 0, &fm34_ctrl_ops);
if (ret == 0) {
fm34_ctrl_class = class_create(THIS_MODULE, FM34_CTRL_NAME);
if (IS_ERR(fm34_ctrl_class)) {
printk("fm34: class_create failed!\n");
}
else
device_create(fm34_ctrl_class, NULL, MKDEV(fm34_ctrl_major, 0), NULL, FM34_CTRL_NAME);
}
adapter = i2c_get_adapter(FM34_I2C_BUS_NR);
client = i2c_new_device(adapter, &fm34_i2c_board_info);
i2c_put_adapter(adapter);
ret = i2c_add_driver(&fm34_i2c_driver);
if (ret != 0)
pr_err("Failed to register FM34 I2C driver: %d\n", ret);
return ret;
}
module_init(fm34_init);
static void __exit fm34_exit(void)
{
cdev_del(&fm34_ctrl_dev);
device_destroy(fm34_ctrl_class, MKDEV(fm34_ctrl_major, 0));
class_destroy(fm34_ctrl_class);
unregister_chrdev_region(MKDEV(fm34_ctrl_major, 0), 1);
i2c_del_driver(&fm34_i2c_driver);
}
module_exit(fm34_exit);
MODULE_DESCRIPTION("WMT [ALSA SoC/echocancellation] driver");
MODULE_AUTHOR("WonderMedia Technologies, Inc.");
MODULE_LICENSE("GPL");
|