Project

General

Profile

AKM8976A » History » Version 10

Paul Kocialkowski, 07/03/2011 11:21 AM

1 1 Paul Kocialkowski
=  AKM8976A =
2
3
The goal here is to add support for AKM8976A to akmd-free (a free rewrite of akmd, the daemon that deals with the accelerometer/magnetometer data for a few chips, including AKM ones). 
4
This page is to coordinate the work around this goal.
5
6
== Current status ==
7
8 2 Paul Kocialkowski
=== Global tasks achievement ===
9 1 Paul Kocialkowski
10 2 Paul Kocialkowski
|| Task || Achievement ||
11
|| Modifying the kernel driver to print the requests akmd makes (ioctl, etc) || [[span(Done , style=background: green; color: white; display: inline-block; width: 100%;)]] ||
12
|| Get an idea of how it works (what akmd does after what) || [[span(Done , style=background: green; color: white; display: inline-block; width: 100%;)]] ||
13
|| Define the exact steps that akmd follows || [[span(Done , style=background: green; color: white; display: inline-block; width: 100%;)]] ||
14
|| Implement AKM8976A in akmd-free without any data treatment yet || [[span(Done , style=background: green; color: white; display: inline-block; width: 100%;)]] ||
15
|| Understand how the data is treated (algorithms, etc) || [[span(Work in progress , style=background: orange; color: white; display: inline-block; width: 100%;)]] ||
16
|| Reproduce the data treatment with standard C code || [[span(Work in progress , style=background: orange; color: white; display: inline-block; width: 100%;)]] ||
17 8 Paul Kocialkowski
|| Include the data treatment code in akmd-free || [[span(TODO , style=background: red; color: white; display: inline-block; width: 100%;)]] ||
18
|| Check that everything is OK on different devices || [[span(TODO , style=background: red; color: white; display: inline-block; width: 100%;)]] ||
19 1 Paul Kocialkowski
20 3 Paul Kocialkowski
=== Specific tasks achievement ===
21
22 5 Paul Kocialkowski
==== Initialization/calibration sequence ====
23 3 Paul Kocialkowski
24
|| Task || Global achievement || Understood || Reproduced || Implemented ||
25 8 Paul Kocialkowski
|| Before the first ECS_IOCTL_GETDATA || [[span(Mostly done , style=background: orange; color: white; display: inline-block; width: 100%;)]] || [[span(Done , style=background: green; color: white; display: inline-block; width: 100%;)]] || [[span(Done , style=background: green; color: white; display: inline-block; width: 100%;)]] || [[span(TODO , style=background: red; color: white; display: inline-block; width: 100%;)]]
26 1 Paul Kocialkowski
27
== Getting started ==
28
29 5 Paul Kocialkowski
Note that before everything, coming on our IRC channel [https://www.jappix.com/?r=replicant%25irc.freenode.net@irc.jappix.com #replicant on irc.freenode.net] and introducing yourself is essential: you'll be able to get help there and, of course, if you want to join the effort, communication is fundamental. 
30
31
If you plan to join the effort to achieve this goal, here are the steps: 
32
33 6 Paul Kocialkowski
 * Downloading and setting up the akm8976a-dev branch for kernel-msm (which contains a modified version of ''drivers/misc/akm8976.c'')
34
 * Downloading some scripts that are useful to debug fast
35
 * Download and build the re_set_data tool (to inject some data to the kernel)
36 7 Paul Kocialkowski
 * Generate the file containing the "phone" button pressed sequence. 
37
 * Get the non-free akmd. 
38 5 Paul Kocialkowski
39
== Using the scripts/tools ==
40 1 Paul Kocialkowski
41
First of all, you need to know that the kernel-side driver that is used for AKM8976A is located at ''drivers/misc/akm8976.c''.
42
This file has been modified in order to:
43 6 Paul Kocialkowski
 * make it trace (print) all the ioctl
44
 * make it possible to inject data 
45
46
Note that before you run any of the scripts, you need to start adb server as root:
47
{{{ # adb start-server }}}
48
49 1 Paul Kocialkowski
Here is a list of the scripts, what they do and how to use them:
50
 * '''replicant_kern_debug.sh''': this one is to get the debug messages from the kernel. It requires no special parameter, nor any specific location to be lunched in. 
51
 * '''replicant_calib_kern.sh''': this script should be used while working on the calibration part. The 2 remaining initialisation sequences we miss start with { 4, 235 } and { 4, 241 } and this script is to print the calibration values for these sequences (when the kernel printk the values, so when akmd sends them). To use it, pass 235 or 241 as first argument to the script, for the first or 2nd initialisation sequence we miss. 
52 8 Paul Kocialkowski
 * '''replicant_calib_adb.sh''': this script should be used while working on the calibration part. This script has to be ran in the directory containing ''akmd_set_dev.txt'' and ''re_set_data.txt''. You can also pass the directory containing these files as first argument to the script. In the correct order, this script: 
53
  * copies the ''akmd_set_dev.txt'' file to ''/data/misc/akmd_set.txt'' (akmd calibration file)
54
  * copies the ''re_set_data.txt'' file to ''/data/re_set_data.txt'' (retro engineering file, which contains the values to force as ECS_IOCTL_GETDATA returning values)
55
  * lunches ''/data/re_set_data load'' to inject the values from ''/data/re_set_data.txt'' to the kernel
56
  * lunches ''akmd'', which won't do anything if the phone is in sleep mode (black screen).
57
  * inject ''/data/suspend_wake'' to ''/dev/input/event4'' (the buttons event node) to wakeup the phone
58
  * wait for akmd to perform the initialisation sequence, that you should see with '''replicant_calib_kern.sh'''.
59
  * kill akmd
60
  * inject ''/data/suspend_wake'' to ''/dev/input/event4'' (the buttons event node) to put the phone in sleep mode
61
62
You can also avoid the use of the scripts and directly run the needed commands:
63
 * '''adb push akmd_set_dev.txt /data/misc/akmd_set.txt''': this is to copy ''akmd_set_dev.txt'' (akmd calibration file) to its correct location on the device. You need to run that in the directory where ''akmd_set_dev.txt'' is.
64
 * '''adb push re_set_data.txt /data/re_set_data.txt''': this is to copy ''re_set_data.txt'' (retro engineering file, which contains the values to force as ECS_IOCTL_GETDATA returning values)to its correct location on the device. You need to run that in the directory where ''re_set_data.txt'' is.
65 9 Paul Kocialkowski
 * '''adb shell "/data/re_set_data load"''': this is to inject the values from ''/data/re_set_data.txt'' to the kernel driver.
66
 * '''adb shell /data/akmd''': this is to start the non-free akmd daemon.
67
 * '''adb shell "cat /data/suspend_wake  > /dev/input/event4"''': this is to inject the "phone" button pressed event, so it will either wakeup the phone or set it in sleep mode. 
68
 * '''adb shell "killall akmd"''': this is to kill the non-free akmd daemon.
69
 * '''adb shell "echo 8 > /proc/sys/kernel/printk && cat /proc/kmsg"''': this is to set the verbosity level of the kernel messages to high and print the messages.
70 10 Paul Kocialkowski
71
== Conclusions on how it works ==
72
73
To begin with, here is the trace of the requests akmd does to the kernel driver (using the ioctl system call):
74
75
{{{
76
<6>[ 2066.362670] --> ECS_IOCTL_SET_MODE #1
77
78
<6>[ 2066.363220] --> ECS_IOCTL_SET_MODE
79
80
<6>[ 2066.364074]  --> AKECS_MODE_E2P_READ
81
82
<6>[ 2066.381042] --> ECS_IOCTL_READ #1
83
84
<6>[ 2066.381317] what is in rwbuf?
85
86
<6>[ 2066.381744] --------------------
87
88
<6>[ 2066.382019] |	index	|	hdata	|	ddata	|
89
90
<6>[ 2066.382263] |	0	|	0x1	|	1	|
91
92
<6>[ 2066.382507] |	1	|	0x42	|	66	|
93
94
<6>[ 2066.382934] |	2	|	0x0	|	0	|
95
96
<6>[ 2066.383178] |	3	|	0x0	|	0	|
97
98
<6>[ 2066.383392] |	4	|	0x0	|	0	|
99
100
<6>[ 2066.383636] ----------
101
102
<6>[ 2066.384063] --> ECS_IOCTL_READ
103
104
<6>[ 2066.384979] --> ECS_IOCTL_READ #3
105
106
<6>[ 2066.385253] --------------------
107
108
<6>[ 2066.385498] |	index	|	hdata	|	ddata	|
109
110
<6>[ 2066.385925] |	0	|	0x1	|	1	|
111
112
<6>[ 2066.386169] |	1	|	0x66	|	102	|
113
114
<6>[ 2066.386383] |	2	|	0x0	|	0	|
115
116
<6>[ 2066.386627] |	3	|	0x0	|	0	|
117
118
<6>[ 2066.387054] |	4	|	0x0	|	0	|
119
120
<6>[ 2066.387268] ----------
121
122
<6>[ 2066.387542] --> ECS_IOCTL_SET_MODE #1
123
124
<6>[ 2066.387786] --> ECS_IOCTL_SET_MODE
125
126
<6>[ 2066.388214]  --> AKECS_MODE_POWERDOWN
127
128
<6>[ 2066.401031] --> ECS_IOCTL_GET_OPEN_STATUS
129
130
<6>[ 2066.401306] --> ECS_IOCTL_GET_OPEN_STATUS #3
131
132
<6>[ 2066.407135] --> ECS_IOCTL_INIT
133
134
<6>[ 2066.408020] --> ECS_IOCTL_SET_MODE #1
135
136
<6>[ 2066.408294] --> ECS_IOCTL_SET_MODE
137
138
<6>[ 2066.408721]  --> AKECS_MODE_E2P_READ
139
140
<6>[ 2066.421234] --> ECS_IOCTL_READ #1
141
142
<6>[ 2066.421630] what is in rwbuf?
143
144
<6>[ 2066.422302] --------------------
145
146
<6>[ 2066.422637] |	index	|	hdata	|	ddata	|
147
148
<6>[ 2066.423004] |	0	|	0x3	|	3	|
149
150
<6>[ 2066.423339] |	1	|	0x46	|	70	|
151
152
<6>[ 2066.423950] |	2	|	0x0	|	0	|
153
154
<6>[ 2066.424285] |	3	|	0x0	|	0	|
155
156
<6>[ 2066.424621] |	4	|	0x0	|	0	|
157
158
<6>[ 2066.424957] ----------
159
160
<6>[ 2066.425567] --> ECS_IOCTL_READ
161
162
<6>[ 2066.426696] --> ECS_IOCTL_READ #3
163
164
<6>[ 2066.427062] --------------------
165
166
<6>[ 2066.427398] |	index	|	hdata	|	ddata	|
167
168
<6>[ 2066.428039] |	0	|	0x3	|	3	|
169
170
<6>[ 2066.428375] |	1	|	0x97	|	151	|
171
172
<6>[ 2066.428710] |	2	|	0x87	|	135	|
173
174
<6>[ 2066.429321] |	3	|	0x19	|	25	|
175
176
<6>[ 2066.429656] |	4	|	0x0	|	0	|
177
178
<6>[ 2066.429992] ----------
179
180
<6>[ 2066.431243] --> ECS_IOCTL_SET_MODE #1
181
182
<6>[ 2066.431915] --> ECS_IOCTL_SET_MODE
183
184
<6>[ 2066.432250]  --> AKECS_MODE_POWERDOWN
185
186
<6>[ 2066.450866] --> ECS_IOCTL_WRITE #1
187
188
<6>[ 2066.451385] what is in rwbuf?
189
190
<6>[ 2066.452239] --------------------
191
192
<6>[ 2066.452697] |	index	|	hdata	|	ddata	|
193
194
<6>[ 2066.453186] |	0	|	0x4	|	4	|
195
196
<6>[ 2066.454040] |	1	|	0xe8	|	232	|
197
198
<6>[ 2066.454498] |	2	|	0x7	|	7	|
199
200
<6>[ 2066.454956] |	3	|	0x7	|	7	|
201
202
<6>[ 2066.455413] |	4	|	0x9	|	9	|
203
204
<6>[ 2066.456268] ----------
205
206
<6>[ 2066.456726] --> ECS_IOCTL_WRITE
207
208
<6>[ 2066.457916] --> ECS_IOCTL_WRITE #1
209
210
<6>[ 2066.458374] what is in rwbuf?
211
212
<6>[ 2066.459228] --------------------
213
214
<6>[ 2066.459686] |	index	|	hdata	|	ddata	|
215
216
<6>[ 2066.460174] |	0	|	0x4	|	4	|
217
218
<6>[ 2066.460784] |	1	|	0xe5	|	229	|
219
220
<6>[ 2066.461669] |	2	|	0x89	|	137	|
221
222
<6>[ 2066.462127] |	3	|	0x0	|	0	|
223
224
<6>[ 2066.462615] |	4	|	0x89	|	137	|
225
226
<6>[ 2066.463073] ----------
227
228
<6>[ 2066.463928] --> ECS_IOCTL_WRITE
229
230
<6>[ 2066.465698] --> ECS_IOCTL_SET_MODE #1
231
232
<6>[ 2066.466186] --> ECS_IOCTL_SET_MODE
233
234
<6>[ 2066.467071]  --> AKECS_MODE_MEASURE_SNG
235
236
<6>[ 2066.480468] --> ECS_IOCTL_GETDATA
237
238
<6>[ 2066.480987] --> ECS_IOCTL_GETDATA #3
239
240
<6>[ 2066.481445] --------------------
241
242
<6>[ 2066.482299] |	index	|	hdata	|	ddata	|
243
244
<6>[ 2066.482788] gflag1|	0	|	0x70	|	112	|
245
246
<6>[ 2066.483245] gflag1|	1	|	0x7f	|	127	|
247
248
<6>[ 2066.484100] gflag1|	2	|	0xa5	|	165	|
249
250
<6>[ 2066.484588] gflag1|	3	|	0x5c	|	92	|
251
252
<6>[ 2066.485046] gflag1|	4	|	0x66	|	102	|
253
254
<6>[ 2066.485900] gflag1|	5	|	0x85	|	133	|
255
256
<6>[ 2066.486450] gflag1|	6	|	0x5c	|	92	|
257
258
<6>[ 2066.486938] gflag1|	7	|	0x85	|	133	|
259
260
<6>[ 2066.487792] gflag1|	8	|	0x0	|	0	|
261
262
<6>[ 2066.488250] gflag1|	9	|	0x0	|	0	|
263
264
<6>[ 2066.488708] gflag1|	10	|	0x0	|	0	|
265
266
<6>[ 2066.489196] gflag1|	11	|	0x0	|	0	|
267
268
<6>[ 2066.490051] gflag1|	12	|	0x0	|	0	|
269
270
<6>[ 2066.490631] gflag1|	13	|	0x0	|	0	|
271
272
<6>[ 2066.491119] gflag1|	14	|	0x0	|	0	|
273
274
<6>[ 2066.491973] gflag1|	15	|	0x0	|	0	|
275
276
<6>[ 2066.492431] gflag1|	16	|	0x0	|	0	|
277
278
<6>[ 2066.492919] gflag1|	17	|	0xa5	|	165	|
279
280
<6>[ 2066.493774] gflag1|	18	|	0x5c	|	92	|
281
282
<6>[ 2066.494262] gflag1|	19	|	0x66	|	102	|
283
284
<6>[ 2066.494720] gflag1|	20	|	0x85	|	133	|
285
286
<6>[ 2066.495574] gflag1|	21	|	0x5c	|	92	|
287
288
<6>[ 2066.496032] gflag1|	22	|	0x85	|	133	|
289
290
<6>[ 2066.496520] gflag1|	23	|	0x0	|	0	|
291
292
<6>[ 2066.496978] gflag1|	24	|	0x0	|	0	|
293
294
<6>[ 2066.497833] gflag1|	25	|	0x0	|	0	|
295
296
<6>[ 2066.498291] gflag1|	26	|	0x0	|	0	|
297
298
<6>[ 2066.498779] gflag1|	27	|	0x0	|	0	|
299
300
<6>[ 2066.499633] gflag1|	28	|	0x0	|	0	|
301
302
<6>[ 2066.500122] gflag1|	29	|	0x0	|	0	|
303
304
<6>[ 2066.500671] gflag1|	30	|	0x0	|	0	|
305
306
<6>[ 2066.501525] gflag1|	31	|	0x0	|	0	|
307
308
<6>[ 2066.501983] ----------
309
310
<6>[ 2066.509826] --> ECS_IOCTL_GET_NUMFRQ
311
312
<6>[ 2066.510559] --> ECS_IOCTL_GET_NUMFRQ #3
313
314
<6>[ 2066.511444] --------------------
315
316
<6>[ 2066.511901] |	index	|	hdata	|	ddata	|
317
318
<6>[ 2066.512390] |	0	|	0x1	|	1	|
319
320
<6>[ 2066.513244] |	1	|	0x0	|	0	|
321
322
<6>[ 2066.513702] ----------
323
324
<6>[ 2066.515655] --> ECS_IOCTL_WRITE #1
325
326
<6>[ 2066.516174] what is in rwbuf?
327
328
<6>[ 2066.517120] --------------------
329
330
<6>[ 2066.517578] |	index	|	hdata	|	ddata	|
331
332
<6>[ 2066.518066] |	0	|	0x4	|	4	|
333
334
<6>[ 2066.518524] |	1	|	0xee	|	238	|
335
336
<6>[ 2066.519378] |	2	|	0x10	|	16	|
337
338
<6>[ 2066.519836] |	3	|	0x10	|	16	|
339
340
<6>[ 2066.520324] |	4	|	0x10	|	16	|
341
342
<6>[ 2066.520904] ----------
343
344
<6>[ 2066.521789] --> ECS_IOCTL_WRITE
345
346
<6>[ 2066.524230] --> ECS_IOCTL_WRITE #1
347
348
<6>[ 2066.524749] what is in rwbuf?
349
350
<6>[ 2066.525299] --------------------
351
352
<6>[ 2066.526153] |	index	|	hdata	|	ddata	|
353
354
<6>[ 2066.526641] |	0	|	0x4	|	4	|
355
356
<6>[ 2066.527099] |	1	|	0xeb	|	235	|
357
358
<6>[ 2066.527954] |	2	|	0x3	|	3	|
359
360
<6>[ 2066.528411] |	3	|	0x7	|	7	|
361
362
<6>[ 2066.528869] |	4	|	0x8a	|	138	|
363
364
<6>[ 2066.529357] ----------
365
366
<6>[ 2066.529815] --> ECS_IOCTL_WRITE
367
368
<6>[ 2066.532836] --> ECS_IOCTL_WRITE #1
369
370
<6>[ 2066.533355] what is in rwbuf?
371
372
<6>[ 2066.533874] --------------------
373
374
<6>[ 2066.534729] |	index	|	hdata	|	ddata	|
375
376
<6>[ 2066.535186] |	0	|	0x2	|	2	|
377
378
<6>[ 2066.535675] |	1	|	0xf4	|	244	|
379
380
<6>[ 2066.536132] |	2	|	0x55	|	85	|
381
382
<6>[ 2066.537017] |	3	|	0x0	|	0	|
383
384
<6>[ 2066.537475] |	4	|	0x0	|	0	|
385
386
<6>[ 2066.537933] ----------
387
388
<6>[ 2066.538391] --> ECS_IOCTL_WRITE
389
390
<6>[ 2066.539947] --> ECS_IOCTL_WRITE #1
391
392
<6>[ 2066.540618] what is in rwbuf?
393
394
<6>[ 2066.541107] --------------------
395
396
<6>[ 2066.541534] |	index	|	hdata	|	ddata	|
397
398
<6>[ 2066.542388] |	0	|	0x2	|	2	|
399
400
<6>[ 2066.542877] |	1	|	0xf5	|	245	|
401
402
<6>[ 2066.543334] |	2	|	0x1b	|	27	|
403
404
<6>[ 2066.544219] |	3	|	0x0	|	0	|
405
406
<6>[ 2066.544677] |	4	|	0x0	|	0	|
407
408
<6>[ 2066.545135] ----------
409
410
<6>[ 2066.545623] --> ECS_IOCTL_WRITE
411
412
<6>[ 2066.548126] --> ECS_IOCTL_WRITE #1
413
414
<6>[ 2066.548370] what is in rwbuf?
415
416
<6>[ 2066.548614] --------------------
417
418
<6>[ 2066.548858] |	index	|	hdata	|	ddata	|
419
420
<6>[ 2066.549285] |	0	|	0x2	|	2	|
421
422
<6>[ 2066.549530] |	1	|	0xf6	|	246	|
423
424
<6>[ 2066.549743] |	2	|	0x8	|	8	|
425
426
<6>[ 2066.549987] |	3	|	0x0	|	0	|
427
428
<6>[ 2066.550537] |	4	|	0x0	|	0	|
429
430
<6>[ 2066.550781] ----------
431
432
<6>[ 2066.551025] --> ECS_IOCTL_WRITE
433
434
<6>[ 2066.552398] --> ECS_IOCTL_WRITE #1
435
436
<6>[ 2066.552856] what is in rwbuf?
437
438
<6>[ 2066.553131] --------------------
439
440
<6>[ 2066.553375] |	index	|	hdata	|	ddata	|
441
442
<6>[ 2066.553802] |	0	|	0x4	|	4	|
443
444
<6>[ 2066.554046] |	1	|	0xf1	|	241	|
445
446
<6>[ 2066.554260] |	2	|	0x84	|	132	|
447
448
<6>[ 2066.554504] |	3	|	0x87	|	135	|
449
450
<6>[ 2066.554931] |	4	|	0x83	|	131	|
451
452
<6>[ 2066.555145] ----------
453
454
<6>[ 2066.555389] --> ECS_IOCTL_WRITE
455
456
<6>[ 2066.557525] --> ECS_IOCTL_GET_CLOSE_STATUS
457
458
<6>[ 2066.558074] --> ECS_IOCTL_GET_DELAY
459
460
<6>[ 2066.558319] --> ECS_IOCTL_GET_DELAY #3
461
462
<6>[ 2066.761016] --> ECS_IOCTL_SET_MODE #1
463
464
<6>[ 2066.761932] --> ECS_IOCTL_SET_MODE
465
466
<6>[ 2066.762420]  --> AKECS_MODE_MEASURE_SNG
467
468
<6>[ 2066.781555] --> ECS_IOCTL_GETDATA
469
470
<6>[ 2066.782531] --> ECS_IOCTL_GETDATA #3
471
472
<6>[ 2066.783020] --------------------
473
474
<6>[ 2066.783477] |	index	|	hdata	|	ddata	|
475
476
<6>[ 2066.783935] gflag1|	0	|	0x70	|	112	|
477
478
<6>[ 2066.784820] gflag1|	1	|	0x7f	|	127	|
479
480
<6>[ 2066.785278] gflag1|	2	|	0xa3	|	163	|
481
482
<6>[ 2066.785766] gflag1|	3	|	0x5d	|	93	|
483
484
<6>[ 2066.786621] gflag1|	4	|	0x68	|	104	|
485
486
<6>[ 2066.787078] gflag1|	5	|	0x86	|	134	|
487
488
<6>[ 2066.787567] gflag1|	6	|	0x5c	|	92	|
489
490
<6>[ 2066.788421] gflag1|	7	|	0x85	|	133	|
491
492
<6>[ 2066.788879] gflag1|	8	|	0x0	|	0	|
493
494
<6>[ 2066.789367] gflag1|	9	|	0x0	|	0	|
495
496
<6>[ 2066.790222] gflag1|	10	|	0x0	|	0	|
497
498
<6>[ 2066.790832] gflag1|	11	|	0x0	|	0	|
499
500
<6>[ 2066.791320] gflag1|	12	|	0x0	|	0	|
501
502
<6>[ 2066.791778] gflag1|	13	|	0x0	|	0	|
503
504
<6>[ 2066.792663] gflag1|	14	|	0x0	|	0	|
505
506
<6>[ 2066.793121] gflag1|	15	|	0x0	|	0	|
507
508
<6>[ 2066.793579] gflag1|	16	|	0x0	|	0	|
509
510
<6>[ 2066.794464] gflag1|	17	|	0xa3	|	163	|
511
512
<6>[ 2066.794921] gflag1|	18	|	0x5d	|	93	|
513
514
<6>[ 2066.795379] gflag1|	19	|	0x68	|	104	|
515
516
<6>[ 2066.796264] gflag1|	20	|	0x86	|	134	|
517
518
<6>[ 2066.796722] gflag1|	21	|	0x5c	|	92	|
519
520
<6>[ 2066.797210] gflag1|	22	|	0x85	|	133	|
521
522
<6>[ 2066.798065] gflag1|	23	|	0x0	|	0	|
523
524
<6>[ 2066.798553] gflag1|	24	|	0x0	|	0	|
525
526
<6>[ 2066.799041] gflag1|	25	|	0x0	|	0	|
527
528
<6>[ 2066.799499] gflag1|	26	|	0x0	|	0	|
529
530
<6>[ 2066.800354] gflag1|	27	|	0x0	|	0	|
531
532
<6>[ 2066.800903] gflag1|	28	|	0x0	|	0	|
533
534
<6>[ 2066.801391] gflag1|	29	|	0x0	|	0	|
535
536
<6>[ 2066.802246] gflag1|	30	|	0x0	|	0	|
537
538
<6>[ 2066.802703] gflag1|	31	|	0x0	|	0	|
539
540
<6>[ 2066.803161] ----------
541
542
<6>[ 2066.807067] --> ECS_IOCTL_GET_NUMFRQ
543
544
<6>[ 2066.808044] --> ECS_IOCTL_GET_NUMFRQ #3
545
546
<6>[ 2066.808502] --------------------
547
548
<6>[ 2066.808959] |	index	|	hdata	|	ddata	|
549
550
<6>[ 2066.809814] |	0	|	0x1	|	1	|
551
552
<6>[ 2066.810302] |	1	|	0x0	|	0	|
553
554
<6>[ 2066.810943] ----------
555
556
<6>[ 2066.813629] --> ECS_IOCTL_SET_YPR #1
557
558
<6>[ 2066.814636] --------------------
559
560
<6>[ 2066.815093] |	index	|	hdata	|	ddata	|
561
562
<6>[ 2066.815582] gflag2|	0	|	0x55	|	85	|
563
564
<6>[ 2066.816467] gflag2|	1	|	0xffffffff	|	-1	|
565
566
<6>[ 2066.816925] gflag2|	2	|	0x2	|	2	|
567
568
<6>[ 2066.817382] gflag2|	3	|	0x1e	|	30	|
569
570
<6>[ 2066.817840] gflag2|	4	|	0x1	|	1	|
571
572
<6>[ 2066.818328] gflag2|	5	|	0x0	|	0	|
573
574
<6>[ 2066.818786] gflag2|	6	|	0x14	|	20	|
575
576
<6>[ 2066.819244] gflag2|	7	|	0xfffffd3b	|	-709	|
577
578
<6>[ 2066.820129] gflag2|	8	|	0x11	|	17	|
579
580
<6>[ 2066.820770] gflag2|	9	|	0x185	|	389	|
581
582
<6>[ 2066.821258] gflag2|	10	|	0xffffffe7	|	-25	|
583
584
<6>[ 2066.822113] gflag2|	11	|	0xfffffe20	|	-480	|
585
586
<6>[ 2066.822570] ----------
587
588
<6>[ 2066.823028] --> ECS_IOCTL_SET_YPR
589
590
<6>[ 2066.823913] AKECS_Report_Value: yaw = 85, pitch = -1, roll = 2
591
592
<6>[ 2066.824401]                     tmp = 30, m_stat= 1, g_stat=0
593
594
<6>[ 2066.825286]           G_Sensor:   x = 20 LSB, y = -709 LSB, z = 17 LSB
595
596
<6>[ 2066.825744]                MAG:   MAGV_X = 389, MAGV_Y = -25, MAGV_Z = -480
597
598
<6>[ 2066.829833] --> ECS_IOCTL_GET_DELAY
599
600
<6>[ 2066.830352] --> ECS_IOCTL_GET_DELAY #3
601
602
<6>[ 2067.034759] --> ECS_IOCTL_SET_MODE #1
603
604
<6>[ 2067.035705] --> ECS_IOCTL_SET_MODE
605
606
<6>[ 2067.036163]  --> AKECS_MODE_MEASURE_SNG
607
608
<6>[ 2067.051818] --> ECS_IOCTL_GETDATA
609
610
<6>[ 2067.052764] --> ECS_IOCTL_GETDATA #3
611
612
<6>[ 2067.053253] --------------------
613
614
<6>[ 2067.053741] |	index	|	hdata	|	ddata	|
615
616
<6>[ 2067.054595] gflag1|	0	|	0x70	|	112	|
617
618
<6>[ 2067.055084] gflag1|	1	|	0x7f	|	127	|
619
620
<6>[ 2067.055572] gflag1|	2	|	0xa2	|	162	|
621
622
<6>[ 2067.056427] gflag1|	3	|	0x5d	|	93	|
623
624
<6>[ 2067.056915] gflag1|	4	|	0x65	|	101	|
625
626
<6>[ 2067.057373] gflag1|	5	|	0x86	|	134	|
627
628
<6>[ 2067.057861] gflag1|	6	|	0x5b	|	91	|
629
630
<6>[ 2067.058715] gflag1|	7	|	0x85	|	133	|
631
632
<6>[ 2067.059173] gflag1|	8	|	0x0	|	0	|
633
634
<6>[ 2067.059661] gflag1|	9	|	0x0	|	0	|
635
636
<6>[ 2067.060577] gflag1|	10	|	0x0	|	0	|
637
638
<6>[ 2067.061157] gflag1|	11	|	0x0	|	0	|
639
640
<6>[ 2067.061645] gflag1|	12	|	0x0	|	0	|
641
642
<6>[ 2067.062500] gflag1|	13	|	0x0	|	0	|
643
644
<6>[ 2067.062957] gflag1|	14	|	0x0	|	0	|
645
646
<6>[ 2067.063415] gflag1|	15	|	0x0	|	0	|
647
648
<6>[ 2067.063873] gflag1|	16	|	0x0	|	0	|
649
650
<6>[ 2067.064727] gflag1|	17	|	0xa2	|	162	|
651
652
<6>[ 2067.065185] gflag1|	18	|	0x5d	|	93	|
653
654
<6>[ 2067.065673] gflag1|	19	|	0x65	|	101	|
655
656
<6>[ 2067.066528] gflag1|	20	|	0x86	|	134	|
657
658
<6>[ 2067.067016] gflag1|	21	|	0x5b	|	91	|
659
660
<6>[ 2067.067474] gflag1|	22	|	0x85	|	133	|
661
662
<6>[ 2067.068328] gflag1|	23	|	0x0	|	0	|
663
664
<6>[ 2067.068817] gflag1|	24	|	0x0	|	0	|
665
666
<6>[ 2067.069274] gflag1|	25	|	0x0	|	0	|
667
668
<6>[ 2067.070129] gflag1|	26	|	0x0	|	0	|
669
670
<6>[ 2067.070587] gflag1|	27	|	0x0	|	0	|
671
672
<6>[ 2067.071136] gflag1|	28	|	0x0	|	0	|
673
674
<6>[ 2067.071624] gflag1|	29	|	0x0	|	0	|
675
676
<6>[ 2067.072479] gflag1|	30	|	0x0	|	0	|
677
678
<6>[ 2067.072937] gflag1|	31	|	0x0	|	0	|
679
680
<6>[ 2067.073394] ----------
681
682
<6>[ 2067.077880] --> ECS_IOCTL_GET_NUMFRQ
683
684
<6>[ 2067.078399] --> ECS_IOCTL_GET_NUMFRQ #3
685
686
<6>[ 2067.078857] --------------------
687
688
<6>[ 2067.079315] |	index	|	hdata	|	ddata	|
689
690
<6>[ 2067.080169] |	0	|	0x1	|	1	|
691
692
<6>[ 2067.080657] |	1	|	0x0	|	0	|
693
694
<6>[ 2067.081298] ----------
695
696
<6>[ 2067.083892] --> ECS_IOCTL_SET_YPR #1
697
698
<6>[ 2067.084869] --------------------
699
700
<6>[ 2067.085327] |	index	|	hdata	|	ddata	|
701
702
<6>[ 2067.085815] gflag2|	0	|	0x54	|	84	|
703
704
<6>[ 2067.086700] gflag2|	1	|	0xffffffff	|	-1	|
705
706
<6>[ 2067.087158] gflag2|	2	|	0x2	|	2	|
707
708
<6>[ 2067.087615] gflag2|	3	|	0x1e	|	30	|
709
710
<6>[ 2067.088470] gflag2|	4	|	0x1	|	1	|
711
712
<6>[ 2067.088928] gflag2|	5	|	0x0	|	0	|
713
714
<6>[ 2067.089416] gflag2|	6	|	0x14	|	20	|
715
716
<6>[ 2067.090270] gflag2|	7	|	0xfffffd2b	|	-725	|
717
718
<6>[ 2067.090728] gflag2|	8	|	0x11	|	17	|
719
720
<6>[ 2067.091400] gflag2|	9	|	0x175	|	373	|
721
722
<6>[ 2067.092254] gflag2|	10	|	0xffffffe7	|	-25	|
723
724
<6>[ 2067.092742] gflag2|	11	|	0xfffffdef	|	-529	|
725
726
<6>[ 2067.093231] ----------
727
728
<6>[ 2067.093688] --> ECS_IOCTL_SET_YPR
729
730
<6>[ 2067.094543] AKECS_Report_Value: yaw = 84, pitch = -1, roll = 2
731
732
<6>[ 2067.095031]                     tmp = 30, m_stat= 1, g_stat=0
733
734
<6>[ 2067.095916]           G_Sensor:   x = 20 LSB, y = -725 LSB, z = 17 LSB
735
736
<6>[ 2067.096405]                MAG:   MAGV_X = 373, MAGV_Y = -25, MAGV_Z = -529
737
}}}
738
739
740
=== Index of the things to know about the different ioctl commands ===
741
742
 * '''ECS_IOCTL_SET_MODE''': value is a short, must be one of the following values, as defined in akm8976.h:
743
{{{
744
#define AKECS_MODE_MEASURE	0x00	/* Starts measurement. Please use AKECS_MODE_MEASURE_SNG */
745
					/* or AKECS_MODE_MEASURE_SEQ instead of this. */
746
#define AKECS_MODE_PFFD		0x01	/* Start pedometer and free fall detect. */
747
#define AKECS_MODE_E2P_READ	0x02	/* E2P access mode (read). */
748
#define AKECS_MODE_POWERDOWN	0x03	/* Power down mode */
749
750
#define AKECS_MODE_MEASURE_SNG	0x10	/* Starts single measurement */
751
#define AKECS_MODE_MEASURE_SEQ	0x11	/* Starts sequential measurement */
752
}}}
753
 * '''ECS_IOCTL_READ'''/'''ECS_IOCTL_WRITE''': value is a char table (called rwbuf on the kernel driver). rwbuf[0] is the length of the data and the data itself starts at rwbuf[1]. '''ECS_IOCTL_READ''' will give an answer to the request (on the same format) while '''ECS_IOCTL_WRITE''' won't. rwbuf is sent to the chip using I2C from the kernel driver.
754
755
=== Index of the files that are used by akmd or the kernel ===
756
757
 * '''/data/misc/akmd_set.txt''': it's the file containing the calibration values that akmd loads when it starts. If this file does not exist, akmd will re-create from the data it gets doing an ioctl system call to the kernel driver with ECS_IOCTL_GET_CALI_DATA. 
758
759
=== The initialization part ===
760
761
Let's take a look closer at the initialization part: this concerns everything before akmd starts reporting treated values.
762
763
So first of all, we have:
764
765
{{{
766
<6>[ 2066.362670] --> ECS_IOCTL_SET_MODE #1
767
768
<6>[ 2066.363220] --> ECS_IOCTL_SET_MODE
769
770
<6>[ 2066.364074]  --> AKECS_MODE_E2P_READ
771
772
}}}
773
774
akmd sets the driver mode to AKECS_MODE_E2P_READ. It's not clear about why it's really necessary but it's there anyway, and it's quite easy to reproduce since there is no data treatment on that and that it's now clear that this call does not change depending of external values.
775
776
{{{
777
<6>[ 2066.381042] --> ECS_IOCTL_READ #1
778
779
<6>[ 2066.381317] what is in rwbuf?
780
781
<6>[ 2066.381744] --------------------
782
783
<6>[ 2066.382019] |	index	|	hdata	|	ddata	|
784
785
<6>[ 2066.382263] |	0	|	0x1	|	1	|
786
787
<6>[ 2066.382507] |	1	|	0x42	|	66	|
788
789
<6>[ 2066.382934] |	2	|	0x0	|	0	|
790
791
<6>[ 2066.383178] |	3	|	0x0	|	0	|
792
793
<6>[ 2066.383392] |	4	|	0x0	|	0	|
794
795
<6>[ 2066.383636] ----------
796
797
<6>[ 2066.384063] --> ECS_IOCTL_READ
798
799
<6>[ 2066.384979] --> ECS_IOCTL_READ #3
800
801
<6>[ 2066.385253] --------------------
802
803
<6>[ 2066.385498] |	index	|	hdata	|	ddata	|
804
805
<6>[ 2066.385925] |	0	|	0x1	|	1	|
806
807
<6>[ 2066.386169] |	1	|	0x66	|	102	|
808
809
<6>[ 2066.386383] |	2	|	0x0	|	0	|
810
811
<6>[ 2066.386627] |	3	|	0x0	|	0	|
812
813
<6>[ 2066.387054] |	4	|	0x0	|	0	|
814
}}}
815
816
This first part (ECS_IOCTL_READ #1) is the request (READ REQ #1) that akmd sends to the kernel and the second part (ECS_IOCTL_READ #3) is the answer (READ ASW #1) it gets. Its length is 1, so all the 0 values are not to be taken in count. 
817
For this, the request is always { 1, 66 } but the answer may not be the same on different devices. 
818
819
Though, this value seems not to be used used for any of the next requests, but it may still be the case. 
820
821
{{{
822
<6>[ 2066.387542] --> ECS_IOCTL_SET_MODE #1
823
824
<6>[ 2066.387786] --> ECS_IOCTL_SET_MODE
825
826
<6>[ 2066.388214]  --> AKECS_MODE_POWERDOWN
827
828
<6>[ 2066.401031] --> ECS_IOCTL_GET_OPEN_STATUS
829
830
<6>[ 2066.401306] --> ECS_IOCTL_GET_OPEN_STATUS #3
831
832
<6>[ 2066.407135] --> ECS_IOCTL_INIT
833
834
<6>[ 2066.408020] --> ECS_IOCTL_SET_MODE #1
835
836
<6>[ 2066.408294] --> ECS_IOCTL_SET_MODE
837
838
<6>[ 2066.408721]  --> AKECS_MODE_E2P_READ
839
}}}
840
841
akmd sets the mode to AKECS_MODE_POWERDOWN, then waits for the kernel to have "open" status. This appears when the accelerometer/magnetometer is requested by the system, so if nothing requests the chip, ECS_IOCTL_GET_OPEN_STATUS
842
 will block until the chip is requested. This also append when the phone is in "sleep" mode. 
843
844
When ECS_IOCTL_GET_OPEN_STATUS is not blocking (the chip is requested by the system), akmd asks the driver to init the chip, with ECS_IOCTL_INIT. Then, akmd sets the mode to AKECS_MODE_E2P_READ. The reason of that is still unclear.
845
846
All this is already implemented in akmd-free.
847
848
{{{
849
<6>[ 2066.421234] --> ECS_IOCTL_READ #1
850
851
<6>[ 2066.421630] what is in rwbuf?
852
853
<6>[ 2066.422302] --------------------
854
855
<6>[ 2066.422637] |	index	|	hdata	|	ddata	|
856
857
<6>[ 2066.423004] |	0	|	0x3	|	3	|
858
859
<6>[ 2066.423339] |	1	|	0x46	|	70	|
860
861
<6>[ 2066.423950] |	2	|	0x0	|	0	|
862
863
<6>[ 2066.424285] |	3	|	0x0	|	0	|
864
865
<6>[ 2066.424621] |	4	|	0x0	|	0	|
866
867
<6>[ 2066.424957] ----------
868
869
<6>[ 2066.425567] --> ECS_IOCTL_READ
870
871
<6>[ 2066.426696] --> ECS_IOCTL_READ #3
872
873
<6>[ 2066.427062] --------------------
874
875
<6>[ 2066.427398] |	index	|	hdata	|	ddata	|
876
877
<6>[ 2066.428039] |	0	|	0x3	|	3	|
878
879
<6>[ 2066.428375] |	1	|	0x97	|	151	|
880
881
<6>[ 2066.428710] |	2	|	0x87	|	135	|
882
883
<6>[ 2066.429321] |	3	|	0x19	|	25	|
884
885
<6>[ 2066.429656] |	4	|	0x0	|	0	|
886
887
<6>[ 2066.429992] ----------
888
}}}
889
890
Here we have a read request, with { 3, 70 } (READ REQ #2) that returns { 3, x, y, z } (READ ASW #2). The answer elements are called x, y, z since these are not constant and my change between devices. We'll refer to these values under the names: READ ASW #2's x, READ ASW #2's y and READ ASW #2's z.
891
892
{{{
893
<6>[ 2066.431243] --> ECS_IOCTL_SET_MODE #1
894
895
<6>[ 2066.431915] --> ECS_IOCTL_SET_MODE
896
897
<6>[ 2066.432250]  --> AKECS_MODE_POWERDOWN
898
899
<6>[ 2066.450866] --> ECS_IOCTL_WRITE #1
900
901
<6>[ 2066.451385] what is in rwbuf?
902
903
<6>[ 2066.452239] --------------------
904
905
<6>[ 2066.452697] |	index	|	hdata	|	ddata	|
906
907
<6>[ 2066.453186] |	0	|	0x4	|	4	|
908
909
<6>[ 2066.454040] |	1	|	0xe8	|	232	|
910
911
<6>[ 2066.454498] |	2	|	0x7	|	7	|
912
913
<6>[ 2066.454956] |	3	|	0x7	|	7	|
914
915
<6>[ 2066.455413] |	4	|	0x9	|	9	|
916
917
<6>[ 2066.456268] ----------
918
919
<6>[ 2066.456726] --> ECS_IOCTL_WRITE
920
}}}
921
922
Here akmd sets the mode to AKECS_MODE_POWERDOWN and writes 4 numbers { 4, 232, x, y, z } to the kernel driver. rwbuf[1] is always 232 but the other numbers are changing depending on READ ASW #2's values. The formula to get x, y and z from READ ASW #2's values is:
923
x = (READ ASW #2's x) % 16
924
y = (READ ASW #2's y) % 16
925
z = (READ ASW #2's y) % 16
926
927
The way to discover that was to determine what makes these values change and how they change depending on READ ASW #2's values. This was easy since the values are also printed in hex format, so (READ ASW #2's x) % 16 is the last number of the hex representation of READ ASW #2's x. 
928
929
{{{
930
<6>[ 2066.457916] --> ECS_IOCTL_WRITE #1
931
932
<6>[ 2066.458374] what is in rwbuf?
933
934
<6>[ 2066.459228] --------------------
935
936
<6>[ 2066.459686] |	index	|	hdata	|	ddata	|
937
938
<6>[ 2066.460174] |	0	|	0x4	|	4	|
939
940
<6>[ 2066.460784] |	1	|	0xe5	|	229	|
941
942
<6>[ 2066.461669] |	2	|	0x89	|	137	|
943
944
<6>[ 2066.462127] |	3	|	0x0	|	0	|
945
946
<6>[ 2066.462615] |	4	|	0x89	|	137	|
947
948
<6>[ 2066.463073] ----------
949
950
<6>[ 2066.463928] --> ECS_IOCTL_WRITE
951
<6>[ 2066.465698] --> ECS_IOCTL_SET_MODE #1
952
953
<6>[ 2066.466186] --> ECS_IOCTL_SET_MODE
954
955
<6>[ 2066.467071]  --> AKECS_MODE_MEASURE_SNG
956
}}}
957
958
Here is a write request of the type { 4, 229, x, y, z }. x, y and z values seem to be written to ''akmd_set_values.txt'' when akmd quits (this should be confirmed), so on the first start of akmd, x, y and z are 0 since there was no previous session to write the numbers on ''akmd_set_values.txt''.
959
960
Anyway, setting x, y and z to 0 doesn't prevent anything to work. 
961
962
Then akmd also sets the mode to AKECS_MODE_MEASURE_SNG.