m5329evb.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. /*
  2. * (C) Copyright 2000-2003
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * Copyright (C) 2004-2007 Freescale Semiconductor, Inc.
  6. * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <common.h>
  27. #include <asm/fec.h>
  28. #include <asm/m5329.h>
  29. #include <asm/immap_5329.h>
  30. #include <config.h>
  31. #include <net.h>
  32. DECLARE_GLOBAL_DATA_PTR;
  33. int checkboard(void)
  34. {
  35. puts("Board: ");
  36. puts("Freescale FireEngine 5329 EVB\n");
  37. return 0;
  38. };
  39. long int initdram(int board_type)
  40. {
  41. volatile sdram_t *sdram = (volatile sdram_t *)(MMAP_SDRAM);
  42. u32 dramsize, i;
  43. dramsize = CFG_SDRAM_SIZE * 0x100000;
  44. for (i = 0x13; i < 0x20; i++) {
  45. if (dramsize == (1 << i))
  46. break;
  47. }
  48. i--;
  49. sdram->cs0 = (CFG_SDRAM_BASE | i);
  50. sdram->cfg1 = CFG_SDRAM_CFG1;
  51. sdram->cfg2 = CFG_SDRAM_CFG2;
  52. /* Issue PALL */
  53. sdram->ctrl = CFG_SDRAM_CTRL | 2;
  54. /* Issue LEMR */
  55. sdram->mode = CFG_SDRAM_EMOD;
  56. sdram->mode = (CFG_SDRAM_MODE | 0x04000000);
  57. udelay(500);
  58. /* Issue PALL */
  59. sdram->ctrl = (CFG_SDRAM_CTRL | 2);
  60. /* Perform two refresh cycles */
  61. sdram->ctrl = CFG_SDRAM_CTRL | 4;
  62. sdram->ctrl = CFG_SDRAM_CTRL | 4;
  63. sdram->mode = CFG_SDRAM_MODE;
  64. sdram->ctrl = (CFG_SDRAM_CTRL & ~0x80000000) | 0x10000c00;
  65. udelay(100);
  66. return dramsize;
  67. };
  68. int testdram(void)
  69. {
  70. /* TODO: XXX XXX XXX */
  71. printf("DRAM test not implemented!\n");
  72. return (0);
  73. }
  74. #ifdef CFG_FLASH_CFI
  75. void sync(void)
  76. {
  77. /* This sync function is PowerPC intruction,
  78. coldfire does not have this instruction. Dummy function */
  79. }
  80. #endif
  81. #if (CONFIG_COMMANDS & CFG_CMD_NET) && defined(CONFIG_NET_MULTI)
  82. #undef MII_DEBUG
  83. #undef ET_DEBUG
  84. int fecpin_setclear(struct eth_device *dev, int setclear)
  85. {
  86. volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  87. if (setclear) {
  88. gpio->par_fec |= GPIO_PAR_FEC_7W_FEC | GPIO_PAR_FEC_MII_FEC;
  89. gpio->par_feci2c |=
  90. GPIO_PAR_FECI2C_MDC_EMDC | GPIO_PAR_FECI2C_MDIO_EMDIO;
  91. } else {
  92. gpio->par_fec &= ~(GPIO_PAR_FEC_7W_FEC | GPIO_PAR_FEC_MII_FEC);
  93. gpio->par_feci2c &=
  94. ~(GPIO_PAR_FECI2C_MDC_EMDC | GPIO_PAR_FECI2C_MDIO_EMDIO);
  95. }
  96. return 0;
  97. }
  98. #if defined(CFG_DISCOVER_PHY) || (CONFIG_COMMANDS & CFG_CMD_MII)
  99. #include <miiphy.h>
  100. /* Make MII read/write commands for the FEC. */
  101. #define mk_mii_read(ADDR, REG) (0x60020000 | ((ADDR << 23) | \
  102. (REG & 0x1f) << 18))
  103. #define mk_mii_write(ADDR, REG, VAL) (0x50020000 | ((ADDR << 23) | \
  104. (REG & 0x1f) << 18) | \
  105. (VAL & 0xffff))
  106. /* PHY identification */
  107. #define PHY_ID_LXT970 0x78100000 /* LXT970 */
  108. #define PHY_ID_LXT971 0x001378e0 /* LXT971 and 972 */
  109. #define PHY_ID_82555 0x02a80150 /* Intel 82555 */
  110. #define PHY_ID_QS6612 0x01814400 /* QS6612 */
  111. #define PHY_ID_AMD79C784 0x00225610 /* AMD 79C784 */
  112. #define PHY_ID_LSI80225 0x0016f870 /* LSI 80225 */
  113. #define PHY_ID_LSI80225B 0x0016f880 /* LSI 80225/B */
  114. #define PHY_ID_DP83848VV 0x20005C90 /* National 83848 */
  115. #define PHY_ID_DP83849 0x20005CA2 /* National 82849 */
  116. #define STR_ID_LXT970 "LXT970"
  117. #define STR_ID_LXT971 "LXT971"
  118. #define STR_ID_82555 "Intel82555"
  119. #define STR_ID_QS6612 "QS6612"
  120. #define STR_ID_AMD79C784 "AMD79C784"
  121. #define STR_ID_LSI80225 "LSI80225"
  122. #define STR_ID_LSI80225B "LSI80225/B"
  123. #define STR_ID_DP83848VV "N83848"
  124. #define STR_ID_DP83849 "N83849"
  125. /****************************************************************************
  126. * mii_init -- Initialize the MII for MII command without ethernet
  127. * This function is a subset of eth_init
  128. ****************************************************************************
  129. */
  130. void mii_reset(struct fec_info_s *info)
  131. {
  132. volatile fec_t *fecp = (fec_t *) (info->miibase);
  133. int i;
  134. fecp->ecr = FEC_ECR_RESET;
  135. for (i = 0; (fecp->ecr & FEC_ECR_RESET) && (i < FEC_RESET_DELAY); ++i) {
  136. udelay(1);
  137. }
  138. if (i == FEC_RESET_DELAY) {
  139. printf("FEC_RESET_DELAY timeout\n");
  140. }
  141. }
  142. /* send command to phy using mii, wait for result */
  143. uint mii_send(uint mii_cmd)
  144. {
  145. struct fec_info_s *info;
  146. struct eth_device *dev;
  147. volatile fec_t *ep;
  148. uint mii_reply;
  149. int j = 0;
  150. /* retrieve from register structure */
  151. dev = eth_get_dev();
  152. info = dev->priv;
  153. ep = (fec_t *) info->miibase;
  154. ep->mmfr = mii_cmd; /* command to phy */
  155. /* wait for mii complete */
  156. while (!(ep->eir & FEC_EIR_MII) && (j < MCFFEC_TOUT_LOOP)) {
  157. udelay(1);
  158. j++;
  159. }
  160. if (j >= MCFFEC_TOUT_LOOP) {
  161. printf("MII not complete\n");
  162. return -1;
  163. }
  164. mii_reply = ep->mmfr; /* result from phy */
  165. ep->eir = FEC_EIR_MII; /* clear MII complete */
  166. #ifdef ET_DEBUG
  167. printf("%s[%d] %s: sent=0x%8.8x, reply=0x%8.8x\n",
  168. __FILE__, __LINE__, __FUNCTION__, mii_cmd, mii_reply);
  169. #endif
  170. return (mii_reply & 0xffff); /* data read from phy */
  171. }
  172. #endif /* CFG_DISCOVER_PHY || (CONFIG_COMMANDS & CFG_CMD_MII) */
  173. #if defined(CFG_DISCOVER_PHY)
  174. int mii_discover_phy(struct eth_device *dev)
  175. {
  176. #define MAX_PHY_PASSES 11
  177. struct fec_info_s *info = dev->priv;
  178. int phyaddr, pass;
  179. uint phyno, phytype;
  180. if (info->phyname_init)
  181. return info->phy_addr;
  182. phyaddr = -1; /* didn't find a PHY yet */
  183. for (pass = 1; pass <= MAX_PHY_PASSES && phyaddr < 0; ++pass) {
  184. if (pass > 1) {
  185. /* PHY may need more time to recover from reset.
  186. * The LXT970 needs 50ms typical, no maximum is
  187. * specified, so wait 10ms before try again.
  188. * With 11 passes this gives it 100ms to wake up.
  189. */
  190. udelay(10000); /* wait 10ms */
  191. }
  192. for (phyno = 0; phyno < 32 && phyaddr < 0; ++phyno) {
  193. phytype = mii_send(mk_mii_read(phyno, PHY_PHYIDR1));
  194. #ifdef ET_DEBUG
  195. printf("PHY type 0x%x pass %d type\n", phytype, pass);
  196. #endif
  197. if (phytype != 0xffff) {
  198. phyaddr = phyno;
  199. phytype <<= 16;
  200. phytype |=
  201. mii_send(mk_mii_read(phyno, PHY_PHYIDR2));
  202. switch (phytype & 0xffffffff) {
  203. case PHY_ID_DP83848VV:
  204. strcpy(info->phy_name,
  205. STR_ID_DP83848VV);
  206. info->phyname_init = 1;
  207. break;
  208. default:
  209. strcpy(info->phy_name, "unknown");
  210. info->phyname_init = 1;
  211. break;
  212. }
  213. #ifdef ET_DEBUG
  214. printf("PHY @ 0x%x pass %d type ", phyno, pass);
  215. switch (phytype & 0xffffffff) {
  216. case PHY_ID_DP83848VV:
  217. printf(STR_ID_DP83848VV);
  218. break;
  219. default:
  220. printf("0x%08x\n", phytype);
  221. break;
  222. }
  223. #endif
  224. }
  225. }
  226. }
  227. if (phyaddr < 0)
  228. printf("No PHY device found.\n");
  229. return phyaddr;
  230. }
  231. #endif /* CFG_DISCOVER_PHY */
  232. void mii_init(void)
  233. {
  234. volatile fec_t *fecp;
  235. struct fec_info_s *info;
  236. struct eth_device *dev;
  237. int miispd = 0, i = 0;
  238. u16 autoneg = 0;
  239. /* retrieve from register structure */
  240. dev = eth_get_dev();
  241. info = dev->priv;
  242. fecp = (fec_t *) info->miibase;
  243. fecpin_setclear(dev, 1);
  244. mii_reset(info);
  245. /* We use strictly polling mode only */
  246. fecp->eimr = 0;
  247. /* Clear any pending interrupt */
  248. fecp->eir = 0xffffffff;
  249. /* Set MII speed */
  250. miispd = (gd->bus_clk / 1000000) / 5;
  251. fecp->mscr = miispd << 1;
  252. info->phy_addr = mii_discover_phy(dev);
  253. #define AUTONEGLINK (PHY_BMSR_AUTN_COMP | PHY_BMSR_LS)
  254. while (i < MCFFEC_TOUT_LOOP) {
  255. autoneg = 0;
  256. miiphy_read(dev->name, info->phy_addr, PHY_BMSR, &autoneg);
  257. i++;
  258. if ((autoneg & AUTONEGLINK) == AUTONEGLINK)
  259. break;
  260. udelay(500);
  261. }
  262. if (i >= MCFFEC_TOUT_LOOP) {
  263. printf("Auto Negotiation not complete\n");
  264. }
  265. /* adapt to the half/full speed settings */
  266. info->dup_spd = miiphy_duplex(dev->name, info->phy_addr) << 16;
  267. info->dup_spd |= miiphy_speed(dev->name, info->phy_addr);
  268. }
  269. /*****************************************************************************
  270. * Read and write a MII PHY register, routines used by MII Utilities
  271. *
  272. * FIXME: These routines are expected to return 0 on success, but mii_send
  273. * does _not_ return an error code. Maybe 0xFFFF means error, i.e.
  274. * no PHY connected...
  275. * For now always return 0.
  276. * FIXME: These routines only work after calling eth_init() at least once!
  277. * Otherwise they hang in mii_send() !!! Sorry!
  278. *****************************************************************************/
  279. int mcffec_miiphy_read(char *devname, unsigned char addr,
  280. unsigned char reg, unsigned short *value)
  281. {
  282. short rdreg; /* register working value */
  283. #ifdef MII_DEBUG
  284. printf("miiphy_read(0x%x) @ 0x%x = ", reg, addr);
  285. #endif
  286. rdreg = mii_send(mk_mii_read(addr, reg));
  287. *value = rdreg;
  288. #ifdef MII_DEBUG
  289. printf("0x%04x\n", *value);
  290. #endif
  291. return 0;
  292. }
  293. int mcffec_miiphy_write(char *devname, unsigned char addr,
  294. unsigned char reg, unsigned short value)
  295. {
  296. short rdreg; /* register working value */
  297. #ifdef MII_DEBUG
  298. printf("miiphy_write(0x%x) @ 0x%x = ", reg, addr);
  299. #endif
  300. rdreg = mii_send(mk_mii_write(addr, reg, value));
  301. #ifdef MII_DEBUG
  302. printf("0x%04x\n", value);
  303. #endif
  304. return 0;
  305. }
  306. #endif /* CFG_CMD_NET, FEC_ENET & NET_MULTI */