spi-topcliff-pch: supports a spi mode setup and bit order setup by IO control
[zen-stable.git] / arch / c6x / kernel / soc.c
blobdd45bc39af0e300fe30a416facbf334762d3b8c7
1 /*
2 * Miscellaneous SoC-specific hooks.
4 * Copyright (C) 2011 Texas Instruments Incorporated
5 * Author: Mark Salter <msalter@redhat.com>
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.
11 #include <linux/module.h>
12 #include <linux/ctype.h>
13 #include <linux/etherdevice.h>
14 #include <asm/system.h>
15 #include <asm/setup.h>
16 #include <asm/soc.h>
18 struct soc_ops soc_ops;
20 int soc_get_exception(void)
22 if (!soc_ops.get_exception)
23 return -1;
24 return soc_ops.get_exception();
27 void soc_assert_event(unsigned int evt)
29 if (soc_ops.assert_event)
30 soc_ops.assert_event(evt);
33 static u8 cmdline_mac[6];
35 static int __init get_mac_addr_from_cmdline(char *str)
37 int count, i, val;
39 for (count = 0; count < 6 && *str; count++, str += 3) {
40 if (!isxdigit(str[0]) || !isxdigit(str[1]))
41 return 0;
42 if (str[2] != ((count < 5) ? ':' : '\0'))
43 return 0;
45 for (i = 0, val = 0; i < 2; i++) {
46 val = val << 4;
47 val |= isdigit(str[i]) ?
48 str[i] - '0' : toupper(str[i]) - 'A' + 10;
50 cmdline_mac[count] = val;
52 return 1;
54 __setup("emac_addr=", get_mac_addr_from_cmdline);
57 * Setup the MAC address for SoC ethernet devices.
59 * Before calling this function, the ethernet driver will have
60 * initialized the addr with local-mac-address from the device
61 * tree (if found). Allow command line to override, but not
62 * the fused address.
64 int soc_mac_addr(unsigned int index, u8 *addr)
66 int i, have_dt_mac = 0, have_cmdline_mac = 0, have_fuse_mac = 0;
68 for (i = 0; i < 6; i++) {
69 if (cmdline_mac[i])
70 have_cmdline_mac = 1;
71 if (c6x_fuse_mac[i])
72 have_fuse_mac = 1;
73 if (addr[i])
74 have_dt_mac = 1;
77 /* cmdline overrides all */
78 if (have_cmdline_mac)
79 memcpy(addr, cmdline_mac, 6);
80 else if (!have_dt_mac) {
81 if (have_fuse_mac)
82 memcpy(addr, c6x_fuse_mac, 6);
83 else
84 random_ether_addr(addr);
87 /* adjust for specific EMAC device */
88 addr[5] += index * c6x_num_cores;
89 return 1;
91 EXPORT_SYMBOL_GPL(soc_mac_addr);