^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Miscellaneous SoC-specific hooks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2011 Texas Instruments Incorporated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Author: Mark Salter <msalter@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <asm/soc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) struct soc_ops soc_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) int soc_get_exception(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) if (!soc_ops.get_exception)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) return soc_ops.get_exception();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) void soc_assert_event(unsigned int evt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) if (soc_ops.assert_event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) soc_ops.assert_event(evt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static u8 cmdline_mac[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static int __init get_mac_addr_from_cmdline(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) int count, i, val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) for (count = 0; count < 6 && *str; count++, str += 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) if (!isxdigit(str[0]) || !isxdigit(str[1]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) if (str[2] != ((count < 5) ? ':' : '\0'))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) for (i = 0, val = 0; i < 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) val = val << 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) val |= isdigit(str[i]) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) str[i] - '0' : toupper(str[i]) - 'A' + 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) cmdline_mac[count] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) __setup("emac_addr=", get_mac_addr_from_cmdline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * Setup the MAC address for SoC ethernet devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * Before calling this function, the ethernet driver will have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * initialized the addr with local-mac-address from the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * tree (if found). Allow command line to override, but not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * the fused address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) int soc_mac_addr(unsigned int index, u8 *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) int i, have_dt_mac = 0, have_cmdline_mac = 0, have_fuse_mac = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) for (i = 0; i < 6; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) if (cmdline_mac[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) have_cmdline_mac = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if (c6x_fuse_mac[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) have_fuse_mac = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if (addr[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) have_dt_mac = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /* cmdline overrides all */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (have_cmdline_mac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) memcpy(addr, cmdline_mac, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) else if (!have_dt_mac) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) if (have_fuse_mac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) memcpy(addr, c6x_fuse_mac, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) eth_random_addr(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /* adjust for specific EMAC device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) addr[5] += index * c6x_num_cores;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) EXPORT_SYMBOL_GPL(soc_mac_addr);