1 /*
2  * Copyright (c) 2010 Broadcom Corporation
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #include <defs.h>
18 #include "types.h"
19 #include <ucode_loader.h>
20 
21 enum {
22 	D11UCODE_NAMETAG_START = 0,
23 	D11LCN0BSINITVALS24,
24 	D11LCN0INITVALS24,
25 	D11LCN1BSINITVALS24,
26 	D11LCN1INITVALS24,
27 	D11LCN2BSINITVALS24,
28 	D11LCN2INITVALS24,
29 	D11N0ABSINITVALS16,
30 	D11N0BSINITVALS16,
31 	D11N0INITVALS16,
32 	D11UCODE_OVERSIGHT16_MIMO,
33 	D11UCODE_OVERSIGHT16_MIMOSZ,
34 	D11UCODE_OVERSIGHT24_LCN,
35 	D11UCODE_OVERSIGHT24_LCNSZ,
36 	D11UCODE_OVERSIGHT_BOMMAJOR,
37 	D11UCODE_OVERSIGHT_BOMMINOR
38 };
39 
40 int brcms_ucode_data_init(struct brcms_info *wl, struct brcms_ucode *ucode)
41 {
42 	int rc;
43 
44 	rc = brcms_check_firmwares(wl);
45 
46 	rc = rc < 0 ? rc :
47 		brcms_ucode_init_buf(wl, (void **)&ucode->d11lcn0bsinitvals24,
48 				     D11LCN0BSINITVALS24);
49 	rc = rc < 0 ?
50 	     rc : brcms_ucode_init_buf(wl, (void **)&ucode->d11lcn0initvals24,
51 				       D11LCN0INITVALS24);
52 	rc = rc < 0 ?
53 	     rc : brcms_ucode_init_buf(wl, (void **)&ucode->d11lcn1bsinitvals24,
54 				       D11LCN1BSINITVALS24);
55 	rc = rc < 0 ?
56 	     rc : brcms_ucode_init_buf(wl, (void **)&ucode->d11lcn1initvals24,
57 				       D11LCN1INITVALS24);
58 	rc = rc < 0 ? rc :
59 		brcms_ucode_init_buf(wl, (void **)&ucode->d11lcn2bsinitvals24,
60 				     D11LCN2BSINITVALS24);
61 	rc = rc < 0 ?
62 	     rc : brcms_ucode_init_buf(wl, (void **)&ucode->d11lcn2initvals24,
63 				       D11LCN2INITVALS24);
64 	rc = rc < 0 ?
65 	     rc : brcms_ucode_init_buf(wl, (void **)&ucode->d11n0absinitvals16,
66 				       D11N0ABSINITVALS16);
67 	rc = rc < 0 ?
68 	     rc : brcms_ucode_init_buf(wl, (void **)&ucode->d11n0bsinitvals16,
69 				       D11N0BSINITVALS16);
70 	rc = rc < 0 ?
71 	     rc : brcms_ucode_init_buf(wl, (void **)&ucode->d11n0initvals16,
72 				       D11N0INITVALS16);
73 	rc = rc < 0 ?
74 	     rc : brcms_ucode_init_buf(wl, (void **)&ucode->bcm43xx_16_mimo,
75 				       D11UCODE_OVERSIGHT16_MIMO);
76 	rc = rc < 0 ?
77 	     rc : brcms_ucode_init_uint(wl, &ucode->bcm43xx_16_mimosz,
78 					D11UCODE_OVERSIGHT16_MIMOSZ);
79 	rc = rc < 0 ?
80 	     rc : brcms_ucode_init_buf(wl, (void **)&ucode->bcm43xx_24_lcn,
81 				       D11UCODE_OVERSIGHT24_LCN);
82 	rc = rc < 0 ?
83 	     rc : brcms_ucode_init_uint(wl, &ucode->bcm43xx_24_lcnsz,
84 					D11UCODE_OVERSIGHT24_LCNSZ);
85 	rc = rc < 0 ?
86 	     rc : brcms_ucode_init_buf(wl, (void **)&ucode->bcm43xx_bommajor,
87 				       D11UCODE_OVERSIGHT_BOMMAJOR);
88 	rc = rc < 0 ?
89 	     rc : brcms_ucode_init_buf(wl, (void **)&ucode->bcm43xx_bomminor,
90 				       D11UCODE_OVERSIGHT_BOMMINOR);
91 	return rc;
92 }
93 
94 void brcms_ucode_data_free(struct brcms_ucode *ucode)
95 {
96 	brcms_ucode_free_buf((void *)ucode->d11lcn0bsinitvals24);
97 	brcms_ucode_free_buf((void *)ucode->d11lcn0initvals24);
98 	brcms_ucode_free_buf((void *)ucode->d11lcn1bsinitvals24);
99 	brcms_ucode_free_buf((void *)ucode->d11lcn1initvals24);
100 	brcms_ucode_free_buf((void *)ucode->d11lcn2bsinitvals24);
101 	brcms_ucode_free_buf((void *)ucode->d11lcn2initvals24);
102 	brcms_ucode_free_buf((void *)ucode->d11n0absinitvals16);
103 	brcms_ucode_free_buf((void *)ucode->d11n0bsinitvals16);
104 	brcms_ucode_free_buf((void *)ucode->d11n0initvals16);
105 	brcms_ucode_free_buf((void *)ucode->bcm43xx_16_mimo);
106 	brcms_ucode_free_buf((void *)ucode->bcm43xx_24_lcn);
107 	brcms_ucode_free_buf((void *)ucode->bcm43xx_bommajor);
108 	brcms_ucode_free_buf((void *)ucode->bcm43xx_bomminor);
109 }
110