Merge tag 'locking-urgent-2020-12-27' of git://git.kernel.org/pub/scm/linux/kernel...
[linux/fpc-iii.git] / arch / c6x / kernel / soc.c
blob8362f9390e03b0865650968a497f4d65fa95b01b
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Miscellaneous SoC-specific hooks.
5 * Copyright (C) 2011 Texas Instruments Incorporated
6 * Author: Mark Salter <msalter@redhat.com>
7 */
8 #include <linux/module.h>
9 #include <linux/ctype.h>
10 #include <linux/etherdevice.h>
11 #include <asm/setup.h>
12 #include <asm/soc.h>
14 struct soc_ops soc_ops;
16 int soc_get_exception(void)
18 if (!soc_ops.get_exception)
19 return -1;
20 return soc_ops.get_exception();
23 void soc_assert_event(unsigned int evt)
25 if (soc_ops.assert_event)
26 soc_ops.assert_event(evt);
29 static u8 cmdline_mac[6];
31 static int __init get_mac_addr_from_cmdline(char *str)
33 int count, i, val;
35 for (count = 0; count < 6 && *str; count++, str += 3) {
36 if (!isxdigit(str[0]) || !isxdigit(str[1]))
37 return 0;
38 if (str[2] != ((count < 5) ? ':' : '\0'))
39 return 0;
41 for (i = 0, val = 0; i < 2; i++) {
42 val = val << 4;
43 val |= isdigit(str[i]) ?
44 str[i] - '0' : toupper(str[i]) - 'A' + 10;
46 cmdline_mac[count] = val;
48 return 1;
50 __setup("emac_addr=", get_mac_addr_from_cmdline);
53 * Setup the MAC address for SoC ethernet devices.
55 * Before calling this function, the ethernet driver will have
56 * initialized the addr with local-mac-address from the device
57 * tree (if found). Allow command line to override, but not
58 * the fused address.
60 int soc_mac_addr(unsigned int index, u8 *addr)
62 int i, have_dt_mac = 0, have_cmdline_mac = 0, have_fuse_mac = 0;
64 for (i = 0; i < 6; i++) {
65 if (cmdline_mac[i])
66 have_cmdline_mac = 1;
67 if (c6x_fuse_mac[i])
68 have_fuse_mac = 1;
69 if (addr[i])
70 have_dt_mac = 1;
73 /* cmdline overrides all */
74 if (have_cmdline_mac)
75 memcpy(addr, cmdline_mac, 6);
76 else if (!have_dt_mac) {
77 if (have_fuse_mac)
78 memcpy(addr, c6x_fuse_mac, 6);
79 else
80 eth_random_addr(addr);
83 /* adjust for specific EMAC device */
84 addr[5] += index * c6x_num_cores;
85 return 1;
87 EXPORT_SYMBOL_GPL(soc_mac_addr);