temp revert rk change
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-tegra / board-stingray-wlan_nvs.c
1 /* arch/arm/mach-tegra/board-stingray-wlan_nvs.c
2  *
3  * Code to extract WiFi calibration information from ATAG set up 
4  * by the bootloader.
5  *
6  * Copyright (C) 2008 Google, Inc.
7  * Author: Dmitry Shmidt <dimitrysh@google.com>
8  *
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.
12  *
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.
17  *
18  */
19
20 #include <linux/kernel.h>
21 #include <linux/init.h>
22 #include <linux/platform_device.h>
23 #include <linux/proc_fs.h>
24
25 #include <asm/setup.h>
26
27 /* configuration tags specific to msm */
28 #define ATAG_WLAN_NVS   0x57494649 /* Wlan ATAG */
29
30 #define NVS_MAX_SIZE    0x800U
31 #define NVS_LEN_OFFSET  0x0C
32 /* #define NVS_DATA_OFFSET      0x40*/
33 #define NVS_DATA_OFFSET 0x0
34
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;
38
39 unsigned char *get_wifi_nvs_ram( void )
40 {
41         return wifi_nvs_ram;
42 }
43 EXPORT_SYMBOL(get_wifi_nvs_ram);
44
45 static int __init parse_tag_wlan_nvs(const struct tag *tag)
46 {
47         unsigned char *dptr = (unsigned char *)(&tag->u);
48         unsigned size;
49 #ifdef ATAG_WLAN_NVS_DEBUG
50         unsigned i;
51 #endif
52
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++);
58         }
59 #endif
60         memcpy(wifi_nvs_ram, dptr, size);
61         wifi_nvs_size = size;
62         return 0;
63 }
64
65 __tagtable(ATAG_WLAN_NVS, parse_tag_wlan_nvs);
66
67 static unsigned wifi_get_nvs_size( void )
68 {
69 #if 0
70         unsigned char *ptr;
71         unsigned len;
72
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));
77         return len;
78 #endif
79         return wifi_nvs_size;
80 }
81
82 int wifi_calibration_size_set(void)
83 {
84         if (wifi_calibration != NULL)
85                 wifi_calibration->size = wifi_get_nvs_size();
86         return 0;
87 }
88
89 static int wifi_calibration_read_proc(char *page, char **start, off_t off,
90                                         int count, int *eof, void *data)
91 {
92         unsigned char *ptr;
93         unsigned len;
94
95         ptr = get_wifi_nvs_ram();
96         len = min(wifi_get_nvs_size(), (unsigned)count);
97         memcpy(page, ptr + NVS_DATA_OFFSET, len);
98         return len;
99 }
100
101 static int __init wifi_nvs_init(void)
102 {
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;
108         }
109         return 0;
110 }
111
112 device_initcall(wifi_nvs_init);