1a47a12beSStefan Roese /* 2a47a12beSStefan Roese * Freescale SerDes initialization routine 3a47a12beSStefan Roese * 4*509adc8bSJerry Huang * Copyright (C) 2007,2011 Freescale Semicondutor, Inc. 5a47a12beSStefan Roese * Copyright (C) 2008 MontaVista Software, Inc. 6a47a12beSStefan Roese * 7a47a12beSStefan Roese * Author: Li Yang <leoli@freescale.com> 8a47a12beSStefan Roese * 9a47a12beSStefan Roese * This program is free software; you can redistribute it and/or modify it 10a47a12beSStefan Roese * under the terms of the GNU General Public License as published by the 11a47a12beSStefan Roese * Free Software Foundation; either version 2 of the License, or (at your 12a47a12beSStefan Roese * option) any later version. 13a47a12beSStefan Roese */ 14a47a12beSStefan Roese 15a47a12beSStefan Roese #include <config.h> 16a47a12beSStefan Roese #include <common.h> 17a47a12beSStefan Roese #include <asm/io.h> 187e1afb62SKumar Gala #include <asm/fsl_mpc83xx_serdes.h> 19a47a12beSStefan Roese 20a47a12beSStefan Roese /* SerDes registers */ 21a47a12beSStefan Roese #define FSL_SRDSCR0_OFFS 0x0 22a47a12beSStefan Roese #define FSL_SRDSCR0_DPP_1V2 0x00008800 23*509adc8bSJerry Huang #define FSL_SRDSCR0_TXEQA_MASK 0x00007000 24*509adc8bSJerry Huang #define FSL_SRDSCR0_TXEQA_SATA 0x00001000 25*509adc8bSJerry Huang #define FSL_SRDSCR0_TXEQE_MASK 0x00000700 26*509adc8bSJerry Huang #define FSL_SRDSCR0_TXEQE_SATA 0x00000100 27a47a12beSStefan Roese #define FSL_SRDSCR1_OFFS 0x4 28a47a12beSStefan Roese #define FSL_SRDSCR1_PLLBW 0x00000040 29a47a12beSStefan Roese #define FSL_SRDSCR2_OFFS 0x8 30a47a12beSStefan Roese #define FSL_SRDSCR2_VDD_1V2 0x00800000 31a47a12beSStefan Roese #define FSL_SRDSCR2_SEIC_MASK 0x00001c1c 32a47a12beSStefan Roese #define FSL_SRDSCR2_SEIC_SATA 0x00001414 33a47a12beSStefan Roese #define FSL_SRDSCR2_SEIC_PEX 0x00001010 34a47a12beSStefan Roese #define FSL_SRDSCR2_SEIC_SGMII 0x00000101 35a47a12beSStefan Roese #define FSL_SRDSCR3_OFFS 0xc 36a47a12beSStefan Roese #define FSL_SRDSCR3_KFR_SATA 0x10100000 37a47a12beSStefan Roese #define FSL_SRDSCR3_KPH_SATA 0x04040000 38a47a12beSStefan Roese #define FSL_SRDSCR3_SDFM_SATA_PEX 0x01010000 39a47a12beSStefan Roese #define FSL_SRDSCR3_SDTXL_SATA 0x00000505 40a47a12beSStefan Roese #define FSL_SRDSCR4_OFFS 0x10 41a47a12beSStefan Roese #define FSL_SRDSCR4_PROT_SATA 0x00000808 42a47a12beSStefan Roese #define FSL_SRDSCR4_PROT_PEX 0x00000101 43a47a12beSStefan Roese #define FSL_SRDSCR4_PROT_SGMII 0x00000505 44a47a12beSStefan Roese #define FSL_SRDSCR4_PLANE_X2 0x01000000 45a47a12beSStefan Roese #define FSL_SRDSRSTCTL_OFFS 0x20 46a47a12beSStefan Roese #define FSL_SRDSRSTCTL_RST 0x80000000 47a47a12beSStefan Roese #define FSL_SRDSRSTCTL_SATA_RESET 0xf 48a47a12beSStefan Roese 49a47a12beSStefan Roese void fsl_setup_serdes(u32 offset, char proto, u32 rfcks, char vdd) 50a47a12beSStefan Roese { 51a47a12beSStefan Roese void *regs = (void *)CONFIG_SYS_IMMR + offset; 52a47a12beSStefan Roese u32 tmp; 53a47a12beSStefan Roese 54a47a12beSStefan Roese /* 1.0V corevdd */ 55a47a12beSStefan Roese if (vdd) { 56a47a12beSStefan Roese /* DPPE/DPPA = 0 */ 57a47a12beSStefan Roese tmp = in_be32(regs + FSL_SRDSCR0_OFFS); 58a47a12beSStefan Roese tmp &= ~FSL_SRDSCR0_DPP_1V2; 59a47a12beSStefan Roese out_be32(regs + FSL_SRDSCR0_OFFS, tmp); 60a47a12beSStefan Roese 61a47a12beSStefan Roese /* VDD = 0 */ 62a47a12beSStefan Roese tmp = in_be32(regs + FSL_SRDSCR2_OFFS); 63a47a12beSStefan Roese tmp &= ~FSL_SRDSCR2_VDD_1V2; 64a47a12beSStefan Roese out_be32(regs + FSL_SRDSCR2_OFFS, tmp); 65a47a12beSStefan Roese } 66a47a12beSStefan Roese 67a47a12beSStefan Roese /* protocol specific configuration */ 68a47a12beSStefan Roese switch (proto) { 69a47a12beSStefan Roese case FSL_SERDES_PROTO_SATA: 70a47a12beSStefan Roese /* Set and clear reset bits */ 71a47a12beSStefan Roese tmp = in_be32(regs + FSL_SRDSRSTCTL_OFFS); 72a47a12beSStefan Roese tmp |= FSL_SRDSRSTCTL_SATA_RESET; 73a47a12beSStefan Roese out_be32(regs + FSL_SRDSRSTCTL_OFFS, tmp); 74a47a12beSStefan Roese udelay(1000); 75a47a12beSStefan Roese tmp &= ~FSL_SRDSRSTCTL_SATA_RESET; 76a47a12beSStefan Roese out_be32(regs + FSL_SRDSRSTCTL_OFFS, tmp); 77a47a12beSStefan Roese 78*509adc8bSJerry Huang /* Configure SRDSCR0 */ 79*509adc8bSJerry Huang clrsetbits_be32(regs + FSL_SRDSCR0_OFFS, 80*509adc8bSJerry Huang FSL_SRDSCR0_TXEQA_MASK | FSL_SRDSCR0_TXEQE_MASK, 81*509adc8bSJerry Huang FSL_SRDSCR0_TXEQA_SATA | FSL_SRDSCR0_TXEQE_SATA); 82*509adc8bSJerry Huang 83a47a12beSStefan Roese /* Configure SRDSCR1 */ 84a47a12beSStefan Roese tmp = in_be32(regs + FSL_SRDSCR1_OFFS); 85a47a12beSStefan Roese tmp &= ~FSL_SRDSCR1_PLLBW; 86a47a12beSStefan Roese out_be32(regs + FSL_SRDSCR1_OFFS, tmp); 87a47a12beSStefan Roese 88a47a12beSStefan Roese /* Configure SRDSCR2 */ 89a47a12beSStefan Roese tmp = in_be32(regs + FSL_SRDSCR2_OFFS); 90a47a12beSStefan Roese tmp &= ~FSL_SRDSCR2_SEIC_MASK; 91a47a12beSStefan Roese tmp |= FSL_SRDSCR2_SEIC_SATA; 92a47a12beSStefan Roese out_be32(regs + FSL_SRDSCR2_OFFS, tmp); 93a47a12beSStefan Roese 94a47a12beSStefan Roese /* Configure SRDSCR3 */ 95a47a12beSStefan Roese tmp = FSL_SRDSCR3_KFR_SATA | FSL_SRDSCR3_KPH_SATA | 96a47a12beSStefan Roese FSL_SRDSCR3_SDFM_SATA_PEX | 97a47a12beSStefan Roese FSL_SRDSCR3_SDTXL_SATA; 98a47a12beSStefan Roese out_be32(regs + FSL_SRDSCR3_OFFS, tmp); 99a47a12beSStefan Roese 100a47a12beSStefan Roese /* Configure SRDSCR4 */ 101a47a12beSStefan Roese tmp = rfcks | FSL_SRDSCR4_PROT_SATA; 102a47a12beSStefan Roese out_be32(regs + FSL_SRDSCR4_OFFS, tmp); 103a47a12beSStefan Roese break; 104a47a12beSStefan Roese case FSL_SERDES_PROTO_PEX: 105a47a12beSStefan Roese case FSL_SERDES_PROTO_PEX_X2: 106a47a12beSStefan Roese /* Configure SRDSCR1 */ 107a47a12beSStefan Roese tmp = in_be32(regs + FSL_SRDSCR1_OFFS); 108a47a12beSStefan Roese tmp |= FSL_SRDSCR1_PLLBW; 109a47a12beSStefan Roese out_be32(regs + FSL_SRDSCR1_OFFS, tmp); 110a47a12beSStefan Roese 111a47a12beSStefan Roese /* Configure SRDSCR2 */ 112a47a12beSStefan Roese tmp = in_be32(regs + FSL_SRDSCR2_OFFS); 113a47a12beSStefan Roese tmp &= ~FSL_SRDSCR2_SEIC_MASK; 114a47a12beSStefan Roese tmp |= FSL_SRDSCR2_SEIC_PEX; 115a47a12beSStefan Roese out_be32(regs + FSL_SRDSCR2_OFFS, tmp); 116a47a12beSStefan Roese 117a47a12beSStefan Roese /* Configure SRDSCR3 */ 118a47a12beSStefan Roese tmp = FSL_SRDSCR3_SDFM_SATA_PEX; 119a47a12beSStefan Roese out_be32(regs + FSL_SRDSCR3_OFFS, tmp); 120a47a12beSStefan Roese 121a47a12beSStefan Roese /* Configure SRDSCR4 */ 122a47a12beSStefan Roese tmp = rfcks | FSL_SRDSCR4_PROT_PEX; 123a47a12beSStefan Roese if (proto == FSL_SERDES_PROTO_PEX_X2) 124a47a12beSStefan Roese tmp |= FSL_SRDSCR4_PLANE_X2; 125a47a12beSStefan Roese out_be32(regs + FSL_SRDSCR4_OFFS, tmp); 126a47a12beSStefan Roese break; 127a47a12beSStefan Roese case FSL_SERDES_PROTO_SGMII: 128a47a12beSStefan Roese /* Configure SRDSCR1 */ 129a47a12beSStefan Roese tmp = in_be32(regs + FSL_SRDSCR1_OFFS); 130a47a12beSStefan Roese tmp &= ~FSL_SRDSCR1_PLLBW; 131a47a12beSStefan Roese out_be32(regs + FSL_SRDSCR1_OFFS, tmp); 132a47a12beSStefan Roese 133a47a12beSStefan Roese /* Configure SRDSCR2 */ 134a47a12beSStefan Roese tmp = in_be32(regs + FSL_SRDSCR2_OFFS); 135a47a12beSStefan Roese tmp &= ~FSL_SRDSCR2_SEIC_MASK; 136a47a12beSStefan Roese tmp |= FSL_SRDSCR2_SEIC_SGMII; 137a47a12beSStefan Roese out_be32(regs + FSL_SRDSCR2_OFFS, tmp); 138a47a12beSStefan Roese 139a47a12beSStefan Roese /* Configure SRDSCR3 */ 140a47a12beSStefan Roese out_be32(regs + FSL_SRDSCR3_OFFS, 0); 141a47a12beSStefan Roese 142a47a12beSStefan Roese /* Configure SRDSCR4 */ 143a47a12beSStefan Roese tmp = rfcks | FSL_SRDSCR4_PROT_SGMII; 144a47a12beSStefan Roese out_be32(regs + FSL_SRDSCR4_OFFS, tmp); 145a47a12beSStefan Roese break; 146a47a12beSStefan Roese default: 147a47a12beSStefan Roese return; 148a47a12beSStefan Roese } 149a47a12beSStefan Roese 150a47a12beSStefan Roese /* Do a software reset */ 151a47a12beSStefan Roese tmp = in_be32(regs + FSL_SRDSRSTCTL_OFFS); 152a47a12beSStefan Roese tmp |= FSL_SRDSRSTCTL_RST; 153a47a12beSStefan Roese out_be32(regs + FSL_SRDSRSTCTL_OFFS, tmp); 154a47a12beSStefan Roese } 155