1 #include <linux/kernel.h>
2 #include <linux/init.h>
4 #include <linux/module.h>
5 #include <linux/interrupt.h>
7 #include <linux/regmap.h>
8 #include <linux/tfa9887.h>
9 #include <sound/initval.h>
10 #include <linux/sysfs.h>
11 #include <linux/miscdevice.h>
12 #include <linux/delay.h>
16 void tegra_asoc_enable_clocks(void);
17 void tegra_asoc_disable_clocks(void);
19 static ssize_t tfa9887_cal_show(struct kobject *kobj,
20 struct kobj_attribute *attr, char *buf);
22 static ssize_t tfa9887_cal_store(struct kobject *kobj,
23 struct kobj_attribute *attr, const char *buf, size_t count);
25 static ssize_t tfa9887_config_show(struct kobject *kobj,
26 struct kobj_attribute *attr, char *buf);
28 static ssize_t tfa9887_config_store(struct kobject *kobj,
29 struct kobj_attribute *attr, const char *buf, size_t count);
31 static ssize_t tfa9887_vol_show(struct kobject *kobj,
32 struct kobj_attribute *attr, char *buf);
34 static ssize_t tfa9887_vol_store(struct kobject *kobj,
35 struct kobj_attribute *attr, const char *buf, size_t count);
38 static struct kobj_attribute tfa9887_config =
39 __ATTR(config, 0640, tfa9887_config_show, tfa9887_config_store);
41 static struct kobj_attribute tfa9887_cal =
42 __ATTR(cal, 0640, tfa9887_cal_show, tfa9887_cal_store);
44 static struct kobj_attribute tfa9887_vol =
45 __ATTR(vol, 0640, tfa9887_vol_show, tfa9887_vol_store);
47 static struct kobject *tfa9887_kobj;
49 static struct tfa9887_priv *tfa9887R, *tfa9887L, *tfa9887R_byte, *tfa9887L_byte;
51 static int eq_mode, preset_mode, srate;
53 static char calibdata[16];
55 static int calibration;
57 static int recalibration;
59 static int powerDown = 1;
61 unsigned int volume_step[5] = {0, 2, 4, 6, 12};
63 /* begin binary data: */
64 unsigned char coldpatch_data[] = {/* 10 */
65 0x08, 0x00, 0x70, 0x00, 0x07, 0x81, 0x00, 0x00, 0x00, 0x01
67 /* end binary data. size = 10 bytes */
69 /* begin binary data: */
71 /* begin binary data: */
72 char n1d2_data[] = {/* 2380 */
73 0x03, 0x00, 0x70, 0x00, 0x01, 0xFB, 0x00, 0x71, 0x40
74 , 0x00, 0x38, 0x08, 0x0A, 0x6F, 0x9B, 0xA6, 0x7D, 0x04, 0xB0, 0xB6, 0x62, 0x88, 0x69, 0x7E
75 , 0xC4, 0x08, 0x6A, 0xBF, 0x54, 0xFC, 0xB5, 0x00, 0x58, 0x7F, 0x3B, 0x80, 0x01, 0x25, 0x30
76 , 0x50, 0x00, 0x80, 0x69, 0x5E, 0xD4, 0x3C, 0x3A, 0x90, 0x00, 0x0D, 0x72, 0x02, 0xC4, 0x80
77 , 0x6A, 0xBE, 0xD4, 0x3E, 0x30, 0x40, 0x00, 0x80, 0x3B, 0x80, 0x01, 0x00, 0xB0, 0xB2, 0xF6
78 , 0x48, 0x6A, 0x5E, 0x54, 0x3E, 0x3A, 0x80, 0x00, 0x80, 0x3B, 0x80, 0x01, 0x00, 0x9B, 0xA6
79 , 0xF8, 0x49, 0x39, 0x84, 0x80, 0x80, 0x92, 0x19, 0xFE, 0x9C, 0x3B, 0x62, 0x40, 0x1C, 0x9B
80 , 0x84, 0x54, 0x3D, 0x61, 0x40, 0x7E, 0x9C, 0x3B, 0x80, 0x07, 0xF1, 0xA6, 0xB6, 0x7E, 0x9C
81 , 0x3B, 0x00, 0x40, 0x21, 0xB5, 0x00, 0x58, 0x3F, 0x3B, 0x80, 0x08, 0x00, 0x9B, 0xA4, 0x7E
82 , 0x9C, 0x9B, 0xA4, 0x54, 0x3D, 0xA5, 0xB2, 0xD8, 0x3F, 0xB5, 0x00, 0x42, 0xC0, 0x3C, 0xD8
83 , 0x03, 0x00, 0x8B, 0x80, 0x7D, 0x7C, 0xB5, 0x00, 0x7E, 0x9C, 0x9B, 0x86, 0x7D, 0x04, 0x38
84 , 0x0A, 0x0A, 0x6F, 0xB0, 0xB2, 0xD4, 0x7E, 0x6A, 0x7E, 0x52, 0xFD, 0x71, 0x04, 0xD8, 0x7F
85 , 0x3B, 0x80, 0x01, 0x25, 0x30, 0x50, 0x00, 0x80, 0x69, 0x5E, 0xD5, 0x3E, 0x72, 0x02, 0xC4
86 , 0x11, 0x6A, 0xBE, 0xD4, 0xBC, 0x30, 0x40, 0x00, 0x80, 0x3B, 0x80, 0x01, 0x00, 0xB0, 0xB2
87 , 0xF6, 0x00, 0xB5, 0x00, 0x54, 0x3C, 0x3A, 0x88, 0x00, 0x80, 0xB5, 0x00, 0x54, 0x3D, 0x3B
88 , 0x80, 0x01, 0x00, 0x9B, 0xA6, 0xFE, 0x9C, 0xB5, 0x00, 0x58, 0x3F, 0x3C, 0xD8, 0x03, 0x00
89 , 0x8B, 0x80, 0x7D, 0x7C, 0xB5, 0x00, 0x7E, 0x9C, 0x3A, 0x88, 0x00, 0x0A, 0x9B, 0x8C, 0x42
90 , 0x88, 0xA6, 0x56, 0x7D, 0x05, 0x39, 0x02, 0x22, 0x20, 0xFB, 0x00, 0x71, 0x40, 0x3E, 0xAA
91 , 0x08, 0xC4, 0x00, 0x3A, 0x89, 0x00, 0xA6, 0xBA, 0x41, 0x58, 0x7B, 0xB5, 0x00, 0x5C, 0x7D
92 , 0x3B, 0x80, 0x13, 0x20, 0xBA, 0x20, 0xDA, 0x7C, 0x6D, 0x5E, 0x50, 0xBD, 0x3A, 0x91, 0x00
93 , 0x18, 0x82, 0x04, 0x7E, 0x50, 0x3A, 0x80, 0x00, 0x29, 0x3A, 0x9A, 0xFF, 0xFA, 0x38, 0x08
94 , 0x0B, 0x68, 0x38, 0x0C, 0x0B, 0x6D, 0xBF, 0x10, 0x42, 0x40, 0x38, 0x0D, 0x0B, 0x6A, 0xBB
95 , 0x00, 0x4C, 0x98, 0x6A, 0x3E, 0xD5, 0xFC, 0x31, 0x80, 0x20, 0xAF, 0x3B, 0x80, 0x01, 0x07
96 , 0x9B, 0xA2, 0xCA, 0x48, 0x7F, 0x4E, 0x54, 0xBC, 0xB5, 0x00, 0x4C, 0x88, 0x3A, 0x91, 0xFF
97 , 0x43, 0xB5, 0x00, 0x42, 0x90, 0x96, 0xF4, 0xD5, 0x3D, 0x3A, 0x81, 0xFF, 0x41, 0x61, 0x48
98 , 0xFD, 0xA9, 0x3A, 0x88, 0x00, 0xAF, 0x61, 0x8A, 0x72, 0xE8, 0x6A, 0x7E, 0xC4, 0x00, 0x30
99 , 0x40, 0x00, 0x80, 0x30, 0x70, 0x02, 0xBC, 0x3B, 0x80, 0x1C, 0x5A, 0xB5, 0x00, 0x55, 0x7C
100 , 0xB5, 0x00, 0x54, 0x3D, 0x3A, 0x88, 0x00, 0x0F, 0x62, 0x24, 0x44, 0x0A, 0x3A, 0x91, 0xFF
101 , 0x4F, 0x30, 0x50, 0x00, 0x80, 0x3B, 0x80, 0x01, 0x25, 0xB5, 0x00, 0x55, 0x7D, 0x6A, 0xDE
102 , 0x54, 0xBD, 0x3A, 0x81, 0xFF, 0xF3, 0x72, 0x22, 0xC2, 0x84, 0x30, 0xA0, 0x0A, 0x70, 0x61
103 , 0x04, 0x42, 0x98, 0x7F, 0x2C, 0x76, 0x91, 0x38, 0x0C, 0x22, 0x08, 0x60, 0x08, 0x43, 0x48
104 , 0x69, 0x3F, 0x54, 0x7D, 0xB5, 0x00, 0x52, 0xFF, 0x3B, 0x80, 0x1B, 0x5B, 0x38, 0x01, 0x0A
105 , 0x6F, 0x30, 0x00, 0x00, 0x20, 0xB9, 0x00, 0x54, 0x3D, 0x9B, 0x2B, 0x55, 0x3C, 0xB0, 0x04
106 , 0x52, 0xBE, 0x38, 0x08, 0x22, 0x01, 0xA6, 0xD0, 0x52, 0x3F, 0x3A, 0x80, 0x00, 0x0F, 0x8B
107 , 0x80, 0x42, 0x50, 0x9B, 0xA2, 0x42, 0xC0, 0xFB, 0x00, 0x71, 0x40, 0x7C, 0x3A, 0x88, 0x00
108 , 0xB4, 0xB5, 0x00, 0x53, 0x7C, 0x31, 0x1F, 0xFF, 0xE9, 0x69, 0x3F, 0x44, 0x0D, 0x3B, 0x80
109 , 0x01, 0x25, 0xB5, 0x00, 0x54, 0xFD, 0x7F, 0x4E, 0x54, 0x3D, 0xB5, 0x00, 0x44, 0x00, 0x3B
110 , 0x80, 0x01, 0x25, 0x9B, 0xA7, 0x7E, 0x9C, 0x7D, 0x8C, 0x54, 0x3D, 0x7C, 0x24, 0xC4, 0x85
111 , 0x6A, 0x3E, 0xD2, 0xBC, 0x61, 0x64, 0x44, 0x00, 0x3B, 0x80, 0x02, 0xE4, 0x30, 0x50, 0x00
112 , 0x80, 0x9B, 0xA2, 0x52, 0x3E, 0x90, 0x90, 0xD4, 0xBD, 0xA2, 0x12, 0xFB, 0x24, 0xB5, 0x00
113 , 0x4C, 0x8D, 0x3B, 0x44, 0x40, 0x7E, 0x31, 0x10, 0x00, 0x1C, 0xB5, 0x00, 0x4C, 0xCD, 0xB5
114 , 0x00, 0x58, 0x3B, 0x3C, 0xD8, 0x03, 0x00, 0x8B, 0x80, 0x7D, 0x7B, 0xB5, 0x00, 0x7E, 0x9C
115 , 0x6C, 0x3F, 0xFD, 0x02, 0x3B, 0x80, 0x10, 0xA5, 0xB5, 0x00, 0x54, 0x7E, 0xB5, 0x00, 0x54
116 , 0x3E, 0x3A, 0x90, 0x00, 0x5C, 0x30, 0x40, 0x00, 0x82, 0x7F, 0x28, 0xC2, 0x51, 0x3A, 0x9A
117 , 0xFF, 0xDE, 0x3A, 0xA3, 0x00, 0x14, 0x30, 0x41, 0x00, 0x00, 0x38, 0x10, 0x26, 0x91, 0x61
118 , 0x2C, 0x7E, 0x50, 0x3A, 0x8C, 0xFF, 0xB3, 0x30, 0x05, 0x00, 0x00, 0x3B, 0x80, 0x0A, 0x71
119 , 0xB5, 0x00, 0x40, 0x60, 0xB5, 0x00, 0x58, 0x3F, 0x3C, 0xD8, 0x03, 0x00, 0x8B, 0x80, 0x7D
120 , 0x7E, 0xB5, 0x00, 0x7E, 0x9C, 0x3C, 0xD0, 0x00, 0x8E, 0x3C, 0xCB, 0xFF, 0xB4, 0x82, 0x14
121 , 0x52, 0xF6, 0x6C, 0x3C, 0xD4, 0x78, 0xB5, 0x00, 0x55, 0xFA, 0x3B, 0x46, 0x40, 0xB8, 0x95
122 , 0xD4, 0xF9, 0x1A, 0xB5, 0x00, 0x53, 0x77, 0xB5, 0x00, 0x52, 0xB6, 0x3C, 0xC5, 0x40, 0xB7
123 , 0x6A, 0x5C, 0x62, 0x0C, 0x61, 0x84, 0xFE, 0x9C, 0x7F, 0x20, 0xC3, 0x41, 0x3C, 0xC9, 0xFF
124 , 0x72, 0x30, 0xA0, 0x02, 0x17, 0xFB, 0x00, 0x71, 0x40, 0xBA, 0x9B, 0xA0, 0xE2, 0x0B, 0x9B
125 , 0xC0, 0xD6, 0x7B, 0x9B, 0x00, 0xD4, 0xFC, 0x8B, 0x80, 0x55, 0x7D, 0x30, 0xB0, 0x21, 0x2C
126 , 0x73, 0x05, 0xD3, 0xB7, 0xB5, 0x00, 0x52, 0x7F, 0x3B, 0x80, 0x01, 0xDA, 0x3A, 0x31, 0xFF
127 , 0xFE, 0x6A, 0x1E, 0x54, 0xBA, 0x7C, 0x01, 0x78, 0x4A, 0x6A, 0x7E, 0x52, 0xB7, 0x3B, 0x80
128 , 0x01, 0x00, 0xB5, 0x00, 0x54, 0x7A, 0x9B, 0xC0, 0xD2, 0xBF, 0x90, 0x94, 0xD5, 0x3D, 0x3A
129 , 0x92, 0x00, 0x04, 0x92, 0x11, 0xD5, 0xBE, 0x6A, 0x1E, 0x54, 0xBA, 0x3A, 0x9B, 0x00, 0x05
130 , 0x7C, 0x27, 0x78, 0x06, 0xB5, 0x00, 0x55, 0x7D, 0x3B, 0x44, 0x40, 0xBF, 0x80, 0x18, 0x54
131 , 0x7A, 0x80, 0xB8, 0x54, 0xFC, 0xB5, 0x00, 0x52, 0xB6, 0x82, 0x14, 0x7E, 0x9C, 0x3B, 0x46
132 , 0x40, 0xDE, 0x6A, 0x5D, 0xD4, 0x38, 0x3C, 0xC5, 0x40, 0xDB, 0xB5, 0x00, 0x43, 0x0B, 0x94
133 , 0x18, 0xFE, 0x9C, 0xB5, 0x00, 0x43, 0x0B, 0x94, 0x18, 0xC0, 0x41, 0x3B, 0x00, 0x40, 0xDF
134 , 0xB5, 0x00, 0x58, 0x39, 0xB5, 0x00, 0x58, 0x39, 0x3C, 0xD8, 0x03, 0x00, 0x8B, 0x80, 0x7E
135 , 0x9C, 0x3C, 0xD0, 0xFF, 0x72, 0x71, 0x65, 0x7D, 0x2B, 0x6A, 0x7B, 0x42, 0x91, 0x6A, 0xBB
136 , 0xE2, 0x4B, 0x6A, 0x3D, 0x52, 0xF8, 0xB5, 0x00, 0x58, 0x7B, 0x3B, 0x80, 0x16, 0x94, 0xB5
137 , 0x00, 0x54, 0xF9, 0x7C, 0x44, 0xD4, 0xB8, 0x6A, 0x1B, 0xC2, 0x91, 0x61, 0xC0, 0x7E, 0x9C
138 , 0x6A, 0xBE, 0x54, 0xB6, 0x3B, 0x80, 0x00, 0xA9, 0x9B, 0xC3, 0x62, 0x09, 0x6A, 0xDB, 0xD4
139 , 0x3C, 0x3A, 0x90, 0x00, 0x25, 0x61, 0xCC, 0x42, 0x80, 0x6A, 0xBE, 0x54, 0xBA, 0x3B, 0x80
140 , 0x00, 0xA9, 0x9B, 0xC3, 0x62, 0x09, 0x9B, 0xA0, 0xD4, 0x37, 0x3A, 0x88, 0x00, 0x96, 0x66
141 , 0x04, 0x45, 0x0A, 0xFB, 0x00, 0x71, 0x40, 0xF8, 0x3A, 0x99, 0xFF, 0x6B, 0xB5, 0x00, 0x72
142 , 0x81, 0x80, 0x18, 0x43, 0x80, 0x6A, 0xFE, 0xD4, 0xBA, 0x3B, 0x80, 0x02, 0x8F, 0x80, 0xD4
143 , 0x62, 0x09, 0x7F, 0x4E, 0x54, 0xBD, 0xB5, 0x00, 0x43, 0x08, 0x38, 0x10, 0x00, 0xCF, 0x3B
144 , 0x80, 0x01, 0x33, 0x9B, 0xA2, 0x74, 0x56, 0x7F, 0x4E, 0x55, 0x3D, 0xB5, 0x00, 0x43, 0x10
145 , 0x3A, 0x82, 0x00, 0xC7, 0x7A, 0x2B, 0x54, 0x7D, 0x30, 0xA0, 0x12, 0x00, 0x30, 0xB0, 0x0B
146 , 0x66, 0x30, 0x50, 0x00, 0x80, 0x3B, 0x80, 0x02, 0xBE, 0xB5, 0x00, 0x62, 0x09, 0x7F, 0x4E
147 , 0x55, 0x3C, 0xB5, 0x00, 0x43, 0x10, 0x90, 0xDB, 0x54, 0xBD, 0x61, 0x44, 0x7E, 0x9C, 0xA2
148 , 0x17, 0x55, 0x39, 0x3A, 0x92, 0x00, 0xC8, 0x3A, 0x89, 0xFF, 0xBE, 0x3B, 0x43, 0x41, 0x49
149 , 0x6A, 0xBF, 0x54, 0xFD, 0x38, 0x12, 0x0B, 0x66, 0x30, 0x60, 0x00, 0x80, 0x30, 0x80, 0x12
150 , 0x00, 0x30, 0xA0, 0x01, 0x80, 0x3B, 0x80, 0x01, 0x1C, 0xB5, 0x00, 0x61, 0x46, 0xB5, 0x00
151 , 0x54, 0xB9, 0x30, 0x80, 0x01, 0x00, 0x30, 0x50, 0x01, 0x00, 0x30, 0x70, 0x00, 0x80, 0x3B
152 , 0x80, 0x1C, 0x3E, 0x38, 0x0C, 0x0B, 0x6B, 0x30, 0x90, 0x01, 0x80, 0x38, 0x0A, 0x22, 0x01
153 , 0x20, 0x80, 0x41, 0x28, 0x30, 0xA0, 0x01, 0x00, 0xB5, 0x00, 0x42, 0x11, 0xB5, 0x00, 0x43
154 , 0x08, 0xD4, 0xC8, 0x42, 0x11, 0x60, 0x24, 0xFE, 0x9C, 0x30, 0x90, 0x01, 0x00, 0x30, 0x50
155 , 0x00, 0x80, 0x30, 0xA0, 0x22, 0x29, 0x3B, 0x80, 0x02, 0x60, 0x30, 0x80, 0x01, 0x80, 0x30
156 , 0x80, 0x01, 0x00, 0x30, 0x50, 0x00, 0x80, 0x3B, 0x80, 0x00, 0xC1, 0x30, 0x90, 0x01, 0x00
157 , 0x30, 0x90, 0x01, 0x00, 0xB5, 0x00, 0x78, 0x09, 0x30, 0x50, 0x00, 0x3F, 0x3B, 0x80, 0x00
158 , 0x51, 0xFB, 0x00, 0x71, 0x41, 0x36, 0xB5, 0x00, 0x54, 0x7F, 0x38, 0x0A, 0x0B, 0x60, 0xD0
159 , 0x0C, 0x54, 0x3F, 0x30, 0x60, 0x00, 0x3F, 0x3B, 0x80, 0x00, 0x7A, 0xB5, 0x00, 0x61, 0x40
160 , 0x9B, 0xA8, 0x74, 0x55, 0xA5, 0xF2, 0xE2, 0x09, 0x38, 0x09, 0x0B, 0x69, 0x38, 0x0A, 0x0B
161 , 0x61, 0x38, 0x0C, 0x0A, 0x7C, 0x30, 0xA0, 0x0B, 0x67, 0x3B, 0x80, 0x00, 0x89, 0x9B, 0xE0
162 , 0xD3, 0xD5, 0x38, 0x0C, 0x0B, 0x67, 0x9B, 0xA8, 0x54, 0xBD, 0xA6, 0x1A, 0xFE, 0x9C, 0x3B
163 , 0x00, 0x41, 0x4A, 0x38, 0x01, 0x0B, 0x69, 0x9B, 0xA8, 0x54, 0xBD, 0x61, 0x84, 0x7E, 0x9C
164 , 0x92, 0x1B, 0xFE, 0x9C, 0x3B, 0x63, 0x41, 0x52, 0x38, 0x08, 0x0B, 0x6C, 0x9B, 0xDF, 0xD4
165 , 0xBE, 0xA5, 0xB2, 0xC3, 0x48, 0x38, 0x0B, 0x0B, 0x67, 0x38, 0x09, 0x0B, 0x69, 0x3B, 0x80
166 , 0x41, 0xD0, 0xB5, 0x00, 0x7E, 0x9C, 0x7F, 0x4E, 0x54, 0xBD, 0xB5, 0x00, 0x42, 0x88, 0x3A
167 , 0x91, 0xFF, 0x7A, 0x31, 0x20, 0x00, 0xC8, 0x82, 0x14, 0x44, 0x95, 0x3B, 0x44, 0x41, 0x60
168 , 0x38, 0x0A, 0x0B, 0x6A, 0x3A, 0x81, 0x00, 0x29, 0x38, 0x0C, 0x0B, 0x69, 0x38, 0x0E, 0x0B
169 , 0x62, 0xA2, 0x1B, 0xFE, 0x9C, 0x3B, 0x66, 0x41, 0x6F, 0x38, 0x0C, 0x0A, 0x7A, 0xA2, 0x13
170 , 0x7E, 0x9C, 0x3B, 0x64, 0x41, 0x6F, 0x38, 0x0C, 0x0A, 0x79, 0xA2, 0x13, 0x7E, 0x9C, 0x3B
171 , 0x67, 0x41, 0x6F, 0x38, 0x0C, 0x0B, 0x63, 0xD0, 0x35, 0x54, 0xB9, 0x3A, 0x89, 0x00, 0x50
172 , 0xB5, 0x00, 0x1A, 0x61, 0x38, 0x00, 0x0B, 0x68, 0x95, 0xD8, 0xC0, 0x40, 0xB3, 0xB7, 0x7E
173 , 0x9C, 0x3B, 0x00, 0x41, 0x76, 0x38, 0x0B, 0x0B, 0x6A, 0x38, 0x0C, 0x0B, 0x64, 0xD0, 0x34
174 , 0x54, 0xBE, 0x38, 0x0A, 0x0B, 0x65, 0x9B, 0x1F, 0xE1, 0x80, 0x95, 0xD8, 0xFE, 0x40, 0xFB
175 , 0x00, 0x71, 0x41, 0x74, 0xB2, 0xB7, 0x40, 0x48, 0x38, 0x0B, 0x0B, 0x6A, 0x61, 0x08, 0x54
176 , 0xBC, 0xB5, 0x00, 0x43, 0x08, 0xA2, 0x13, 0x54, 0x3E, 0x3A, 0x92, 0xFF, 0x94, 0x3B, 0x46
177 , 0x41, 0x7E, 0x3A, 0x89, 0xFF, 0xEB, 0x9B, 0xBF, 0xD4, 0xFC, 0xB5, 0x00, 0x42, 0xC0, 0xB5
178 , 0x00, 0x42, 0x90, 0x3A, 0x8A, 0xFF, 0xA5, 0x82, 0x14, 0x7E, 0x9C, 0x3B, 0x43, 0x41, 0x91
179 , 0x6A, 0x7B, 0xD5, 0x37, 0x3A, 0x8A, 0x00, 0x95, 0x31, 0x1F, 0xFF, 0x6A, 0x9B, 0xA0, 0xCC
180 , 0x0D, 0x6A, 0x7E, 0xC3, 0x90, 0x6A, 0x1B, 0x72, 0x81, 0xB5, 0x00, 0x74, 0x56, 0x30, 0xA0
181 , 0x0E, 0xBA, 0x3B, 0x80, 0x02, 0x8F, 0x80, 0x18, 0x61, 0x85, 0x6A, 0x5D, 0x55, 0x3D, 0x3B
182 , 0x80, 0x1A, 0x0A, 0x3C, 0xC8, 0xFF, 0xD6, 0x3B, 0x00, 0x41, 0x92, 0xB5, 0x00, 0x54, 0xBC
183 , 0xB5, 0x00, 0x54, 0xBC, 0x61, 0x44, 0x7E, 0x9C, 0x98, 0xB5, 0x7E, 0x9C, 0x82, 0x14, 0x7E
184 , 0x9C, 0x3B, 0x62, 0x41, 0xA3, 0x6A, 0x9C, 0x54, 0xB9, 0x3A, 0x81, 0x00, 0x14, 0x3A, 0x8A
185 , 0x00, 0x22, 0x61, 0x40, 0x43, 0x08, 0x3A, 0x90, 0xFF, 0xED, 0xD0, 0x4C, 0x43, 0x10, 0xB5
186 , 0x00, 0x54, 0xB6, 0x94, 0x03, 0xE2, 0x09, 0x30, 0xA0, 0x07, 0xA1, 0x3B, 0x80, 0x00, 0x14
187 , 0xB5, 0x00, 0x61, 0x40, 0x3B, 0x00, 0x41, 0xA4, 0xB5, 0x00, 0x55, 0xB7, 0xB5, 0x00, 0x55
188 , 0xB7, 0x3A, 0x83, 0x00, 0x97, 0x9B, 0xA0, 0xC5, 0x04, 0x31, 0x0F, 0xFF, 0x6A, 0x7F, 0x4E
189 , 0x4C, 0x05, 0xB5, 0x00, 0x72, 0x81, 0x80, 0x18, 0x43, 0x98, 0x6A, 0x3B, 0xD4, 0xB6, 0x3B
190 , 0x80, 0x02, 0x8F, 0x80, 0xD4, 0x62, 0x09, 0x6A, 0x5D, 0x55, 0x37, 0xB5, 0x00, 0x54, 0x36
191 , 0x3B, 0x80, 0x17, 0x99, 0xB5, 0x00, 0x7E, 0x9C, 0x8B, 0x80, 0x54, 0xB7, 0xFB, 0x00, 0x71
192 , 0x41, 0xB2, 0x3A, 0x89, 0x00, 0x5C, 0x3A, 0x91, 0xFF, 0xF2, 0x60, 0x00, 0x78, 0x11, 0x38
193 , 0x0A, 0x0B, 0x6A, 0xB5, 0x00, 0x4A, 0x10, 0xB3, 0x02, 0xC3, 0x08, 0x90, 0xDB, 0xCA, 0x50
194 , 0x3A, 0x98, 0x00, 0x10, 0xB2, 0xD3, 0x42, 0x98, 0x92, 0x17, 0xC3, 0x48, 0xB5, 0x00, 0x48
195 , 0x40, 0x3B, 0x42, 0x41, 0xCD, 0xB5, 0x00, 0x55, 0x39, 0x3A, 0x9A, 0x00, 0x5D, 0xB5, 0x00
196 , 0x43, 0x18, 0x82, 0x18, 0x7E, 0x9C, 0x3B, 0x66, 0x41, 0xCD, 0x3A, 0x8A, 0x00, 0x5E, 0xB5
197 , 0x00, 0x43, 0x08, 0x90, 0xD8, 0xFE, 0x9C, 0xA2, 0x1A, 0xC3, 0x48, 0x3B, 0x66, 0x41, 0xCB
198 , 0x6C, 0x1D, 0xFE, 0x4A, 0x3B, 0x00, 0x41, 0xCE, 0xB5, 0x00, 0x7E, 0x48, 0x3B, 0x00, 0x41
199 , 0xCE, 0xB5, 0x00, 0x58, 0x3B, 0xB5, 0x00, 0x58, 0x3B, 0x3C, 0xD8, 0x03, 0x00, 0x7F, 0x4E
200 , 0x7D, 0x55, 0x39, 0x84, 0x80, 0x02, 0x39, 0x86, 0x80, 0x02, 0x30, 0x40, 0x01, 0x00, 0xA8
201 , 0x1E, 0x7E, 0x9C, 0xA2, 0x02, 0x7E, 0x9C, 0x3B, 0x43, 0x41, 0xDA, 0x30, 0x10, 0x01, 0xFF
202 , 0xA8, 0x38, 0xFE, 0x9C, 0x30, 0x4F, 0xFE, 0x00, 0xA9, 0x26, 0x7E, 0x9C, 0x3C, 0xD8, 0x03
203 , 0x00, 0x9B, 0x99, 0x7E, 0x9C, 0xA0, 0x86, 0x7E, 0x9C, 0x3A, 0x89, 0x00, 0xC7, 0x7E, 0x81
204 , 0xC2, 0x88, 0x3A, 0x89, 0xFF, 0xE9, 0x6A, 0x3F, 0x54, 0xFD, 0xB5, 0x00, 0x58, 0x7F, 0x30
205 , 0x60, 0x00, 0x80, 0x3B, 0x80, 0x00, 0xB6, 0xB8, 0xA2, 0xE2, 0x48, 0xB5, 0x00, 0x54, 0xBE
206 , 0x38, 0x20, 0x0A, 0x6F, 0xB5, 0x00, 0x76, 0x88, 0x30, 0x62, 0x00, 0x00, 0xB5, 0x00, 0x42
207 , 0x90, 0xA0, 0xB7, 0x55, 0xBD, 0xB5, 0x00, 0x42, 0xD0, 0x38, 0x0C, 0x22, 0x13, 0xB5, 0x00
208 , 0x42, 0x98, 0xD0, 0x35, 0x7E, 0x9C, 0x3A, 0x83, 0xFF, 0x57, 0x3F, 0x00, 0x71, 0x41, 0xF0
209 , 0xB5, 0x00, 0x18, 0x61, 0x3A, 0x90, 0x00, 0x9B, 0xD0, 0x4C, 0x62, 0x09, 0x30, 0x70, 0x00
210 , 0x80, 0xB5, 0x00, 0x55, 0x7D, 0x3B, 0x80, 0x00, 0xA9, 0x9B, 0xC6, 0x61, 0x40, 0x7F, 0x4E
211 , 0x54, 0xBD, 0x6A, 0x1F, 0x4C, 0x08, 0x3B, 0x80, 0x01, 0x0E, 0x30, 0x50, 0x00, 0x80, 0xB5
212 , 0x00, 0x58, 0x3F, 0x3C, 0xD8, 0x03, 0x00, 0x8B, 0x80, 0x7D, 0x7D, 0xB5, 0x00, 0x7E, 0x9C
213 , 0x03, 0x00, 0x70, 0x00, 0x03, 0x21, 0x00, 0x71, 0x0A, 0x6F, 0x00, 0x00, 0x01, 0x00, 0x00
214 , 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00
215 , 0x02, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x2D, 0x00, 0x71, 0x0B, 0x60
216 , 0x00, 0xB8, 0x45, 0x7F, 0xEA, 0x29, 0x00, 0x00, 0x07, 0x40, 0x0F, 0x26, 0x3F, 0xFF, 0x9F
217 , 0x02, 0xCC, 0xCD, 0x00, 0x12, 0x00, 0x40, 0x00, 0x00, 0x01, 0x47, 0xAE, 0x00, 0x00, 0x00
218 , 0x02, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x08, 0x04, 0x00, 0x00, 0x0F, 0x00, 0x71
219 , 0x0A, 0x79, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x7E, 0x4D, 0xFE, 0x03
220 , 0x00, 0x70, 0x00, 0x05, 0x03, 0x00, 0x70, 0x00, 0x07, 0x7B, 0x00, 0x71, 0x03, 0x00, 0x00
221 , 0x00, 0x01, 0x00, 0x0B, 0x23, 0x00, 0x40, 0x00, 0x00, 0x3B, 0x80, 0x00, 0x00, 0x01, 0x00
222 , 0x0B, 0xAB, 0x00, 0x40, 0x24, 0x00, 0x3B, 0x80, 0x00, 0x00, 0x01, 0x00, 0x0D, 0xF5, 0x00
223 , 0x40, 0x3A, 0x00, 0x3B, 0x80, 0x00, 0x00, 0x01, 0x00, 0x0A, 0x6B, 0x00, 0x40, 0x97, 0x00
224 , 0x3B, 0x80, 0x00, 0x00, 0x01, 0x00, 0x05, 0xC6, 0x00, 0x40, 0xAB, 0x00, 0x3B, 0x80, 0x00
225 , 0x00, 0x01, 0x00, 0x0D, 0x24, 0x00, 0x40, 0xE2, 0x00, 0x3B, 0x80, 0x00, 0x00, 0x01, 0x00
226 , 0x12, 0x3A, 0x00, 0x7E, 0x9C, 0x00, 0xB5, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x7B, 0x00
227 , 0x41, 0xD0, 0x00, 0x3B, 0x80, 0x00, 0x00, 0x01, 0x00, 0x1B, 0xA7, 0x00, 0x41, 0xDD, 0x00
228 , 0x3B, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03
229 , 0x00, 0x70, 0x00, 0x00, 0x23, 0x00, 0x70, 0x00, 0x02, 0x00, 0x01, 0x00, 0x80, 0x03, 0xFF
230 , 0xFF, 0xF9, 0xFF, 0xFF, 0xF7, 0xFF, 0xFF, 0xF6, 0x00, 0x00, 0x1D, 0x00, 0x00, 0x1B, 0x00
231 , 0x00, 0x1B, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x1C, 0x03, 0x00, 0x70, 0x01
234 /* end binary data. size = 2380bytes */
236 /* begin binary data: */
237 char speaker_data[] = {/* 423 */
238 0x00, 0x00, 0xD1, 0xFF, 0xFE, 0x06, 0xFF, 0xFE, 0x55, 0x00, 0x03, 0x2F, 0xFF, 0xFA, 0xF9
239 , 0x00, 0x05, 0x77, 0xFF, 0xFC, 0x89, 0xFF, 0xFC, 0x9A, 0x00, 0x00, 0x0B, 0xFF, 0xFA, 0x84
240 , 0x00, 0x02, 0x39, 0xFF, 0xFA, 0xD6, 0x00, 0x02, 0x98, 0xFF, 0xFC, 0xF7, 0x00, 0x00, 0xFE
241 , 0xFF, 0xFB, 0xD6, 0xFF, 0xFF, 0x47, 0x00, 0x02, 0x0A, 0xFF, 0xFD, 0x0F, 0x00, 0x01, 0x40
242 , 0xFF, 0xFD, 0xE5, 0xFF, 0xFE, 0x9D, 0xFF, 0xFE, 0xD6, 0xFF, 0xFE, 0x68, 0xFF, 0xFD, 0x59
243 , 0xFF, 0xFE, 0xAB, 0xFF, 0xFE, 0x65, 0x00, 0x00, 0x2E, 0xFF, 0xFB, 0x78, 0xFF, 0xFF, 0x2C
244 , 0x00, 0x00, 0x28, 0xFF, 0xFA, 0x9D, 0x00, 0x01, 0x7D, 0xFF, 0xFC, 0x9E, 0xFF, 0xFC, 0x0C
245 , 0x00, 0x01, 0x97, 0xFF, 0xF9, 0x25, 0x00, 0x00, 0xA5, 0xFF, 0xFC, 0x5B, 0xFF, 0xFF, 0x1B
246 , 0x00, 0x01, 0xCE, 0xFF, 0xF9, 0xE0, 0x00, 0x03, 0x9B, 0x00, 0x00, 0x98, 0xFF, 0xFC, 0x5D
247 , 0x00, 0x01, 0x7A, 0xFF, 0xFA, 0x43, 0xFF, 0xFF, 0x82, 0xFF, 0xFF, 0x66, 0xFF, 0xF8, 0xD6
248 , 0xFF, 0xFD, 0xE7, 0x00, 0x01, 0x04, 0xFF, 0xF7, 0xF3, 0xFF, 0xFE, 0x79, 0xFF, 0xFD, 0x5B
249 , 0xFF, 0xFB, 0xC4, 0xFF, 0xFE, 0xF5, 0xFF, 0xFA, 0x9B, 0xFF, 0xFF, 0x87, 0xFF, 0xFB, 0xC1
250 , 0xFF, 0xFD, 0xF3, 0x00, 0x00, 0x12, 0x00, 0x01, 0x8C, 0xFF, 0xF6, 0x37, 0x00, 0x05, 0x49
251 , 0xFF, 0xFA, 0x1F, 0xFF, 0xFC, 0x9E, 0x00, 0x00, 0xD8, 0xFF, 0xF7, 0x74, 0xFF, 0xFE, 0x29
252 , 0xFF, 0xFD, 0x42, 0xFF, 0xF3, 0x14, 0x00, 0x02, 0x1B, 0xFF, 0xF5, 0x86, 0xFF, 0xF7, 0x64
253 , 0xFF, 0xF6, 0x6D, 0xFF, 0xF3, 0x81, 0x00, 0x00, 0x2F, 0xFF, 0xF0, 0x35, 0xFF, 0xFC, 0xFA
254 , 0x00, 0x03, 0x5E, 0xFF, 0xF9, 0xA2, 0x00, 0x09, 0x46, 0xFF, 0xFE, 0x88, 0x00, 0x09, 0x61
255 , 0x00, 0x04, 0x3E, 0x00, 0x07, 0x57, 0x00, 0x09, 0xA2, 0xFF, 0xFD, 0x53, 0x00, 0x10, 0xD6
256 , 0xFF, 0xF7, 0xEE, 0xFF, 0xFC, 0xDC, 0x00, 0x04, 0x42, 0xFF, 0xF4, 0x9B, 0xFF, 0xF4, 0xA3
257 , 0xFF, 0xF0, 0x54, 0xFF, 0xF0, 0x30, 0xFF, 0xFB, 0x3B, 0xFF, 0xF2, 0x47, 0x00, 0x0E, 0xBA
258 , 0xFF, 0xF7, 0x96, 0x00, 0x22, 0x85, 0x00, 0x13, 0xA9, 0x00, 0x57, 0x54, 0x00, 0x13, 0x9B
259 , 0x00, 0x69, 0xD8, 0x00, 0x2B, 0xD5, 0x00, 0x73, 0x6B, 0x00, 0x40, 0x09, 0x00, 0x40, 0x8E
260 , 0xFF, 0xD6, 0x1D, 0xFF, 0xEA, 0x06, 0xFF, 0xB0, 0xD7, 0xFF, 0x5F, 0x5B, 0xFF, 0xA0, 0xAA
261 , 0x07, 0x36, 0x2D, 0xFF, 0xAA, 0xA7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
262 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
263 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6C, 0xCC, 0xCD
264 , 0x66, 0x66, 0x66, 0x20, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x00, 0x00, 0x19, 0x99, 0x9A
265 , 0x00, 0x01, 0x76, 0x00, 0x01, 0x77, 0x04, 0x00, 0x00, 0x00, 0x67, 0xAE, 0x1C, 0xC0, 0x00
268 /* end binary data. size = 423 bytes */
270 /* begin binary data: */
271 char config_data[] = {/* 165 */
272 0x09, 0xF3, 0x33, 0x01, 0x3E, 0x66, 0x00, 0x54, 0xCD, 0x00, 0x00, 0x14, 0x00, 0x00, 0x02
273 , 0x1A, 0xE6, 0x40, 0x1B, 0x40, 0xD4, 0x1C, 0x59, 0xDA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
274 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x4B, 0x00, 0x01, 0x4B
275 , 0x00, 0x00, 0x00, 0x00, 0x00, 0xFA, 0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01
276 , 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x80, 0x00, 0x20, 0x00, 0x00, 0x00, 0x03, 0x47
277 , 0x01, 0x47, 0xAE, 0x00, 0x19, 0x9A, 0x00, 0x00, 0x00, 0x00, 0x0C, 0xCD, 0x02, 0x80, 0x00
278 , 0x00, 0x00, 0x01, 0x05, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0x50, 0x00, 0x00
279 , 0x00, 0x10, 0x00, 0x08, 0x00, 0x00, 0x00, 0x19, 0x9A, 0x00, 0x00, 0x80, 0x00, 0x00, 0x02
280 , 0x00, 0x00, 0x01, 0x01, 0x47, 0xAE, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x19, 0x99, 0x9A
281 , 0x00, 0x80, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x30, 0x00, 0x00, 0x02, 0x00, 0x00, 0x18
282 , 0xEC, 0x00, 0x00, 0x00, 0x03, 0xD7, 0x01, 0x00, 0x00, 0x20, 0x00, 0x00, 0x01, 0x00, 0x00
284 /* end binary data. size = 165 bytes */
286 /* begin binary data: */
287 char eq_data_hand[] = {/* 180 */
288 0x00, 0x00, 0x01, 0xC2, 0x90, 0xA8, 0x7D, 0x5E, 0x28, 0x3E, 0xB3, 0x60, 0x82, 0x99, 0x40
289 , 0x3E, 0xB3, 0x60, 0x00, 0x00, 0x01, 0xC2, 0x90, 0xA8, 0x7D, 0x5E, 0x28, 0x3E, 0xB3, 0x60
290 , 0x82, 0x99, 0x40, 0x3E, 0xB3, 0x60, 0x00, 0x00, 0x01, 0xC8, 0xCF, 0x48, 0x76, 0x89, 0x90
291 , 0x34, 0xDC, 0x58, 0x89, 0xF4, 0xCC, 0x42, 0xD2, 0xBC, 0x00, 0x00, 0x01, 0xEE, 0x00, 0x24
292 , 0x31, 0xEB, 0x08, 0x29, 0x55, 0x8C, 0x8C, 0x6F, 0x80, 0x6A, 0x4F, 0xC8, 0x00, 0x00, 0x01
293 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00
294 , 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
295 , 0x40, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
296 , 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
297 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00
298 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x01
299 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00
301 /* end binary data. size = 180 bytes */
303 /* begin binary data: */
304 char eq_data_table[] = {/* 180 */
305 0x00, 0x00, 0x01, 0xC2, 0x90, 0xA8, 0x7D, 0x5E, 0x28, 0x3E, 0xB3, 0x60, 0x82, 0x99, 0x40
306 , 0x3E, 0xB3, 0x60, 0x00, 0x00, 0x01, 0xC2, 0x90, 0xA8, 0x7D, 0x5E, 0x28, 0x3E, 0xB3, 0x60
307 , 0x82, 0x99, 0x40, 0x3E, 0xB3, 0x60, 0x00, 0x00, 0x01, 0xC8, 0xCF, 0x48, 0x76, 0x89, 0x90
308 , 0x36, 0x25, 0x30, 0x89, 0xA7, 0x50, 0x41, 0x3C, 0x6C, 0x00, 0x00, 0x01, 0xEE, 0x00, 0x24
309 , 0x31, 0xEB, 0x08, 0x29, 0x55, 0x8C, 0x8C, 0x6F, 0x80, 0x6A, 0x4F, 0xC8, 0x00, 0x00, 0x01
310 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00
311 , 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
312 , 0x40, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
313 , 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
314 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00
315 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x01
316 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00
319 /* end binary data. size = 180 bytes */
321 /* begin binary data: */
322 char preset_data0[] = {/* 87 */
323 0x00, 0x00, 0x07, 0x00, 0x01, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x40
324 , 0x00, 0x00, 0x00, 0x00, 0x01, 0x2C, 0x01, 0x47, 0xAE, 0x00, 0x2B, 0xB1, 0x00, 0x00, 0x9D
325 , 0x00, 0x0D, 0x1B, 0x01, 0x00, 0x00, 0x07, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x08, 0x00, 0x00
326 , 0x08, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x0C, 0xCD, 0x00, 0x40, 0x00
327 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x48, 0x00, 0x01, 0x48
328 , 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0C, 0xCD, 0x00, 0x00, 0x03
330 /* end binary data. size = 87 bytes */
332 /* begin binary data: */
333 char preset_data1[] = {/* 87 */
334 0x00, 0x00, 0x07, 0x00, 0x01, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x40
335 , 0x00, 0x00, 0x00, 0x00, 0x01, 0x2C, 0x01, 0x47, 0xAE, 0x00, 0x2B, 0xB1, 0x00, 0x00, 0x9D
336 , 0x00, 0x0D, 0x1B, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00
337 , 0x08, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x0C, 0xCD, 0x00, 0x40, 0x00
338 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x48, 0x00, 0x01, 0x48
339 , 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0C, 0xCD, 0x00, 0x00, 0x03
341 /* end binary data. size = 87 bytes */
343 char preset_data2[] = {/* 87 */
344 0x00, 0x00, 0x07, 0x00, 0x01, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x40
345 , 0x00, 0x00, 0x00, 0x00, 0x01, 0x2C, 0x01, 0x47, 0xAE, 0x00, 0x2B, 0xB1, 0x00, 0x00, 0x9D
346 , 0x00, 0x0D, 0x1B, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x05, 0x00, 0x00, 0x08, 0x00, 0x00
347 , 0x08, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x0C, 0xCD, 0x00, 0x40, 0x00
348 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x48, 0x00, 0x01, 0x48
349 , 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0C, 0xCD, 0x00, 0x00, 0x03
351 /* end binary data. size = 87 bytes */
353 /* begin binary data: */
354 char preset_data3[] = {/* 87 */
355 0x00, 0x00, 0x07, 0x00, 0x01, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x40
356 , 0x00, 0x00, 0x00, 0x00, 0x01, 0x2C, 0x01, 0x47, 0xAE, 0x00, 0x2B, 0xB1, 0x00, 0x00, 0x9D
357 , 0x00, 0x0D, 0x1B, 0x01, 0x00, 0x00, 0x01, 0x80, 0x00, 0x04, 0x00, 0x00, 0x08, 0x00, 0x00
358 , 0x08, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x0C, 0xCD, 0x00, 0x40, 0x00
359 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x48, 0x00, 0x01, 0x48
360 , 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0C, 0xCD, 0x00, 0x00, 0x03
362 /* end binary data. size = 87 bytes */
364 /* begin binary data: */
365 char preset_data4[] = {/* 87 */
366 0x00, 0x00, 0x07, 0x00, 0x01, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x40
367 , 0x00, 0x00, 0x00, 0x00, 0x01, 0x2C, 0x01, 0x47, 0xAE, 0x00, 0x2B, 0xB1, 0x00, 0x00, 0x9D
368 , 0x00, 0x0D, 0x1B, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x08, 0x00, 0x00
369 , 0x08, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x0C, 0xCD, 0x00, 0x40, 0x00
370 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x48, 0x00, 0x01, 0x48
371 , 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0C, 0xCD, 0x00, 0x00, 0x03
373 /* end binary data. size = 87 bytes */
375 void convertBytes2Data(int num_bytes, const unsigned char bytes[], int data[])
377 int i; /* index for data */
378 int k; /* index for bytes */
380 int num_data = num_bytes/3;
382 for (i = 0, k = 0; i < num_data; ++i, k += 3) {
383 d = (bytes[k] << 16) | (bytes[k+1] << 8) | (bytes[k+2]);
384 if (bytes[k] & 0x80) {/* sign bit was set*/
391 int ProcessPatchFile(struct tfa9887_priv *tfa9887, struct tfa9887_priv *tfa9887_byte, int length, const unsigned char* bytes)
395 unsigned char buffer[MAX_I2C_LENGTH];
399 error = Tfa9887_ReadRegister(tfa9887, TFA9887_STATUS, &status);
400 if (error == Tfa9887_Error_Ok) {
401 if ( (status & 0x0043) != 0x0043) {
402 /* one of Vddd, PLL and clocks not ok */
406 //pr_info("tfa status %u\n",status);
407 error = DspReadMem(tfa9887, tfa9887_byte, 0x2210, 1, &value);
408 //pr_info("tfa Version %x\n",value);
409 while (index < length) {
410 /* extract little endian length */
411 size = bytes[index] + bytes[index+1] * 256;
413 if ( (index + size) > length) {
414 /* too big, outside the buffer, error in the input data */
417 memcpy(buffer, bytes + index, size);
418 error = regmap_raw_write(tfa9887_byte->regmap, buffer[0], &buffer[1] , (size -1));
419 //pr_info("%d %d\n",buffer[0],size -1);
420 if (error != Tfa9887_Error_Ok) {
421 pr_info("ProcessPatchFile error\n");
429 int DspReadMem(struct tfa9887_priv *tfa9887, struct tfa9887_priv *tfa9887_byte, unsigned short start_offset, int num_words, int *pValues)
431 unsigned int cf_ctrl; /* the value to sent to the CF_CONTROLS register */
432 unsigned char bytes[MAX_I2C_LENGTH];
433 int burst_size; /* number of words per burst size */
434 int bytes_per_word=3;
438 /* first set DMEM and AIF, leaving other bits intact */
439 error = Tfa9887_ReadRegister(tfa9887, TFA9887_CF_CONTROLS, &cf_ctrl);
440 if (error != Tfa9887_Error_Ok) {
443 cf_ctrl &= ~0x000E; /* clear AIF & DMEM */
444 cf_ctrl |= (Tfa9887_DMEM_XMEM<<1); /* set DMEM, leave AIF cleared for autoincrement */
445 error = Tfa9887_WriteRegister(tfa9887, TFA9887_CF_CONTROLS, cf_ctrl);
446 if (error != Tfa9887_Error_Ok) {
449 error = Tfa9887_WriteRegister(tfa9887, TFA9887_CF_MAD, start_offset);
450 if (error != Tfa9887_Error_Ok) {
453 num_bytes = num_words*bytes_per_word;
455 for (; num_bytes > 0; ) {
456 burst_size = ROUND_DOWN(MAX_I2C_LENGTH, bytes_per_word);
457 if (num_bytes < burst_size) {
458 burst_size = num_bytes;
461 error = regmap_raw_read(tfa9887_byte->regmap, TFA9887_CF_MEM, bytes,burst_size);
462 if (error != Tfa9887_Error_Ok) {
465 convertBytes2Data(burst_size, bytes, p);
466 num_bytes -= burst_size;
467 p += burst_size/bytes_per_word;
469 return Tfa9887_Error_Ok;
472 int DspSetParam(struct tfa9887_priv *tfa9887, struct tfa9887_priv *tfa9887_byte, unsigned char module_id, unsigned char param_id, int num_bytes, const unsigned char *data)
476 unsigned int cf_ctrl = 0x0002; /* the value to be sent to the CF_CONTROLS register: cf_req=00000000, cf_int=0, cf_aif=0, cf_dmem=XMEM=01, cf_rst_dsp=0 */
477 unsigned int cf_mad = 0x0001; /* memory address to be accessed (0 : Status, 1 : ID, 2 : parameters) */
478 unsigned int cf_status; /* the contents of the CF_STATUS register */
479 unsigned char mem[3];
480 int rpcStatus = STATUS_OK;
483 error = Tfa9887_WriteRegister(tfa9887, TFA9887_CF_CONTROLS, cf_ctrl);
484 if (error == Tfa9887_Error_Ok) {
485 error = Tfa9887_WriteRegister(tfa9887, TFA9887_CF_MAD, cf_mad);
487 if (error == Tfa9887_Error_Ok) {
490 id[1] = module_id+128;
492 error = regmap_raw_write(tfa9887_byte->regmap, TFA9887_CF_MEM,&id, 3);
495 error = regmap_raw_write(tfa9887_byte->regmap, TFA9887_CF_MEM, data, num_bytes);
497 if (error == Tfa9887_Error_Ok) {
498 cf_ctrl |= (1<<8) | (1<<4); /* set the cf_req1 and cf_int bit */
499 error = Tfa9887_WriteRegister(tfa9887, TFA9887_CF_CONTROLS, cf_ctrl);
502 error = Tfa9887_ReadRegister(tfa9887, TFA9887_CF_STATUS, &cf_status);
504 usleep_range(100, 200);
505 } while ((error == Tfa9887_Error_Ok) && ((cf_status & 0x0100) == 0) && (tries < 100)); /* don't wait forever, DSP is pretty quick to respond (< 1ms) */
507 if (tries >= 100 && !powerDown) {
508 /* something wrong with communication with DSP */
509 pr_info("Setparam failed\n");
515 if (error == Tfa9887_Error_Ok) {
516 error = Tfa9887_WriteRegister(tfa9887, TFA9887_CF_CONTROLS,cf_ctrl);
519 if (error == Tfa9887_Error_Ok) {
520 error = Tfa9887_WriteRegister(tfa9887, TFA9887_CF_MAD, cf_mad);
522 if (error == Tfa9887_Error_Ok) {
523 error = regmap_raw_read(tfa9887_byte->regmap, TFA9887_CF_MEM,&mem,3);
524 rpcStatus = (int)((mem[0] << 16) | (mem[1] << 8) | mem[2]);
526 if (error == Tfa9887_Error_Ok) {
527 if (rpcStatus != STATUS_OK) {
528 error = rpcStatus+100;
529 //pr_info("RPC rpcStatus =%d\n",error);
535 int DspGetParam(struct tfa9887_priv *tfa9887, struct tfa9887_priv *tfa9887_byte,
536 unsigned char module_id, unsigned char param_id, int num_bytes, unsigned char *data)
539 unsigned int cf_ctrl = 0x0002; /* the value to be sent to the CF_CONTROLS register: cf_req=00000000, cf_int=0, cf_aif=0, cf_dmem=XMEM=01, cf_rst_dsp=0 */
540 unsigned int cf_mad = 0x0001; /* memory address to be accessed (0 : Status, 1 : ID, 2 : parameters) */
541 unsigned int cf_status; /* the contents of the CF_STATUS register */
542 unsigned char mem[3];
545 /* 1) write the id and data to the DSP XMEM */
547 Tfa9887_WriteRegister(tfa9887, TFA9887_CF_CONTROLS,
549 error = Tfa9887_WriteRegister(tfa9887, TFA9887_CF_MAD, cf_mad);
551 id[1] = module_id + 128;
553 /* only try MEM once, if error, need to resend mad as well */
554 error = regmap_raw_write(tfa9887_byte->regmap, TFA9887_CF_MEM, id, 3);
555 /* 2) wake up the DSP and let it process the data */
557 cf_ctrl |= (1 << 8) | (1 << 4); /* set the cf_req1 and cf_int bit */
559 Tfa9887_WriteRegister(tfa9887, TFA9887_CF_CONTROLS,
562 /* 3) wait for the ack */
563 if (error == Tfa9887_Error_Ok) {
566 Tfa9887_ReadRegister(tfa9887, TFA9887_CF_STATUS,
570 } while (( error == 0) && ((cf_status & 0x0100) == 0)
571 && (tries < 100)); /* don't wait forever, DSP is pretty quick to respond (< 1ms) */
573 /* something wrong with communication with DSP */
574 pr_info("GetParam failed\n");
578 /* 4) check the RPC return value */
581 if (error == Tfa9887_Error_Ok) {
582 error = Tfa9887_WriteRegister(tfa9887, TFA9887_CF_CONTROLS,cf_ctrl);
584 if (error == Tfa9887_Error_Ok) {
585 error = Tfa9887_WriteRegister(tfa9887, TFA9887_CF_MAD, cf_mad);
587 if (error == Tfa9887_Error_Ok) {
588 regmap_raw_read(tfa9887_byte->regmap, TFA9887_CF_MEM,&mem,3);
589 error = (mem[0] << 16) | (mem[1] << 8) | mem[2];
592 if (error != Tfa9887_Error_Ok) {
593 pr_info("RPC error\n");
597 /* 5) read the resulting data */
599 cf_mad = 0x0002; /* memory address to be accessed (0 : Status, 1 : ID, 2 : parameters) */
600 error = Tfa9887_WriteRegister(tfa9887, TFA9887_CF_MAD, cf_mad);
604 regmap_raw_read(tfa9887_byte->regmap, TFA9887_CF_MEM, data, num_bytes);
609 int Tfa9887_WriteRegister(struct tfa9887_priv *tfa9887, unsigned int subaddress, unsigned int value)
611 int error = regmap_write(tfa9887->regmap,subaddress,value);
615 int Tfa9887_ReadRegister(struct tfa9887_priv *tfa9887, unsigned int subaddress, unsigned int* pValue)
617 int error = regmap_read(tfa9887->regmap,subaddress,pValue);
621 void calibrate (struct tfa9887_priv *tfa9887, struct tfa9887_priv *tfa9887_byte, char *calibdata)
626 unsigned int status, value;
627 unsigned char bytes[3];
631 if (!recalibration) {
632 SetMute(tfa9887, Tfa9887_Mute_Digital);
633 pr_info("Inside calib\n");
634 while ((calibrateDone == 0) && (tries < 100)) {
635 error = DspReadMem(tfa9887, tfa9887_byte, 231, 1, &calibrateDone);
642 DspGetParam(tfa9887, tfa9887_byte, MODULE_SPEAKERBOOST, PARAM_GET_RE0, 3, bytes);
643 convertBytes2Data(3, bytes, &data[0]);
645 speaker_data[420] = 0;
646 speaker_data[421] = 0;
647 speaker_data[422] = 0;
648 error = loadSettings(tfa9887, tfa9887_byte);
653 error = Tfa9887_ReadRegister(tfa9887, TFA9887_SYSTEM_CONTROL, &value);
655 if (error == Tfa9887_Error_Ok) {
657 value |= TFA9887_SYSCTRL_CONFIGURED;
658 error = Tfa9887_WriteRegister(tfa9887, TFA9887_SYSTEM_CONTROL, value);
664 error = DspReadMem(tfa9887, tfa9887_byte, 231, 1, &calibrateDone);
665 while ((calibrateDone == 0) && (tries < 100)) {
666 error = DspReadMem(tfa9887, tfa9887_byte, 231, 1, &calibrateDone);
671 pr_info("Calibrate failed1\n");
677 error = Tfa9887_ReadRegister(tfa9887, TFA9887_STATUS, &status);
680 } while ( ((status & TFA9887_STATUS_MTPB) == TFA9887_STATUS_MTPB) && (tries < 100));
682 pr_info("Calibrate failed2\n");
686 while ((calibrateDone == 0) && (tries < 100)) {
687 error = DspReadMem(tfa9887, tfa9887_byte, 231, 1, &calibrateDone);
692 pr_info("Calibrate failed3\n");
694 DspGetParam(tfa9887, tfa9887_byte, MODULE_SPEAKERBOOST, PARAM_GET_RE0, 3, bytes);
695 convertBytes2Data(3, bytes, &data[0]);
696 DspReadMem(tfa9887, tfa9887_byte, 232, 1, &data[1]);
697 pr_info("%d %d\n",data[0], data[1]);
698 memcpy(calibdata, (char *)data, 8);
701 void resetMtpEx(struct tfa9887_priv *tfa9887)
704 unsigned int mtp, status;
706 err = Tfa9887_ReadRegister(tfa9887, TFA9887_MTP, &mtp);
708 pr_info("%d****************mtp",mtp);
709 /* all settings loaded, signal the DSP to start calibration, only needed once after cold boot */
710 /* reset MTPEX bit if needed */
711 err = Tfa9887_WriteRegister(tfa9887, 0x0B, 0x5A); /* unlock key2 */
712 err = Tfa9887_WriteRegister(tfa9887, TFA9887_MTP, 1); /* MTPOTC=1, MTPEX=0 */
714 err = Tfa9887_WriteRegister(tfa9887, 0x62, 1<<11); /* CIMTP=1 */
717 err = Tfa9887_ReadRegister(tfa9887, TFA9887_STATUS, &status);
720 } while ( ((status & TFA9887_STATUS_MTPB) == TFA9887_STATUS_MTPB) && (tries < 100));
724 int checkMTPEX(struct tfa9887_priv *tfa9887)
729 err = Tfa9887_ReadRegister(tfa9887, TFA9887_MTP, &mtp);
730 if ( mtp & (1<<1)) /* check MTP bit1 (MTPEX) */
731 return 1; /* MTPEX is 1, calibration is done */
733 return 0; /* MTPEX is 0, calibration is not done yet */
736 int Tfa9887_Init(int sRate)
741 mutex_lock(&tfa9887R->lock);
742 if (tfa9887R->deviceInit) {
743 coldStartup(tfa9887R, tfa9887R_byte, srate);
744 //Tfa9887_WriteRegister(tfa9887R, 0x0B, 0x5A); /* unlock key2 */
745 //Tfa9887_WriteRegister(tfa9887R, TFA9887_MTP, 0); /* MTPOTC=1, MTPEX=0 */
748 if((checkMTPEX(tfa9887R) == 0)) {
750 calibrate(tfa9887R, tfa9887R_byte, &calibdata[0]);
753 error = Init(tfa9887R,tfa9887R_byte, sRate);
757 mutex_unlock(&tfa9887R->lock);
761 mutex_lock(&tfa9887L->lock);
762 if (tfa9887L->deviceInit) {
763 coldStartup(tfa9887L, tfa9887L_byte, srate);
764 //Tfa9887_WriteRegister(tfa9887L, 0x0B, 0x5A); /* unlock key2 */
765 //Tfa9887_WriteRegister(tfa9887L, TFA9887_MTP, 0); /* MTPOTC=1, MTPEX=0 */
768 if((checkMTPEX(tfa9887L) == 0)) {
770 calibrate(tfa9887L, tfa9887L_byte, &calibdata[8]);
773 error = Init(tfa9887L,tfa9887L_byte, sRate);
777 mutex_unlock(&tfa9887L->lock);
780 pr_info("Failed to Init tfa\n");
784 void setOtc(struct tfa9887_priv *tfa9887, unsigned short otcOn)
793 err = Tfa9887_ReadRegister(tfa9887, TFA9887_MTP, &mtp);
794 /* set reset MTPEX bit if needed */
795 if ( (mtp & TFA9887_MTP_MTPOTC) != otcOn) {
796 /* need to change the OTC bit, set MTPEX=0 in any case */
797 err = Tfa9887_WriteRegister(tfa9887, 0x0B, 0x5A); /* unlock key2 */
799 err = Tfa9887_WriteRegister(tfa9887, TFA9887_MTP, otcOn); /* MTPOTC=otcOn, MTPEX=0 */
801 err = Tfa9887_WriteRegister(tfa9887, 0x62, 1<<11); /* CIMTP=1 */
806 //Sleep(13*16); /* need to wait until all parameters are copied into MTP */
808 err = Tfa9887_ReadRegister(tfa9887, TFA9887_STATUS, &status);
811 } while ( ((status & TFA9887_STATUS_MTPB) == TFA9887_STATUS_MTPB) && (tries < 100));
814 /* ensure the DSP restarts after this to read out the new value */
815 err = Tfa9887_WriteRegister(tfa9887, 0x70, 0x1); /* DSP reset */
820 int Tfa9887_SetEq(void)
825 mutex_lock(&tfa9887R->lock);
826 if (tfa9887R->deviceInit)
827 error = SetEq(tfa9887R, tfa9887R_byte);
828 mutex_unlock(&tfa9887R->lock);
832 mutex_lock(&tfa9887L->lock);
833 if (tfa9887L->deviceInit)
834 error = SetEq(tfa9887L, tfa9887L_byte);
835 mutex_unlock(&tfa9887L->lock);
840 int Tfa9887_SetPreset(unsigned int preset)
843 if (preset != preset_mode) {
844 preset_mode = preset;
847 mutex_lock(&tfa9887R->lock);
848 if (tfa9887R->deviceInit)
849 error = SetPreset(tfa9887R, tfa9887R_byte);
850 mutex_unlock(&tfa9887R->lock);
854 mutex_lock(&tfa9887L->lock);
855 if (tfa9887L->deviceInit)
856 error = SetPreset(tfa9887L, tfa9887L_byte);
857 mutex_unlock(&tfa9887L->lock);
863 int coldStartup(struct tfa9887_priv *tfa9887, struct tfa9887_priv *tfa9887_byte, int sRate)
865 int error,volume_value;
868 error = Tfa9887_WriteRegister(tfa9887, 0x09, 0x0002);
869 if (Tfa9887_Error_Ok == error) {
870 error = Tfa9887_ReadRegister(tfa9887, 0x09, &value);
872 if (Tfa9887_Error_Ok == error) {
873 /* DSP must be in control of the amplifier to avoid plops */
874 value |= TFA9887_SYSCTRL_SEL_ENBL_AMP;
875 error = Tfa9887_WriteRegister(tfa9887, 0x09, value);
878 /* some other registers must be set for optimal amplifier behaviour */
879 if (Tfa9887_Error_Ok == error) {
880 error = Tfa9887_WriteRegister(tfa9887, 0x40, 0x5A6B);
882 if (Tfa9887_Error_Ok == error) {
883 error = Tfa9887_WriteRegister(tfa9887, 0x05, 0x13AB);
885 if (Tfa9887_Error_Ok == error) {
886 error = Tfa9887_WriteRegister(tfa9887, 0x06, 0x001F);
888 if (Tfa9887_Error_Ok == error) {
889 error = Tfa9887_WriteRegister(tfa9887,
890 TFA9887_SPKR_CALIBRATION, 0x3C4E); /* adjusted to mandatory defaults */
892 if (Tfa9887_Error_Ok == error) {
893 error = Tfa9887_WriteRegister(tfa9887, 0x09, 0x025D);
895 if (Tfa9887_Error_Ok == error) {
896 error = Tfa9887_WriteRegister(tfa9887, 0x0A, 0x3EC3);
898 if (Tfa9887_Error_Ok == error) {
899 error = Tfa9887_WriteRegister(tfa9887, 0x41, 0x0308);
901 if (Tfa9887_Error_Ok == error) {
902 error = Tfa9887_WriteRegister(tfa9887, 0x48, 0x0180);
904 if (Tfa9887_Error_Ok == error) {
905 error = Tfa9887_WriteRegister(tfa9887, 0x49, 0x0E82);
907 if (Tfa9887_Error_Ok == error) {
908 error = Tfa9887_WriteRegister(tfa9887, 0x52, 0x0000);
910 if (Tfa9887_Error_Ok == error) {
911 error = Tfa9887_WriteRegister(tfa9887, 0x40, 0x0000);
913 //Set Sampling Frequency
914 error = Tfa9887_ReadRegister(tfa9887, TFA9887_I2S_CONTROL, &value);
915 if (error == Tfa9887_Error_Ok) {
916 // clear the 4 bits first
917 value &= (~(0xF<<TFA9887_I2SCTRL_RATE_SHIFT));
920 value |= TFA9887_I2SCTRL_RATE_48000;
923 value |= TFA9887_I2SCTRL_RATE_44100;
926 value |= TFA9887_I2SCTRL_RATE_32000;
929 value |= TFA9887_I2SCTRL_RATE_24000;
932 value |= TFA9887_I2SCTRL_RATE_22050;
935 value |= TFA9887_I2SCTRL_RATE_16000;
938 value |= TFA9887_I2SCTRL_RATE_12000;
941 value |= TFA9887_I2SCTRL_RATE_11025;
944 value |= TFA9887_I2SCTRL_RATE_08000;
947 pr_info("unsupported samplerate\n");
951 error = Tfa9887_WriteRegister(tfa9887, TFA9887_I2S_CONTROL, value);
953 volume_value = volume_step[PRESET_DEFAULT];
954 error = Tfa9887_ReadRegister(tfa9887, TFA9887_AUDIO_CONTROL, &value);
955 if(error == Tfa9887_Error_Ok) {
956 value = (value&0x00FF) | (unsigned int)(volume_value<<8);
957 error = Tfa9887_WriteRegister(tfa9887, TFA9887_AUDIO_CONTROL, value);
960 error = Tfa9887_ReadRegister(tfa9887, TFA9887_SYSTEM_CONTROL, &value);
961 if(error == Tfa9887_Error_Ok) {
962 value &= ~(TFA9887_SYSCTRL_POWERDOWN);
963 error = Tfa9887_WriteRegister(tfa9887, TFA9887_SYSTEM_CONTROL, value);
966 //Waiting for IC to startup
967 error = Tfa9887_ReadRegister(tfa9887, TFA9887_STATUS, &value);
969 error = Tfa9887_ReadRegister(tfa9887, TFA9887_STATUS, &value);
972 } while ((error == Tfa9887_Error_Ok) && ((value & TFA9887_STATUS_PLLS) == 0) && (tries < 100));
975 error = ProcessPatchFile(tfa9887, tfa9887_byte, 10, coldpatch_data);
976 error = Tfa9887_ReadRegister(tfa9887, TFA9887_STATUS, &value);
977 if(value & TFA9887_STATUS_ACS)
978 //pr_info("TFA COLD BOOTED\n");
979 error = ProcessPatchFile(tfa9887, tfa9887_byte, sizeof(n1d2_data), n1d2_data);
984 int Init(struct tfa9887_priv *tfa9887,struct tfa9887_priv *tfa9887_byte, int sRate)
989 error = loadSettings(tfa9887, tfa9887_byte);
990 if(error != Tfa9887_Error_Ok) {
991 pr_info("Loading Settings Failed\n");
994 error = stereoRouting(tfa9887);
996 if(error != Tfa9887_Error_Ok) {
997 pr_info("Stereo routing Failed\n");
1001 error = Tfa9887_ReadRegister(tfa9887, TFA9887_SYSTEM_CONTROL, &value);
1002 if(error == Tfa9887_Error_Ok)
1004 value |= TFA9887_SYSCTRL_CONFIGURED;
1005 error = Tfa9887_WriteRegister(tfa9887, TFA9887_SYSTEM_CONTROL, value);
1008 SetMute(tfa9887, Tfa9887_Mute_Amplifier);
1010 if(error == Tfa9887_Error_Ok)
1012 error = Tfa9887_ReadRegister(tfa9887, TFA9887_SYSTEM_CONTROL, &value);
1013 value |= TFA9887_SYSCTRL_POWERDOWN;
1014 error = Tfa9887_WriteRegister(tfa9887, TFA9887_SYSTEM_CONTROL, value);
1021 int SetEq(struct tfa9887_priv *tfa9887,struct tfa9887_priv *tfa9887_byte)
1024 if (eq_mode == IN_HAND_MODE) {
1025 //pr_info("Setting hand mode\n");
1026 error = DspSetParam(tfa9887,tfa9887_byte, MODULE_BIQUADFILTERBANK,0, 180, eq_data_hand);
1027 } else if (eq_mode == ON_DESK_MODE) {
1028 //pr_info("setting deskmode\n");
1029 error = DspSetParam(tfa9887,tfa9887_byte, MODULE_BIQUADFILTERBANK,0, 180, eq_data_table);
1034 int SetPreset(struct tfa9887_priv *tfa9887,struct tfa9887_priv *tfa9887_byte)
1037 unsigned int value = 0;
1038 unsigned int volume_value = 0;
1040 switch(preset_mode) {
1042 error = DspSetParam(tfa9887,tfa9887_byte, MODULE_SPEAKERBOOST, PARAM_SET_PRESET, 87, preset_data0);
1045 error = DspSetParam(tfa9887,tfa9887_byte, MODULE_SPEAKERBOOST, PARAM_SET_PRESET, 87, preset_data1);
1048 error = DspSetParam(tfa9887,tfa9887_byte, MODULE_SPEAKERBOOST, PARAM_SET_PRESET, 87, preset_data2);
1051 error = DspSetParam(tfa9887,tfa9887_byte, MODULE_SPEAKERBOOST, PARAM_SET_PRESET, 87, preset_data3);
1054 error = DspSetParam(tfa9887,tfa9887_byte, MODULE_SPEAKERBOOST, PARAM_SET_PRESET, 87, preset_data4);
1059 volume_value = volume_step[preset_mode];
1060 //volume_value = volume_step[PRESET_DEFAULT];
1061 //pr_info("%u %u\n",preset_mode,volume_value);
1062 error = Tfa9887_ReadRegister(tfa9887, TFA9887_AUDIO_CONTROL, &value);
1063 if(error == Tfa9887_Error_Ok) {
1064 value = (value&0x00FF) | (unsigned int)(volume_value<<8);
1065 error = Tfa9887_WriteRegister(tfa9887, TFA9887_AUDIO_CONTROL, value);
1070 int loadSettings(struct tfa9887_priv *tfa9887,struct tfa9887_priv *tfa9887_byte)
1074 error = DspSetParam(tfa9887,tfa9887_byte,MODULE_SPEAKERBOOST, PARAM_SET_LSMODEL, 423, speaker_data);
1075 error = DspSetParam(tfa9887,tfa9887_byte, MODULE_SPEAKERBOOST, PARAM_SET_CONFIG, 165, config_data);
1076 SetPreset(tfa9887,tfa9887_byte);
1077 SetEq(tfa9887,tfa9887_byte);
1081 int stereoRouting(struct tfa9887_priv *tfa9887)
1085 if(tfa9887 == tfa9887L) {
1087 error = Tfa9887_ReadRegister(tfa9887, TFA9887_I2S_CONTROL, &value);
1088 // clear the 2 bits first
1089 value &= ~(0x3<<TFA9887_I2SCTRL_CHANSEL_SHIFT);
1091 value |=(1<<TFA9887_I2SCTRL_CHANSEL_SHIFT);
1092 error = Tfa9887_WriteRegister(tfa9887, TFA9887_I2S_CONTROL, value);
1094 //select ouput left for gain
1095 error = Tfa9887_ReadRegister(tfa9887, TFA9887_I2S_SEL, &value);
1096 value &= ~(0x7<<TFA9887_I2SSEL_I2SOUT_LEFT_SHIFT);
1097 value |=(1<<TFA9887_I2SSEL_I2SOUT_LEFT_SHIFT);
1098 error = Tfa9887_WriteRegister(tfa9887, TFA9887_I2S_SEL, value);
1099 //Select stereo gain
1100 error = Tfa9887_ReadRegister(tfa9887, TFA9887_I2S_CONTROL, &value);
1101 value &= ~(0x1<<TFA9887_I2SCTRL_DATAI2_SHIFT);
1102 value |=(1<<TFA9887_I2SCTRL_DATAI2_SHIFT);
1103 error = Tfa9887_WriteRegister(tfa9887, TFA9887_I2S_CONTROL, value);
1105 //select output right for current sense
1106 error = Tfa9887_ReadRegister(tfa9887, TFA9887_I2S_SEL, &value);
1107 value &= ~(0x7<<TFA9887_I2SSEL_I2SOUT_RIGHT_SHIFT);
1108 value |=(0<<TFA9887_I2SSEL_I2SOUT_RIGHT_SHIFT);
1109 error = Tfa9887_WriteRegister(tfa9887, TFA9887_I2S_SEL, value);
1110 error = Tfa9887_WriteRegister(tfa9887, TFA9887_I2S_SEL, value);
1111 //pr_info("Tfa inside left\n");
1114 else if (tfa9887 == tfa9887R) {
1115 // clear the 2 bits first
1116 error = Tfa9887_ReadRegister(tfa9887, TFA9887_I2S_CONTROL, &value);
1117 value &= ~(0x3<<TFA9887_I2SCTRL_CHANSEL_SHIFT);
1119 value |=(2<<TFA9887_I2SCTRL_CHANSEL_SHIFT);
1120 error = Tfa9887_WriteRegister(tfa9887, TFA9887_I2S_CONTROL, value);
1122 error = Tfa9887_ReadRegister(tfa9887, TFA9887_I2S_SEL, &value);
1123 value &= ~(0x7<<TFA9887_I2SSEL_I2SOUT_RIGHT_SHIFT);
1124 value |=(1<<TFA9887_I2SSEL_I2SOUT_RIGHT_SHIFT);
1125 error = Tfa9887_WriteRegister(tfa9887, TFA9887_I2S_SEL, value);
1127 error = Tfa9887_ReadRegister(tfa9887, TFA9887_I2S_CONTROL, &value);
1128 value &= ~(0x1<<TFA9887_I2SCTRL_DATAI2_SHIFT);
1129 value |=(0<<TFA9887_I2SCTRL_DATAI2_SHIFT);
1130 error = Tfa9887_WriteRegister(tfa9887, TFA9887_I2S_CONTROL, value);
1132 error = Tfa9887_ReadRegister(tfa9887, TFA9887_I2S_SEL, &value);
1133 value &= ~(0x7<<TFA9887_I2SSEL_I2SOUT_LEFT_SHIFT);
1134 value |=(0<<TFA9887_I2SSEL_I2SOUT_LEFT_SHIFT);
1135 error = Tfa9887_WriteRegister(tfa9887, TFA9887_I2S_SEL, value);
1136 //pr_info("tfa inside right\n");
1146 int Tfa9887_Powerdown(int powerdown)
1150 powerDown = powerdown;
1153 mutex_lock(&tfa9887R->lock);
1154 if (tfa9887R->deviceInit)
1155 error = Powerdown(tfa9887R, tfa9887R_byte, powerdown);
1156 mutex_unlock(&tfa9887R->lock);
1160 mutex_lock(&tfa9887L->lock);
1161 if (tfa9887L->deviceInit)
1162 error = Powerdown(tfa9887L, tfa9887L_byte, powerdown);
1163 mutex_unlock(&tfa9887L->lock);
1168 EXPORT_SYMBOL(Tfa9887_Powerdown);
1170 int Powerdown(struct tfa9887_priv *tfa9887, struct tfa9887_priv *tfa9887_byte, int powerdown)
1175 /* read the SystemControl register, modify the bit and write again */
1176 error = Tfa9887_ReadRegister(tfa9887, TFA9887_SYSTEM_CONTROL, &value);
1177 if (error != Tfa9887_Error_Ok) {
1183 value |= TFA9887_SYSCTRL_POWERDOWN;
1184 SetMute(tfa9887,Tfa9887_Mute_Amplifier);
1187 value &= ~(TFA9887_SYSCTRL_POWERDOWN);
1192 error = Tfa9887_WriteRegister(tfa9887, TFA9887_SYSTEM_CONTROL, value);
1194 SetMute(tfa9887,Tfa9887_Mute_Off);
1195 SetPreset(tfa9887,tfa9887_byte);
1196 SetEq(tfa9887,tfa9887_byte);
1202 int SetMute(struct tfa9887_priv *tfa9887, Tfa9887_Mute_t mute)
1205 unsigned int audioctrl_value;
1206 unsigned int sysctrl_value;
1208 Tfa9887_ReadRegister(tfa9887, TFA9887_AUDIO_CONTROL,
1210 if (error != Tfa9887_Error_Ok)
1213 Tfa9887_ReadRegister(tfa9887, TFA9887_SYSTEM_CONTROL,
1215 if (error != Tfa9887_Error_Ok)
1218 case Tfa9887_Mute_Off:
1219 /* previous state can be digital or amplifier mute,
1220 * clear the cf_mute and set the enbl_amplifier bits
1222 audioctrl_value &= ~(TFA9887_AUDIOCTRL_MUTE);
1223 sysctrl_value |= TFA9887_SYSCTRL_ENBL_AMP;
1225 case Tfa9887_Mute_Digital:
1226 /* expect the amplifier to run */
1227 /* set the cf_mute bit */
1228 audioctrl_value |= TFA9887_AUDIOCTRL_MUTE;
1229 /* set the enbl_amplifier bit */
1230 sysctrl_value |= TFA9887_SYSCTRL_ENBL_AMP;
1232 case Tfa9887_Mute_Amplifier:
1233 /* clear the cf_mute bit */
1234 audioctrl_value &= ~TFA9887_AUDIOCTRL_MUTE;
1235 /* clear the enbl_amplifier bit */
1236 sysctrl_value &= ~TFA9887_SYSCTRL_ENBL_AMP;
1241 if (error != Tfa9887_Error_Ok)
1244 Tfa9887_WriteRegister(tfa9887, TFA9887_AUDIO_CONTROL,
1246 if (error != Tfa9887_Error_Ok)
1249 Tfa9887_WriteRegister(tfa9887, TFA9887_SYSTEM_CONTROL,
1253 bool tfa9887_readable_register(struct device *dev, unsigned int reg)
1258 bool tfa9887_volatile_register(struct device *dev, unsigned int reg)
1263 static const struct regmap_config tfa9887_regmap = {
1266 .volatile_reg = tfa9887_volatile_register,
1267 .readable_reg = tfa9887_readable_register,
1268 .cache_type = REGCACHE_NONE,
1271 static const struct regmap_config tfa9887_regmap_byte = {
1274 .volatile_reg = tfa9887_volatile_register,
1275 .readable_reg = tfa9887_readable_register,
1276 .cache_type = REGCACHE_NONE,
1278 static ssize_t tfa9887_cal_show(struct kobject *kobj,
1279 struct kobj_attribute *attr, char *buf)
1281 //printk("!tfa9887_cal_show\n");
1283 memcpy(buf, calibdata, 16);
1285 //pr_info("copying data\n");
1291 static ssize_t tfa9887_cal_store(struct kobject *kobj,
1292 struct kobj_attribute *attr, const char *buf, size_t count)
1294 ssize_t ret = count;
1295 //printk("+tfa9887_cal_store: %p, %d\n", buf, count);
1297 if (!buf || !count) {
1304 tegra_asoc_enable_clocks();
1305 memcpy(&speaker_data[420],buf,3);
1306 recalibrate(tfa9887R, tfa9887R_byte);
1307 memcpy(&speaker_data[420],buf+3,3);
1308 recalibrate(tfa9887L, tfa9887L_byte);
1311 tegra_asoc_disable_clocks();
1315 //printk("-tfa9887_cal_store: %d\n", count);
1319 void recalibrate(struct tfa9887_priv *tfa9887, struct tfa9887_priv *tfa9887_byte) {
1323 mutex_lock(&tfa9887->lock);
1324 if (tfa9887->deviceInit) {
1325 resetMtpEx(tfa9887);
1326 SetMute(tfa9887, Tfa9887_Mute_Amplifier);
1327 coldStartup(tfa9887, tfa9887_byte, srate);
1328 Init(tfa9887,tfa9887_byte, srate);
1329 calibrate(tfa9887, tfa9887_byte, &calibdata[0]);
1330 Tfa9887_ReadRegister(tfa9887, TFA9887_SYSTEM_CONTROL, &value);
1331 value |= TFA9887_SYSCTRL_POWERDOWN;
1332 Tfa9887_WriteRegister(tfa9887, TFA9887_SYSTEM_CONTROL, value);
1334 mutex_unlock(&tfa9887->lock);
1338 static ssize_t tfa9887_config_show(struct kobject *kobj,
1339 struct kobj_attribute *attr, char *buf)
1341 //printk("!tfa9887_config_show\n");
1346 else if (eq_mode == 2)
1351 printk("%c\n",*buf);
1355 static ssize_t tfa9887_config_store(struct kobject *kobj,
1356 struct kobj_attribute *attr, const char *buf, size_t count)
1358 ssize_t ret = count;
1360 //printk("+tfa9887_config_store: %p, %d\n", buf, count);
1362 if (!buf || !count) {
1367 pr_info("IN HAND MODE\n");
1370 else if (*buf == '1'){
1371 pr_info("IN DESK MODE\n");
1376 //printk("-tfa9887_config_store: %d\n", count);
1380 static ssize_t tfa9887_vol_show(struct kobject *kobj,
1381 struct kobj_attribute *attr, char *buf)
1383 printk("!tfa9887_vol_show\n");
1387 static ssize_t tfa9887_vol_store(struct kobject *kobj,
1388 struct kobj_attribute *attr, const char *buf, size_t count)
1390 ssize_t ret = count;
1391 unsigned int preset;
1393 //printk("+tfa9887_vol_store: %d, %d\n", *buf, count);
1395 if (!buf || !count) {
1399 if (*buf >= DB_CUTOFF_INDEX)
1400 preset = MAX_DB_INDEX - *buf;
1402 preset = PRESET_DEFAULT;
1404 Tfa9887_SetPreset(preset);
1406 //printk("-tfa9887_vol_store: %d\n", count);
1410 static __devinit int tfa9887R_i2c_probe(struct i2c_client *i2c,
1411 const struct i2c_device_id *id)
1416 pr_info("tfa9887R_i2c_probe\n");
1417 tfa9887R = devm_kzalloc(&i2c->dev, sizeof(struct tfa9887_priv),
1419 tfa9887R_byte = devm_kzalloc(&i2c->dev, sizeof(struct tfa9887_priv),
1422 if (tfa9887R == NULL)
1424 tfa9887R->regmap = regmap_init_i2c(i2c, &tfa9887_regmap);
1425 tfa9887R_byte->regmap = regmap_init_i2c(i2c, &tfa9887_regmap_byte);
1426 if (IS_ERR(tfa9887R->regmap)) {
1427 ret = PTR_ERR(tfa9887R->regmap);
1428 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
1433 i2c_set_clientdata(i2c, tfa9887R);
1434 i2c_set_clientdata(i2c, tfa9887R_byte);
1435 mutex_init(&tfa9887R->lock);
1436 tfa9887R->irq = i2c->irq;
1437 tfa9887R_byte->irq = i2c->irq;
1438 ret = regmap_read(tfa9887R->regmap, TFA9887_REVISIONNUMBER, &val);
1440 dev_err(&i2c->dev, "Failed to read chip revision: %d\n", ret);
1443 dev_info(&i2c->dev, "TFA9887 revision %d\n",val);
1444 tfa9887_kobj = kobject_create_and_add("tfa9887", kernel_kobj);
1446 ret = sysfs_create_file(tfa9887_kobj, &tfa9887_config);
1447 printk("tfa9887_add_sysfs ret=%d\n", ret);
1449 dev_err(&i2c->dev, "Failed to add sysfs: %d\n", ret);
1452 ret = sysfs_create_file(tfa9887_kobj, &tfa9887_cal);
1453 printk("tfa9887_add_sysfs ret=%d\n", ret);
1455 dev_err(&i2c->dev, "Failed to add sysfs: %d\n", ret);
1458 ret = sysfs_create_file(tfa9887_kobj, &tfa9887_vol);
1459 printk("tfa9887_add_sysfs ret=%d\n", ret);
1461 dev_err(&i2c->dev, "Failed to add sysfs: %d\n", ret);
1465 mutex_lock(&tfa9887R->lock);
1466 tfa9887R->deviceInit = true;
1467 mutex_unlock(&tfa9887R->lock);
1469 eq_mode = IN_HAND_MODE;
1470 preset_mode = PRESET_DEFAULT;
1473 regmap_exit(tfa9887R->regmap);
1477 static __devexit int tfa9887R_i2c_remove(struct i2c_client *client)
1479 struct tfa9887_priv *tfa9887R = i2c_get_clientdata(client);
1480 regmap_exit(tfa9887R->regmap);
1481 sysfs_remove_file(tfa9887_kobj, &tfa9887_config);
1482 sysfs_remove_file(tfa9887_kobj, &tfa9887_cal);
1483 sysfs_remove_file(tfa9887_kobj, &tfa9887_vol);
1484 kobject_del(tfa9887_kobj);
1488 static void tfa9887R_i2c_shutdown(struct i2c_client *i2c)
1491 mutex_lock(&tfa9887R->lock);
1493 disable_irq(i2c->irq);
1494 tfa9887R->deviceInit = false;
1495 mutex_unlock(&tfa9887R->lock);
1499 static const struct of_device_id tfa9887R_of_match[] = {
1500 { .compatible = "nxp,tfa9887R", },
1503 MODULE_DEVICE_TABLE(of, tfa9887R_of_match);
1505 static const struct i2c_device_id tfa9887R_i2c_id[] = {
1509 MODULE_DEVICE_TABLE(i2c, tfa9887R_i2c_id);
1511 static struct i2c_driver tfa9887R_i2c_driver = {
1514 .owner = THIS_MODULE,
1515 .of_match_table = tfa9887R_of_match,
1517 .probe = tfa9887R_i2c_probe,
1518 .remove = __devexit_p(tfa9887R_i2c_remove),
1519 .id_table = tfa9887R_i2c_id,
1520 .shutdown = tfa9887R_i2c_shutdown,
1523 static __devinit int tfa9887L_i2c_probe(struct i2c_client *i2c,
1524 const struct i2c_device_id *id)
1529 pr_info("tfa9887L_i2c_probe\n");
1530 tfa9887L = devm_kzalloc(&i2c->dev, sizeof(struct tfa9887_priv),
1532 tfa9887L_byte = devm_kzalloc(&i2c->dev, sizeof(struct tfa9887_priv),
1535 if (tfa9887L == NULL)
1537 tfa9887L->regmap = regmap_init_i2c(i2c, &tfa9887_regmap);
1538 tfa9887L_byte->regmap = regmap_init_i2c(i2c, &tfa9887_regmap_byte);
1539 if (IS_ERR(tfa9887L->regmap)) {
1540 ret = PTR_ERR(tfa9887L->regmap);
1541 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
1546 i2c_set_clientdata(i2c, tfa9887L);
1547 mutex_init(&tfa9887L->lock);
1548 tfa9887L->irq = i2c->irq;
1549 ret = regmap_read(tfa9887L->regmap, TFA9887_REVISIONNUMBER, &val);
1551 dev_err(&i2c->dev, "Failed to read chip revision: %d\n", ret);
1554 dev_info(&i2c->dev, "TFA9887 revision %d\n",val);
1556 mutex_lock(&tfa9887L->lock);
1557 tfa9887L->deviceInit = true;
1558 mutex_unlock(&tfa9887L->lock);
1562 regmap_exit(tfa9887L->regmap);
1566 static __devexit int tfa9887L_i2c_remove(struct i2c_client *client)
1568 struct tfa9887_priv *tfa9887L = i2c_get_clientdata(client);
1569 regmap_exit(tfa9887L->regmap);
1573 static void tfa9887L_i2c_shutdown(struct i2c_client *i2c)
1576 mutex_lock(&tfa9887L->lock);
1578 disable_irq(i2c->irq);
1579 tfa9887L->deviceInit = false;
1580 mutex_unlock(&tfa9887L->lock);
1584 static const struct of_device_id tfa9887L_of_match[] = {
1585 { .compatible = "nxp,tfa9887L", },
1588 MODULE_DEVICE_TABLE(of, tfa9887L_of_match);
1590 static const struct i2c_device_id tfa9887L_i2c_id[] = {
1594 MODULE_DEVICE_TABLE(i2c, tfa9887L_i2c_id);
1596 static struct i2c_driver tfa9887L_i2c_driver = {
1599 .owner = THIS_MODULE,
1600 .of_match_table = tfa9887L_of_match,
1602 .probe = tfa9887L_i2c_probe,
1603 .remove = __devexit_p(tfa9887L_i2c_remove),
1604 .id_table = tfa9887L_i2c_id,
1605 .shutdown = tfa9887L_i2c_shutdown,
1608 static int __init tfa9887_modinit(void)
1611 ret = i2c_add_driver(&tfa9887R_i2c_driver);
1613 printk(KERN_ERR "Failed to register tfa9887 I2C driver: %d\n",
1616 ret = i2c_add_driver(&tfa9887L_i2c_driver);
1618 printk(KERN_ERR "Failed to register tfa9887 I2C driver: %d\n",
1623 module_init(tfa9887_modinit);
1625 static void __exit tfa9887_exit(void)
1627 i2c_del_driver(&tfa9887R_i2c_driver);
1628 i2c_del_driver(&tfa9887L_i2c_driver);
1630 module_exit(tfa9887_exit);