1/*-
2 * Copyright (c) 2016 Michael Zhilin <mizhka@gmail.com>
3 *
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD$");
30
31#include <sys/param.h>
32#include "bcm_socinfo.h"
33
34/* found on https://wireless.wiki.kernel.org/en/users/drivers/b43/soc */
35struct bcm_socinfo bcm_socinfos[] = {
36		{0x00005300, 600, 25000000, 1}, /* BCM4706 to check */
37		{0x0022B83A, 300, 20000000, 1}, /* BCM4716B0 ASUS RT-N12  */
38		{0x00914716, 354, 20000000, 1}, /* BCM4717A1 to check  */
39		{0x00A14716, 480, 20000000, 1}, /* BCM4718A1 ASUS RT-N16 */
40		{0x00435356, 300, 25000000, 1}, /* BCM5356A1 (RT-N10, WNR1000v3) */
41		{0x00825357, 500, 20000000, 1}, /* BCM5358UB0 ASUS RT-N53A1 */
42		{0x00845357, 300, 20000000, 1}, /* BCM5357B0 to check */
43		{0x00945357, 500, 20000000, 1}, /* BCM5358 */
44		{0x00A45357, 500, 20000000, 1}, /* BCM47186B0 Tenda N60  */
45		{0x0085D144, 300, 20000000, 1}, /* BCM5356C0 */
46		{0x00B5D144, 300, 20000000, 1}, /* BCM5357C0 */
47		{0x00015365, 200, 0, 1},	/* BCM5365 */
48		{0,0,0}
49};
50
51/* Most popular BCM SoC info */
52struct bcm_socinfo BCM_DEFAULT_SOCINFO = {0x0, 300, 20000000, 0};
53
54struct bcm_socinfo*
55bcm_get_socinfo_by_socid(uint32_t key)
56{
57	struct bcm_socinfo* start;
58
59	if(!key)
60		return (NULL);
61
62	for(start = bcm_socinfos; start->id > 0; start++)
63		if(start->id == key)
64			return (start);
65
66	return (NULL);
67}
68
69struct bcm_socinfo*
70bcm_get_socinfo(void)
71{
72	uint32_t		socid;
73	struct bcm_socinfo	*socinfo;
74
75	/*
76	 * We need Chip ID + Revision + Package
77	 * --------------------------------------------------------------
78         * | 	Mask		| Usage					|
79         * --------------------------------------------------------------
80	 * |	0x0000FFFF	| Chip ID				|
81	 * |	0x000F0000	| Chip Revision				|
82	 * |	0x00F00000	| Package Options			|
83	 * |	0x0F000000	| Number of Cores (ChipCommon Rev. >= 4)|
84	 * |	0xF0000000	| Chip Type				|
85	 * --------------------------------------------------------------
86	 */
87
88	socid = BCM_READ_REG32(BCM_REG_CHIPC_ID) & 0x00FFFFFF;
89	socinfo = bcm_get_socinfo_by_socid(socid);
90	return (socinfo != NULL) ? socinfo : &BCM_DEFAULT_SOCINFO;
91}
92