1 /* arch/arm/mach-tegra/board-stingray-wlan_nvs.c
3 * Code to extract WiFi calibration information from ATAG set up
6 * Copyright (C) 2008 Google, Inc.
7 * Author: Dmitry Shmidt <dimitrysh@google.com>
9 * This software is licensed under the terms of the GNU General Public
10 * License version 2, as published by the Free Software Foundation, and
11 * may be copied, distributed, and modified under those terms.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
20 #include <linux/kernel.h>
21 #include <linux/init.h>
22 #include <linux/platform_device.h>
23 #include <linux/proc_fs.h>
25 #include <asm/setup.h>
27 /* configuration tags specific to msm */
28 #define ATAG_WLAN_NVS 0x57494649 /* Wlan ATAG */
30 #define NVS_MAX_SIZE 0x800U
31 #define NVS_LEN_OFFSET 0x0C
32 /* #define NVS_DATA_OFFSET 0x40*/
33 #define NVS_DATA_OFFSET 0x0
35 static unsigned char wifi_nvs_ram[NVS_MAX_SIZE];
36 static unsigned wifi_nvs_size = 0;
37 static struct proc_dir_entry *wifi_calibration;
39 unsigned char *get_wifi_nvs_ram( void )
43 EXPORT_SYMBOL(get_wifi_nvs_ram);
45 static int __init parse_tag_wlan_nvs(const struct tag *tag)
47 unsigned char *dptr = (unsigned char *)(&tag->u);
49 #ifdef ATAG_WLAN_NVS_DEBUG
53 size = min((tag->hdr.size - 2) * sizeof(__u32), NVS_MAX_SIZE);
54 #ifdef ATAG_WLAN_NVS_DEBUG
55 printk("WiFi Data size = %d , 0x%x\n", tag->hdr.size, tag->hdr.tag);
56 for(i=0;( i < size );i++) {
57 printk("%02x ", *dptr++);
60 memcpy(wifi_nvs_ram, dptr, size);
65 __tagtable(ATAG_WLAN_NVS, parse_tag_wlan_nvs);
67 static unsigned wifi_get_nvs_size( void )
73 ptr = get_wifi_nvs_ram();
74 /* Size in format LE assumed */
75 memcpy(&len, ptr + NVS_LEN_OFFSET, sizeof(len));
76 len = min(len, (NVS_MAX_SIZE - NVS_DATA_OFFSET));
82 int wifi_calibration_size_set(void)
84 if (wifi_calibration != NULL)
85 wifi_calibration->size = wifi_get_nvs_size();
89 static int wifi_calibration_read_proc(char *page, char **start, off_t off,
90 int count, int *eof, void *data)
95 ptr = get_wifi_nvs_ram();
96 len = min(wifi_get_nvs_size(), (unsigned)count);
97 memcpy(page, ptr + NVS_DATA_OFFSET, len);
101 static int __init wifi_nvs_init(void)
103 wifi_calibration = create_proc_entry("calibration", 0444, NULL);
104 if (wifi_calibration != NULL) {
105 wifi_calibration->size = wifi_get_nvs_size();
106 wifi_calibration->read_proc = wifi_calibration_read_proc;
107 wifi_calibration->write_proc = NULL;
112 device_initcall(wifi_nvs_init);