bcm_socinfo.c revision 299994
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: head/sys/mips/broadcom/bcm_socinfo.c 299994 2016-05-17 00:00:01Z adrian $");
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}, /* BCM4706 to check */
37		{0x0022B83A, 300, 20000000}, /* BCM4716B0 ASUS RT-N12  */
38		{0x00914716, 354, 20000000}, /* BCM4717A1 to check  */
39		{0x00A14716, 480, 20000000}, /* BCM4718A1 ASUS RT-N16 */
40		{0x00435356, 300, 25000000}, /* BCM5356A1 (RT-N10, WNR1000v3) */
41		{0x00825357, 500, 20000000}, /* BCM5358UB0 ASUS RT-N53A1 */
42		{0x00845357, 300, 20000000}, /* BCM5357B0 to check */
43		{0x00945357, 500, 20000000}, /* BCM5358 */
44		{0x00A45357, 500, 20000000}, /* BCM47186B0 Tenda N60  */
45		{0x0085D144, 300, 20000000}, /* BCM5356C0 */
46		{0x00B5D144, 300, 20000000}, /* BCM5357C0 */
47		{0,0,0}
48};
49
50/* Most popular BCM SoC info */
51struct bcm_socinfo BCM_DEFAULT_SOCINFO = {0x0, 300, 20000000};
52
53struct bcm_socinfo*
54bcm_get_socinfo_by_socid(uint32_t key)
55{
56	struct bcm_socinfo* start;
57
58	if(!key)
59		return (NULL);
60
61	for(start = bcm_socinfos; start->id > 0; start++)
62		if(start->id == key)
63			return (start);
64
65	return (NULL);
66}
67
68struct bcm_socinfo*
69bcm_get_socinfo(void)
70{
71	uint32_t		socid;
72	struct bcm_socinfo	*socinfo;
73
74	/*
75	 * We need Chip ID + Revision + Package
76	 * --------------------------------------------------------------
77         * | 	Mask		| Usage					|
78         * --------------------------------------------------------------
79	 * |	0x0000FFFF	| Chip ID				|
80	 * |	0x000F0000	| Chip Revision				|
81	 * |	0x00F00000	| Package Options			|
82	 * |	0x0F000000	| Number of Cores (ChipCommon Rev. >= 4)|
83	 * |	0xF0000000	| Chip Type				|
84	 * --------------------------------------------------------------
85	 */
86
87	socid = BCM_READ_REG32(BCM_REG_CHIPC_ID) & 0x00FFFFFF;
88	socinfo = bcm_get_socinfo_by_socid(socid);
89	return (socinfo != NULL) ? socinfo : &BCM_DEFAULT_SOCINFO;
90}
91