| 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 "ad9144.h" |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
int32_t ad9144_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 ad9144_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 ad9144_setup(spi_device *dev, |
| 88 |
ad9144_init_param init_param) |
| 89 |
{ |
| 90 |
uint8_t chip_id; |
| 91 |
uint8_t scratchpad; |
| 92 |
uint8_t pll_stat; |
| 93 |
uint8_t cal_stat; |
| 94 |
int32_t ret; |
| 95 |
|
| 96 |
ad9144_spi_read(dev, REG_SPI_PRODIDL, &chip_id); |
| 97 |
if(chip_id != AD9144_CHIP_ID) |
| 98 |
{ |
| 99 |
ad_printf("%s : Invalid CHIP ID (0x%x).\n", __func__, chip_id); |
| 100 |
return -1; |
| 101 |
} |
| 102 |
|
| 103 |
ad9144_spi_write(dev, REG_SPI_SCRATCHPAD, 0xAD); |
| 104 |
ad9144_spi_read(dev, REG_SPI_SCRATCHPAD, &scratchpad); |
| 105 |
if(scratchpad != 0xAD) |
| 106 |
{ |
| 107 |
ad_printf("%s : scratchpad read-write failed (0x%x)!\n", __func__, scratchpad); |
| 108 |
return -1; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
ad9144_spi_write(dev, REG_SPI_INTFCONFA, SOFTRESET_M | SOFTRESET); |
| 114 |
ad9144_spi_write(dev, REG_SPI_INTFCONFA, 0x00); |
| 115 |
mdelay(1); |
| 116 |
|
| 117 |
ad9144_spi_write(dev, 0x011, 0x00); |
| 118 |
ad9144_spi_write(dev, 0x080, 0x00); |
| 119 |
ad9144_spi_write(dev, 0x081, 0x00); |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
ad9144_spi_write(dev, 0x12d, 0x8b); |
| 124 |
ad9144_spi_write(dev, 0x146, 0x01); |
| 125 |
ad9144_spi_write(dev, 0x2a4, 0xff); |
| 126 |
ad9144_spi_write(dev, 0x1c4, 0x73); |
| 127 |
ad9144_spi_write(dev, 0x291, 0x49); |
| 128 |
ad9144_spi_write(dev, 0x29c, 0x24); |
| 129 |
ad9144_spi_write(dev, 0x29f, 0x73); |
| 130 |
ad9144_spi_write(dev, 0x232, 0xff); |
| 131 |
ad9144_spi_write(dev, 0x333, 0x01); |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
ad9144_spi_write(dev, 0x112, 0x00); |
| 136 |
ad9144_spi_write(dev, 0x110, 0x00); |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
ad9144_spi_write(dev, 0x200, 0x00); |
| 141 |
ad9144_spi_write(dev, 0x201, 0x00); |
| 142 |
ad9144_spi_write(dev, 0x300, 0x01); |
| 143 |
ad9144_spi_write(dev, 0x450, 0x00); |
| 144 |
ad9144_spi_write(dev, 0x451, 0x00); |
| 145 |
ad9144_spi_write(dev, 0x452, 0x04); |
| 146 |
ad9144_spi_write(dev, 0x453, 0x83); |
| 147 |
ad9144_spi_write(dev, 0x454, 0x00); |
| 148 |
ad9144_spi_write(dev, 0x455, 0x1f); |
| 149 |
ad9144_spi_write(dev, 0x456, 0x01); |
| 150 |
ad9144_spi_write(dev, 0x457, 0x0f); |
| 151 |
ad9144_spi_write(dev, 0x458, 0x2f); |
| 152 |
ad9144_spi_write(dev, 0x459, 0x20); |
| 153 |
ad9144_spi_write(dev, 0x45a, 0x80); |
| 154 |
ad9144_spi_write(dev, 0x45d, 0x49); |
| 155 |
ad9144_spi_write(dev, 0x46c, 0x0f); |
| 156 |
ad9144_spi_write(dev, 0x476, 0x01); |
| 157 |
ad9144_spi_write(dev, 0x47d, 0x0f); |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
ad9144_spi_write(dev, 0x2aa, 0xb7); |
| 162 |
ad9144_spi_write(dev, 0x2ab, 0x87); |
| 163 |
ad9144_spi_write(dev, 0x2b1, 0xb7); |
| 164 |
ad9144_spi_write(dev, 0x2b2, 0x87); |
| 165 |
ad9144_spi_write(dev, 0x2a7, 0x01); |
| 166 |
ad9144_spi_write(dev, 0x2ae, 0x01); |
| 167 |
ad9144_spi_write(dev, 0x314, 0x01); |
| 168 |
if (init_param.lane_rate_kbps < 2880000) |
| 169 |
ad9144_spi_write(dev, 0x230, 0x2A); |
| 170 |
else |
| 171 |
if (init_param.lane_rate_kbps > 5520000) |
| 172 |
ad9144_spi_write(dev, 0x230, 0x28); |
| 173 |
else |
| 174 |
ad9144_spi_write(dev, 0x230, 0x08); |
| 175 |
ad9144_spi_write(dev, 0x206, 0x00); |
| 176 |
ad9144_spi_write(dev, 0x206, 0x01); |
| 177 |
if (init_param.lane_rate_kbps < 2880000) |
| 178 |
ad9144_spi_write(dev, 0x289, 0x06); |
| 179 |
else |
| 180 |
if (init_param.lane_rate_kbps > 5520000) |
| 181 |
ad9144_spi_write(dev, 0x289, 0x04); |
| 182 |
else |
| 183 |
ad9144_spi_write(dev, 0x289, 0x05); |
| 184 |
ad9144_spi_write(dev, 0x280, 0x01); |
| 185 |
ad9144_spi_write(dev, 0x280, 0x05); |
| 186 |
mdelay(20); |
| 187 |
|
| 188 |
ad9144_spi_read(dev, 0x281, &pll_stat); |
| 189 |
if ((pll_stat & 0x01) != 0x01) |
| 190 |
ad_printf("%s : PLL NOT locked!.\n", __func__); |
| 191 |
|
| 192 |
ad9144_spi_write(dev, 0x268, 0x62); |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
ad9144_spi_write(dev, 0x301, 0x01); |
| 197 |
ad9144_spi_write(dev, 0x304, 0x00); |
| 198 |
ad9144_spi_write(dev, 0x305, 0x00); |
| 199 |
ad9144_spi_write(dev, 0x306, 0x0a); |
| 200 |
ad9144_spi_write(dev, 0x307, 0x0a); |
| 201 |
ad9144_spi_write(dev, 0x03a, 0x01); |
| 202 |
ad9144_spi_write(dev, 0x03a, 0x81); |
| 203 |
ad9144_spi_write(dev, 0x03a, 0xc1); |
| 204 |
ad9144_spi_write(dev, 0x300, 0x01); |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
ad9144_spi_write(dev, 0x0e7, 0x38); |
| 209 |
ad9144_spi_write(dev, 0x0ed, 0xa6); |
| 210 |
ad9144_spi_write(dev, 0x0e8, 0x03); |
| 211 |
ad9144_spi_write(dev, 0x0e9, 0x01); |
| 212 |
ad9144_spi_write(dev, 0x0e9, 0x03); |
| 213 |
mdelay(10); |
| 214 |
|
| 215 |
ad9144_spi_write(dev, 0x0e8, 0x01); |
| 216 |
ad9144_spi_read(dev, 0x0e9, &cal_stat); |
| 217 |
if ((cal_stat & 0xc0) != 0x80) |
| 218 |
ad_printf("%s : dac-0 calibration failed!\n", __func__); |
| 219 |
|
| 220 |
ad9144_spi_write(dev, 0x0e8, 0x02); |
| 221 |
ad9144_spi_read(dev, 0x0e9, &cal_stat); |
| 222 |
if ((cal_stat & 0xc0) != 0x80) |
| 223 |
ad_printf("%s : dac-1 calibration failed!\n", __func__); |
| 224 |
|
| 225 |
ad9144_spi_write(dev, 0x0e7, 0x30); |
| 226 |
|
| 227 |
return ret; |
| 228 |
} |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
int32_t ad9144_status(spi_device *dev) { |
| 234 |
|
| 235 |
uint8_t status = 0; |
| 236 |
int32_t ret = 0; |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
ad9144_spi_read(dev, REG_CODEGRPSYNCFLG, &status); |
| 242 |
if (status != 0x0f) |
| 243 |
{ |
| 244 |
ad_printf("%s : CGS NOT received (%x)!.\n", __func__, status); |
| 245 |
ret = -1; |
| 246 |
} |
| 247 |
ad9144_spi_read(dev, REG_INITLANESYNCFLG, &status); |
| 248 |
if (status != 0x0f) |
| 249 |
{ |
| 250 |
ad_printf("%s : ILAS NOT received (%x)!.\n", __func__, status); |
| 251 |
ret = -1; |
| 252 |
} |
| 253 |
ad9144_spi_read(dev, REG_FRAMESYNCFLG, &status); |
| 254 |
if (status != 0x0f) |
| 255 |
{ |
| 256 |
ad_printf("%s : framer OUT OF SYNC (%x)!.\n", __func__, status); |
| 257 |
ret = -1; |
| 258 |
} |
| 259 |
ad9144_spi_read(dev, REG_GOODCHKSUMFLG, &status); |
| 260 |
if (status != 0x0f) |
| 261 |
{ |
| 262 |
ad_printf("%s : check-sum MISMATCH (%x)!.\n", __func__, status); |
| 263 |
ret = -1; |
| 264 |
} |
| 265 |
|
| 266 |
return ret; |
| 267 |
} |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
int32_t ad9144_short_pattern_test(spi_device *dev, ad9144_init_param init_param) { |
| 273 |
|
| 274 |
uint32_t dac = 0; |
| 275 |
uint32_t sample = 0; |
| 276 |
uint8_t status = 0; |
| 277 |
|
| 278 |
for (dac = 0; dac < init_param.active_converters; dac++) { |
| 279 |
for (sample = 0; sample < 4; sample++) { |
| 280 |
ad9144_spi_write(dev, 0x32c, ((sample << 4) | (dac << 2) | 0x00)); |
| 281 |
ad9144_spi_write(dev, 0x32e, (init_param.stpl_samples[dac][sample]>>8)); |
| 282 |
ad9144_spi_write(dev, 0x32d, (init_param.stpl_samples[dac][sample]>>0)); |
| 283 |
ad9144_spi_write(dev, 0x32c, ((sample << 4) | (dac << 2) | 0x01)); |
| 284 |
ad9144_spi_write(dev, 0x32c, ((sample << 4) | (dac << 2) | 0x03)); |
| 285 |
ad9144_spi_write(dev, 0x32c, ((sample << 4) | (dac << 2) | 0x01)); |
| 286 |
mdelay(1); |
| 287 |
|
| 288 |
ad9144_spi_read(dev, 0x32f, &status); |
| 289 |
if ((status & 0x1) == 0x1) |
| 290 |
ad_printf("%s : short-pattern-test mismatch (0x%x, 0x%x 0x%x, 0x%x)!.\n", |
| 291 |
__func__, dac, sample, init_param.stpl_samples[dac][sample], status); |
| 292 |
} |
| 293 |
} |
| 294 |
return 0; |
| 295 |
} |
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
int32_t ad9144_datapath_prbs_test(spi_device *dev, ad9144_init_param init_param) { |
| 301 |
|
| 302 |
uint8_t status = 0; |
| 303 |
int32_t ret = 0; |
| 304 |
|
| 305 |
|
| 306 |
ad9144_spi_write(dev, REG_PRBS, ((init_param.prbs_type << 2) | 0x03)); |
| 307 |
ad9144_spi_write(dev, REG_PRBS, ((init_param.prbs_type << 2) | 0x01)); |
| 308 |
mdelay(500); |
| 309 |
|
| 310 |
ad9144_spi_write(dev, REG_SPI_PAGEINDX, 0x01); |
| 311 |
ad9144_spi_read(dev, REG_PRBS, &status); |
| 312 |
if ((status & 0xc0) != 0xc0) |
| 313 |
{ |
| 314 |
ad_printf("%s : PRBS OUT OF SYNC (%x)!.\n", __func__, status); |
| 315 |
ret = -1; |
| 316 |
} |
| 317 |
ad9144_spi_read(dev, REG_PRBS_ERROR_I, &status); |
| 318 |
if (status != 0x00) |
| 319 |
{ |
| 320 |
ad_printf("%s : PRBS I channel ERRORS (%x)!.\n", __func__, status); |
| 321 |
ret = -1; |
| 322 |
} |
| 323 |
ad9144_spi_read(dev, REG_PRBS_ERROR_Q, &status); |
| 324 |
if (status != 0x00) |
| 325 |
{ |
| 326 |
ad_printf("%s : PRBS Q channel ERRORS (%x)!.\n", __func__, status); |
| 327 |
ret = -1; |
| 328 |
} |
| 329 |
|
| 330 |
return ret; |
| 331 |
} |
| 332 |
|