soc.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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/system.h>
  15. #include <asm/setup.h>
  16. #include <asm/soc.h>
  17. struct soc_ops soc_ops;
  18. int soc_get_exception(void)
  19. {
  20. if (!soc_ops.get_exception)
  21. return -1;
  22. return soc_ops.get_exception();
  23. }
  24. void soc_assert_event(unsigned int evt)
  25. {
  26. if (soc_ops.assert_event)
  27. soc_ops.assert_event(evt);
  28. }
  29. static u8 cmdline_mac[6];
  30. static int __init get_mac_addr_from_cmdline(char *str)
  31. {
  32. int count, i, val;
  33. for (count = 0; count < 6 && *str; count++, str += 3) {
  34. if (!isxdigit(str[0]) || !isxdigit(str[1]))
  35. return 0;
  36. if (str[2] != ((count < 5) ? ':' : '\0'))
  37. return 0;
  38. for (i = 0, val = 0; i < 2; i++) {
  39. val = val << 4;
  40. val |= isdigit(str[i]) ?
  41. str[i] - '0' : toupper(str[i]) - 'A' + 10;
  42. }
  43. cmdline_mac[count] = val;
  44. }
  45. return 1;
  46. }
  47. __setup("emac_addr=", get_mac_addr_from_cmdline);
  48. /*
  49. * Setup the MAC address for SoC ethernet devices.
  50. *
  51. * Before calling this function, the ethernet driver will have
  52. * initialized the addr with local-mac-address from the device
  53. * tree (if found). Allow command line to override, but not
  54. * the fused address.
  55. */
  56. int soc_mac_addr(unsigned int index, u8 *addr)
  57. {
  58. int i, have_dt_mac = 0, have_cmdline_mac = 0, have_fuse_mac = 0;
  59. for (i = 0; i < 6; i++) {
  60. if (cmdline_mac[i])
  61. have_cmdline_mac = 1;
  62. if (c6x_fuse_mac[i])
  63. have_fuse_mac = 1;
  64. if (addr[i])
  65. have_dt_mac = 1;
  66. }
  67. /* cmdline overrides all */
  68. if (have_cmdline_mac)
  69. memcpy(addr, cmdline_mac, 6);
  70. else if (!have_dt_mac) {
  71. if (have_fuse_mac)
  72. memcpy(addr, c6x_fuse_mac, 6);
  73. else
  74. random_ether_addr(addr);
  75. }
  76. /* adjust for specific EMAC device */
  77. addr[5] += index * c6x_num_cores;
  78. return 1;
  79. }
  80. EXPORT_SYMBOL_GPL(soc_mac_addr);