xref: /netbsd-src/sys/arch/powerpc/ibm4xx/ibm4xx_autoconf.c (revision 36cc5934272a805aaf7bb57ea8f9fff0003dd45c)
1*36cc5934Srin /*	$NetBSD: ibm4xx_autoconf.c,v 1.17 2021/03/29 13:40:21 rin Exp $	*/
279354dbaSshige /*	Original Tag: ibm4xxgpx_autoconf.c,v 1.2 2004/10/23 17:12:22 thorpej Exp $	*/
379354dbaSshige 
479354dbaSshige /*
579354dbaSshige  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
679354dbaSshige  * Copyright (C) 1995, 1996 TooLs GmbH.
779354dbaSshige  * All rights reserved.
879354dbaSshige  *
979354dbaSshige  * Redistribution and use in source and binary forms, with or without
1079354dbaSshige  * modification, are permitted provided that the following conditions
1179354dbaSshige  * are met:
1279354dbaSshige  * 1. Redistributions of source code must retain the above copyright
1379354dbaSshige  *    notice, this list of conditions and the following disclaimer.
1479354dbaSshige  * 2. Redistributions in binary form must reproduce the above copyright
1579354dbaSshige  *    notice, this list of conditions and the following disclaimer in the
1679354dbaSshige  *    documentation and/or other materials provided with the distribution.
1779354dbaSshige  * 3. All advertising materials mentioning features or use of this software
1879354dbaSshige  *    must display the following acknowledgement:
1979354dbaSshige  *	This product includes software developed by TooLs GmbH.
2079354dbaSshige  * 4. The name of TooLs GmbH may not be used to endorse or promote products
2179354dbaSshige  *    derived from this software without specific prior written permission.
2279354dbaSshige  *
2379354dbaSshige  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
2479354dbaSshige  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2579354dbaSshige  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2679354dbaSshige  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2779354dbaSshige  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2879354dbaSshige  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
2979354dbaSshige  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
3079354dbaSshige  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
3179354dbaSshige  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
3279354dbaSshige  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3379354dbaSshige  */
3479354dbaSshige 
3579354dbaSshige #include <sys/cdefs.h>
36*36cc5934Srin __KERNEL_RCSID(0, "$NetBSD: ibm4xx_autoconf.c,v 1.17 2021/03/29 13:40:21 rin Exp $");
3779354dbaSshige 
3879354dbaSshige #include <sys/param.h>
3979354dbaSshige #include <sys/conf.h>
4079354dbaSshige #include <sys/device.h>
4179354dbaSshige #include <sys/systm.h>
421fd2c684Smatt #include <sys/cpu.h>
4379354dbaSshige 
44ce880a59Sshige #include <net/if.h>
45ce880a59Sshige #include <net/if_ether.h>
46ce880a59Sshige 
471fd2c684Smatt #include <powerpc/ibm4xx/cpu.h>
48*36cc5934Srin #include <powerpc/ibm4xx/dev/comopbvar.h>
49b636d491Sthorpej #include <powerpc/ibm4xx/dev/opbvar.h>
50b636d491Sthorpej 
5179354dbaSshige void
cpu_rootconf(void)522e55efcfSrin cpu_rootconf(void)
532e55efcfSrin {
542e55efcfSrin 
552e55efcfSrin 	rootconf();
562e55efcfSrin }
572e55efcfSrin 
582e55efcfSrin void
ibm4xx_device_register(device_t dev,void * aux,int com_freq)59*36cc5934Srin ibm4xx_device_register(device_t dev, void *aux, int com_freq)
6079354dbaSshige {
61036ca983Smatt 	device_t parent = device_parent(dev);
6279354dbaSshige 
63*36cc5934Srin 	if (device_is_a(dev, "com") && device_is_a(parent, "opb")) {
64*36cc5934Srin 		/* Set the frequency of the on-chip UART. */
65*36cc5934Srin 		com_opb_device_register(dev, com_freq);
66*36cc5934Srin 		return;
67*36cc5934Srin 	}
68*36cc5934Srin 
695034f87dSsimonb 	if (device_is_a(dev, "emac") && device_is_a(parent, "opb")) {
702692e2e2Skiyohara 		/* Set the mac-address of the on-chip Ethernet. */
71b636d491Sthorpej 		struct opb_attach_args *oaa = aux;
72ce880a59Sshige 
7311c16d37Sthorpej 		if (oaa->opb_instance < 10) {
742692e2e2Skiyohara 			prop_dictionary_t dict = device_properties(dev);
75fb44a857Sthorpej 			prop_data_t pd;
762692e2e2Skiyohara 			prop_number_t pn;
77ce880a59Sshige 			unsigned char prop_name[15];
78ce880a59Sshige 
79ce880a59Sshige 			snprintf(prop_name, sizeof(prop_name),
80b636d491Sthorpej 			    "emac%d-mac-addr", oaa->opb_instance);
81fb44a857Sthorpej 			pd = prop_dictionary_get(board_properties, prop_name);
82fb44a857Sthorpej 			if (pd == NULL) {
83ce880a59Sshige 				printf("WARNING: unable to get mac-addr "
84ce880a59Sshige 				    "property from board properties\n");
85ce880a59Sshige 				return;
86ce880a59Sshige 			}
872692e2e2Skiyohara 			if (prop_dictionary_set(dict, "mac-address", pd) ==
882692e2e2Skiyohara 			    false)
892692e2e2Skiyohara 				printf("WARNING: unable to set mac-address "
90036ca983Smatt 				    "property for %s\n", device_xname(dev));
912692e2e2Skiyohara 
922692e2e2Skiyohara 			snprintf(prop_name, sizeof(prop_name),
932692e2e2Skiyohara 			    "emac%d-mii-phy", oaa->opb_instance);
942692e2e2Skiyohara 			pn = prop_dictionary_get(board_properties, prop_name);
952692e2e2Skiyohara 			if (pn != NULL)
962692e2e2Skiyohara 				prop_dictionary_set_uint32(dict, "mii-phy",
972692e2e2Skiyohara 				    prop_number_integer_value(pn));
98fb44a857Sthorpej 		}
9979354dbaSshige 		return;
10079354dbaSshige 	}
10179354dbaSshige }
102