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