soc.c 2.0 KB

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