omap3_smc911x.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2014 CompuLab, Ltd. <www.compulab.co.il>
  4. *
  5. * Authors: Igor Grinberg <grinberg@compulab.co.il>
  6. */
  7. #include <common.h>
  8. #include <netdev.h>
  9. #include <asm/io.h>
  10. #include <linux/errno.h>
  11. #include <asm/arch/cpu.h>
  12. #include <asm/arch/mem.h>
  13. #include <asm/arch/sys_proto.h>
  14. #include <asm/gpio.h>
  15. #include "common.h"
  16. static u32 cl_omap3_smc911x_gpmc_net_config[GPMC_MAX_REG] = {
  17. NET_GPMC_CONFIG1,
  18. NET_GPMC_CONFIG2,
  19. NET_GPMC_CONFIG3,
  20. NET_GPMC_CONFIG4,
  21. NET_GPMC_CONFIG5,
  22. NET_GPMC_CONFIG6,
  23. 0
  24. };
  25. static void cl_omap3_smc911x_setup_net_chip_gmpc(int cs, u32 base_addr)
  26. {
  27. struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
  28. enable_gpmc_cs_config(cl_omap3_smc911x_gpmc_net_config,
  29. &gpmc_cfg->cs[cs], base_addr, GPMC_SIZE_16M);
  30. /* Enable off mode for NWE in PADCONF_GPMC_NWE register */
  31. writew(readw(&ctrl_base->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe);
  32. /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */
  33. writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe);
  34. /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */
  35. writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00,
  36. &ctrl_base->gpmc_nadv_ale);
  37. }
  38. #ifdef CONFIG_OMAP_GPIO
  39. static int cl_omap3_smc911x_reset_net_chip(int gpio)
  40. {
  41. int err;
  42. if (!gpio_is_valid(gpio))
  43. return -EINVAL;
  44. err = gpio_request(gpio, "eth rst");
  45. if (err)
  46. return err;
  47. /* Set gpio as output and send a pulse */
  48. gpio_direction_output(gpio, 1);
  49. udelay(1);
  50. gpio_set_value(gpio, 0);
  51. mdelay(40);
  52. gpio_set_value(gpio, 1);
  53. mdelay(1);
  54. return 0;
  55. }
  56. #else /* !CONFIG_OMAP_GPIO */
  57. static inline int cl_omap3_smc911x_reset_net_chip(int gpio) { return 0; }
  58. #endif /* CONFIG_OMAP_GPIO */
  59. int cl_omap3_smc911x_init(int id, int cs, u32 base_addr,
  60. int (*reset)(int), int rst_gpio)
  61. {
  62. int ret;
  63. cl_omap3_smc911x_setup_net_chip_gmpc(cs, base_addr);
  64. if (reset)
  65. reset(rst_gpio);
  66. else
  67. cl_omap3_smc911x_reset_net_chip(rst_gpio);
  68. ret = smc911x_initialize(id, base_addr);
  69. if (ret > 0)
  70. return ret;
  71. printf("Failed initializing SMC911x! ");
  72. return 0;
  73. }