summaryrefslogtreecommitdiff
path: root/arch/arm/mach-msm/htc_akm_cal.c
blob: 943083fe0fbe857b6e081e9fda9e9c5bcbeb2de7 (plain)
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
/* arch/arm/mach-msm/htc_akm_cal.c
 *
 * Code to extract compass calibration information from ATAG set up 
 * by the bootloader.
 *
 * Copyright (C) 2007-2008 HTC Corporation
 * Author: Farmer Tseng <farmer_tseng@htc.com>
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * 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.
 *
 */

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/platform_device.h>

#include <asm/setup.h>

/* configuration tags specific to AKM8976 */
#define ATAG_AKM8976	0x89768976 /* AKM8976 */

#define MAX_CALI_SIZE	0x1000U

static char akm_cal_ram[MAX_CALI_SIZE];

char *get_akm_cal_ram(void)
{
	return(akm_cal_ram);
}
EXPORT_SYMBOL(get_akm_cal_ram);

static int __init parse_tag_akm(const struct tag *tag)
{
	unsigned char *dptr = (unsigned char *)(&tag->u);
	unsigned size;

	size = min((tag->hdr.size - 2) * sizeof(__u32), MAX_CALI_SIZE);

	printk(KERN_INFO "AKM Data size = %d , 0x%x, size = %d\n",
			tag->hdr.size, tag->hdr.tag, size);

#ifdef ATAG_COMPASS_DEBUG
	unsigned i;
	unsigned char *ptr;

	ptr = dptr;
	printk(KERN_INFO
	       "AKM Data size = %d , 0x%x\n",
	       tag->hdr.size, tag->hdr.tag);
	for (i = 0; i < size; i++)
		printk(KERN_INFO "%02x ", *ptr++);
#endif
	memcpy((void *)akm_cal_ram, (void *)dptr, size);
	return 0;
}

__tagtable(ATAG_AKM8976, parse_tag_akm);