| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
#include "ad9152.h" |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
int32_t ad9152_spi_read(spi_device *dev, |
| 49 |
uint16_t reg_addr, |
| 50 |
uint8_t *reg_data) |
| 51 |
{ |
| 52 |
uint8_t buf[3]; |
| 53 |
int32_t ret; |
| 54 |
|
| 55 |
buf[0] = 0x80 | (reg_addr >> 8); |
| 56 |
buf[1] = reg_addr & 0xFF; |
| 57 |
buf[2] = 0x00; |
| 58 |
|
| 59 |
ret = ad_spi_xfer(dev, buf, 3); |
| 60 |
*reg_data = buf[2]; |
| 61 |
|
| 62 |
return ret; |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
int32_t ad9152_spi_write(spi_device *dev, |
| 69 |
uint16_t reg_addr, |
| 70 |
uint8_t reg_data) |
| 71 |
{ |
| 72 |
uint8_t buf[3]; |
| 73 |
int32_t ret; |
| 74 |
|
| 75 |
buf[0] = reg_addr >> 8; |
| 76 |
buf[1] = reg_addr & 0xFF; |
| 77 |
buf[2] = reg_data; |
| 78 |
|
| 79 |
ret = ad_spi_xfer(dev, buf, 3); |
| 80 |
|
| 81 |
return ret; |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
int32_t ad9152_setup(spi_device *dev, |
| 88 |
ad9152_init_param init_param) |
| 89 |
{ |
| 90 |
uint8_t chip_id; |
| 91 |
uint8_t pll_stat; |
| 92 |
int32_t ret; |
| 93 |
|
| 94 |
ret = 0; |
| 95 |
|
| 96 |
ad9152_spi_read(dev, REG_SPI_PRODIDL, &chip_id); |
| 97 |
if(chip_id != AD9152_CHIP_ID) |
| 98 |
{ |
| 99 |
ad_printf("AD9152: Invalid CHIP ID (0x%x)!\n", chip_id); |
| 100 |
return -1; |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
mdelay(5); |
| 105 |
|
| 106 |
ad9152_spi_write(dev, REG_SPI_INTFCONFA, SOFTRESET_M | SOFTRESET); |
| 107 |
ad9152_spi_write(dev, REG_SPI_INTFCONFA, 0x00); |
| 108 |
|
| 109 |
mdelay(4); |
| 110 |
|
| 111 |
ad9152_spi_write(dev, 0x011, 0x00); |
| 112 |
ad9152_spi_write(dev, 0x080, 0x00); |
| 113 |
ad9152_spi_write(dev, 0x081, 0x00); |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
ad9152_spi_write(dev, 0x112, 0x00); |
| 118 |
ad9152_spi_write(dev, 0x110, 0x00); |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
ad9152_spi_write(dev, 0x200, 0x00); |
| 123 |
ad9152_spi_write(dev, 0x201, 0x00); |
| 124 |
ad9152_spi_write(dev, 0x230, 0x28); |
| 125 |
ad9152_spi_write(dev, 0x312, 0x20); |
| 126 |
ad9152_spi_write(dev, 0x300, 0x01); |
| 127 |
ad9152_spi_write(dev, 0x450, 0x00); |
| 128 |
ad9152_spi_write(dev, 0x451, 0x00); |
| 129 |
ad9152_spi_write(dev, 0x452, 0x04); |
| 130 |
ad9152_spi_write(dev, 0x453, 0x83); |
| 131 |
ad9152_spi_write(dev, 0x454, 0x00); |
| 132 |
ad9152_spi_write(dev, 0x455, 0x1f); |
| 133 |
ad9152_spi_write(dev, 0x456, 0x01); |
| 134 |
ad9152_spi_write(dev, 0x457, 0x0f); |
| 135 |
ad9152_spi_write(dev, 0x458, 0x2f); |
| 136 |
ad9152_spi_write(dev, 0x459, 0x20); |
| 137 |
ad9152_spi_write(dev, 0x45a, 0x80); |
| 138 |
ad9152_spi_write(dev, 0x45d, 0x49); |
| 139 |
ad9152_spi_write(dev, 0x478, 0x01); |
| 140 |
ad9152_spi_write(dev, 0x46c, 0x0f); |
| 141 |
ad9152_spi_write(dev, 0x476, 0x01); |
| 142 |
ad9152_spi_write(dev, 0x47d, 0x0f); |
| 143 |
|
| 144 |
|
| 145 |
ad9152_spi_write(dev, 0x2a6, 0x08); |
| 146 |
ad9152_spi_write(dev, 0x248, 0xaa); |
| 147 |
ad9152_spi_write(dev, 0x2aa, 0xb7); |
| 148 |
ad9152_spi_write(dev, 0x2ab, 0x87); |
| 149 |
ad9152_spi_write(dev, 0x2a7, 0x01); |
| 150 |
ad9152_spi_write(dev, 0x314, 0x01); |
| 151 |
ad9152_spi_write(dev, 0x230, 0x28); |
| 152 |
ad9152_spi_write(dev, 0x206, 0x00); |
| 153 |
ad9152_spi_write(dev, 0x206, 0x01); |
| 154 |
ad9152_spi_write(dev, 0x289, 0x04); |
| 155 |
ad9152_spi_write(dev, 0x280, 0x01); |
| 156 |
ad9152_spi_write(dev, 0x280, 0x05); |
| 157 |
mdelay(20); |
| 158 |
|
| 159 |
ad9152_spi_read(dev, 0x281, &pll_stat); |
| 160 |
if (pll_stat == 0) |
| 161 |
{ |
| 162 |
ad_printf("AD9152: PLL is NOT locked!.\n"); |
| 163 |
ret = -1; |
| 164 |
} |
| 165 |
|
| 166 |
ad9152_spi_write(dev, 0x268, 0x62); |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
ad9152_spi_write(dev, 0x301, 0x01); |
| 172 |
ad9152_spi_write(dev, 0x304, 0x00); |
| 173 |
ad9152_spi_write(dev, 0x306, 0x0a); |
| 174 |
ad9152_spi_write(dev, 0x03a, 0x01); |
| 175 |
ad9152_spi_write(dev, 0x03a, 0x81); |
| 176 |
ad9152_spi_write(dev, 0x03a, 0xc1); |
| 177 |
ad9152_spi_write(dev, 0x300, 0x01); |
| 178 |
|
| 179 |
ad9152_spi_write(dev, 0x0e7, 0x30); |
| 180 |
|
| 181 |
return ret; |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
int32_t ad9152_short_pattern_test(spi_device *dev, ad9152_init_param init_param) |
| 189 |
{ |
| 190 |
uint32_t dac; |
| 191 |
uint32_t sample; |
| 192 |
uint8_t status; |
| 193 |
|
| 194 |
status = 0; |
| 195 |
|
| 196 |
for (dac = 0; dac < 2; dac++) { |
| 197 |
for (sample = 0; sample < 4; sample++) { |
| 198 |
ad9152_spi_write(dev, 0x32c, ((sample << 4) | (dac << 2) | 0x00)); |
| 199 |
ad9152_spi_write(dev, 0x32e, (init_param.stpl_samples[dac][sample]>>8)); |
| 200 |
ad9152_spi_write(dev, 0x32d, (init_param.stpl_samples[dac][sample]>>0)); |
| 201 |
ad9152_spi_write(dev, 0x32c, ((sample << 4) | (dac << 2) | 0x01)); |
| 202 |
ad9152_spi_write(dev, 0x32c, ((sample << 4) | (dac << 2) | 0x03)); |
| 203 |
ad9152_spi_write(dev, 0x32c, ((sample << 4) | (dac << 2) | 0x01)); |
| 204 |
mdelay(1); |
| 205 |
|
| 206 |
ad9152_spi_read(dev, 0x32f, &status); |
| 207 |
if ((status & 0x1) == 0x1) |
| 208 |
ad_printf("AD9152: short-pattern-test mismatch (%x, %d, %d, %x)!.\n", |
| 209 |
dac, sample, init_param.stpl_samples[dac][sample], status); |
| 210 |
} |
| 211 |
} |
| 212 |
return(0); |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
int32_t ad9152_datapath_prbs_test(spi_device *dev, ad9152_init_param init_param) |
| 220 |
{ |
| 221 |
|
| 222 |
uint8_t status; |
| 223 |
int32_t ret; |
| 224 |
|
| 225 |
status = 0; |
| 226 |
ret = 0; |
| 227 |
|
| 228 |
if (init_param.interpolation == 1) |
| 229 |
return(ret); |
| 230 |
|
| 231 |
ad9152_spi_write(dev, REG_PRBS, ((init_param.prbs_type << 2) | 0x03)); |
| 232 |
ad9152_spi_write(dev, REG_PRBS, ((init_param.prbs_type << 2) | 0x01)); |
| 233 |
mdelay(100); |
| 234 |
|
| 235 |
ad9152_spi_read(dev, REG_PRBS, &status); |
| 236 |
if ((status & 0xc0) != 0xc0) |
| 237 |
{ |
| 238 |
ad_printf("AD9152: PRBS OUT OF SYNC (%x)!.\n", status); |
| 239 |
ret = -1; |
| 240 |
} |
| 241 |
ad9152_spi_read(dev, REG_PRBS_ERROR_I, &status); |
| 242 |
if (status != 0x00) |
| 243 |
{ |
| 244 |
ad_printf("AD9152: PRBS I channel ERRORS (%x)!.\n", status); |
| 245 |
ret = -1; |
| 246 |
} |
| 247 |
ad9152_spi_read(dev, REG_PRBS_ERROR_Q, &status); |
| 248 |
if (status != 0x00) |
| 249 |
{ |
| 250 |
ad_printf("AD9152: PRBS Q channel ERRORS (%x)!.\n", status); |
| 251 |
ret = -1; |
| 252 |
} |
| 253 |
|
| 254 |
return(ret); |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
int32_t ad9152_status(spi_device *dev) |
| 262 |
{ |
| 263 |
|
| 264 |
uint8_t status; |
| 265 |
int32_t ret; |
| 266 |
|
| 267 |
status = 0; |
| 268 |
ret = 0; |
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
ad9152_spi_read(dev, REG_CODEGRPSYNCFLG, &status); |
| 274 |
if (status != 0x0f) |
| 275 |
{ |
| 276 |
ad_printf("AD9152: CGS NOT received (%x)!.\n", status); |
| 277 |
ret = -1; |
| 278 |
} |
| 279 |
ad9152_spi_read(dev, REG_INITLANESYNCFLG, &status); |
| 280 |
if (status != 0x0f) |
| 281 |
{ |
| 282 |
ad_printf("AD9152: ILAS NOT received (%x)!.\n", status); |
| 283 |
ret = -1; |
| 284 |
} |
| 285 |
ad9152_spi_read(dev, REG_FRAMESYNCFLG, &status); |
| 286 |
if (status != 0x0f) |
| 287 |
{ |
| 288 |
ad_printf("AD9152: framer OUT OF SYNC (%x)!.\n", status); |
| 289 |
ret = -1; |
| 290 |
} |
| 291 |
ad9152_spi_read(dev, REG_GOODCHKSUMFLG, &status); |
| 292 |
if (status != 0x0f) |
| 293 |
{ |
| 294 |
ad_printf("AD9152: check-sum MISMATCH (%x)!.\n", status); |
| 295 |
ret = -1; |
| 296 |
} |
| 297 |
|
| 298 |
return(ret); |
| 299 |
} |
| 300 |
|