1 // SPDX-License-Identifier: GPL-2.0-only
3 * Miscellaneous SoC-specific hooks.
5 * Copyright (C) 2011 Texas Instruments Incorporated
6 * Author: Mark Salter <msalter@redhat.com>
8 #include <linux/module.h>
9 #include <linux/ctype.h>
10 #include <linux/etherdevice.h>
11 #include <asm/setup.h>
14 struct soc_ops soc_ops
;
16 int soc_get_exception(void)
18 if (!soc_ops
.get_exception
)
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
)
35 for (count
= 0; count
< 6 && *str
; count
++, str
+= 3) {
36 if (!isxdigit(str
[0]) || !isxdigit(str
[1]))
38 if (str
[2] != ((count
< 5) ? ':' : '\0'))
41 for (i
= 0, val
= 0; i
< 2; i
++) {
43 val
|= isdigit(str
[i
]) ?
44 str
[i
] - '0' : toupper(str
[i
]) - 'A' + 10;
46 cmdline_mac
[count
] = val
;
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
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
++) {
73 /* cmdline overrides all */
75 memcpy(addr
, cmdline_mac
, 6);
76 else if (!have_dt_mac
) {
78 memcpy(addr
, c6x_fuse_mac
, 6);
80 eth_random_addr(addr
);
83 /* adjust for specific EMAC device */
84 addr
[5] += index
* c6x_num_cores
;
87 EXPORT_SYMBOL_GPL(soc_mac_addr
);