| 1 |
|
| 2 |
|
| 3 |
#ifndef _ZL3073X_CORE_H |
| 4 |
#define _ZL3073X_CORE_H |
| 5 |
|
| 6 |
#include <linux/bitfield.h> |
| 7 |
#include <linux/kthread.h> |
| 8 |
#include <linux/list.h> |
| 9 |
#include <linux/mutex.h> |
| 10 |
#include <linux/types.h> |
| 11 |
|
| 12 |
#include "out.h" |
| 13 |
#include "ref.h" |
| 14 |
#include "regs.h" |
| 15 |
#include "synth.h" |
| 16 |
|
| 17 |
struct device; |
| 18 |
struct regmap; |
| 19 |
struct zl3073x_dpll; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#define ZL3073X_MAX_CHANNELS 5 |
| 25 |
#define ZL3073X_NUM_REFS 10 |
| 26 |
#define ZL3073X_NUM_OUTS 10 |
| 27 |
#define ZL3073X_NUM_SYNTHS 5 |
| 28 |
#define ZL3073X_NUM_INPUT_PINS ZL3073X_NUM_REFS |
| 29 |
#define ZL3073X_NUM_OUTPUT_PINS (ZL3073X_NUM_OUTS * 2) |
| 30 |
#define ZL3073X_NUM_PINS (ZL3073X_NUM_INPUT_PINS + \ |
| 31 |
ZL3073X_NUM_OUTPUT_PINS) |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
struct zl3073x_dev { |
| 49 |
struct device *dev; |
| 50 |
struct regmap *regmap; |
| 51 |
struct mutex multiop_lock; |
| 52 |
u16 chip_id; |
| 53 |
|
| 54 |
|
| 55 |
struct zl3073x_ref ref[ZL3073X_NUM_REFS]; |
| 56 |
struct zl3073x_out out[ZL3073X_NUM_OUTS]; |
| 57 |
struct zl3073x_synth synth[ZL3073X_NUM_SYNTHS]; |
| 58 |
|
| 59 |
|
| 60 |
struct list_head dplls; |
| 61 |
|
| 62 |
|
| 63 |
struct kthread_worker *kworker; |
| 64 |
struct kthread_delayed_work work; |
| 65 |
|
| 66 |
|
| 67 |
u64 clock_id; |
| 68 |
u8 phase_avg_factor; |
| 69 |
}; |
| 70 |
|
| 71 |
struct zl3073x_chip_info { |
| 72 |
const u16 *ids; |
| 73 |
size_t num_ids; |
| 74 |
int num_channels; |
| 75 |
}; |
| 76 |
|
| 77 |
extern const struct zl3073x_chip_info zl30731_chip_info; |
| 78 |
extern const struct zl3073x_chip_info zl30732_chip_info; |
| 79 |
extern const struct zl3073x_chip_info zl30733_chip_info; |
| 80 |
extern const struct zl3073x_chip_info zl30734_chip_info; |
| 81 |
extern const struct zl3073x_chip_info zl30735_chip_info; |
| 82 |
extern const struct regmap_config zl3073x_regmap_config; |
| 83 |
|
| 84 |
struct zl3073x_dev *zl3073x_devm_alloc(struct device *dev); |
| 85 |
int zl3073x_dev_probe(struct zl3073x_dev *zldev, |
| 86 |
const struct zl3073x_chip_info *chip_info); |
| 87 |
|
| 88 |
int zl3073x_dev_start(struct zl3073x_dev *zldev, bool full); |
| 89 |
void zl3073x_dev_stop(struct zl3073x_dev *zldev); |
| 90 |
|
| 91 |
static inline u8 zl3073x_dev_phase_avg_factor_get(struct zl3073x_dev *zldev) |
| 92 |
{ |
| 93 |
return zldev->phase_avg_factor; |
| 94 |
} |
| 95 |
|
| 96 |
int zl3073x_dev_phase_avg_factor_set(struct zl3073x_dev *zldev, u8 factor); |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
struct zl3073x_hwreg_seq_item { |
| 110 |
u32 addr; |
| 111 |
u32 value; |
| 112 |
u32 mask; |
| 113 |
u32 wait; |
| 114 |
}; |
| 115 |
|
| 116 |
#define HWREG_SEQ_ITEM(_addr, _value, _mask, _wait) \ |
| 117 |
{ \ |
| 118 |
.addr = _addr, \ |
| 119 |
.value = FIELD_PREP_CONST(_mask, _value), \ |
| 120 |
.mask = _mask, \ |
| 121 |
.wait = _wait, \ |
| 122 |
} |
| 123 |
|
| 124 |
int zl3073x_mb_op(struct zl3073x_dev *zldev, unsigned int op_reg, u8 op_val, |
| 125 |
unsigned int mask_reg, u16 mask_val); |
| 126 |
int zl3073x_poll_zero_u8(struct zl3073x_dev *zldev, unsigned int reg, u8 mask); |
| 127 |
int zl3073x_read_u8(struct zl3073x_dev *zldev, unsigned int reg, u8 *val); |
| 128 |
int zl3073x_read_u16(struct zl3073x_dev *zldev, unsigned int reg, u16 *val); |
| 129 |
int zl3073x_read_u32(struct zl3073x_dev *zldev, unsigned int reg, u32 *val); |
| 130 |
int zl3073x_read_u48(struct zl3073x_dev *zldev, unsigned int reg, u64 *val); |
| 131 |
int zl3073x_write_u8(struct zl3073x_dev *zldev, unsigned int reg, u8 val); |
| 132 |
int zl3073x_write_u16(struct zl3073x_dev *zldev, unsigned int reg, u16 val); |
| 133 |
int zl3073x_write_u32(struct zl3073x_dev *zldev, unsigned int reg, u32 val); |
| 134 |
int zl3073x_write_u48(struct zl3073x_dev *zldev, unsigned int reg, u64 val); |
| 135 |
int zl3073x_read_hwreg(struct zl3073x_dev *zldev, u32 addr, u32 *value); |
| 136 |
int zl3073x_write_hwreg(struct zl3073x_dev *zldev, u32 addr, u32 value); |
| 137 |
int zl3073x_update_hwreg(struct zl3073x_dev *zldev, u32 addr, u32 value, |
| 138 |
u32 mask); |
| 139 |
int zl3073x_write_hwreg_seq(struct zl3073x_dev *zldev, |
| 140 |
const struct zl3073x_hwreg_seq_item *seq, |
| 141 |
size_t num_items); |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
int zl3073x_ref_phase_offsets_update(struct zl3073x_dev *zldev, int channel); |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
static inline bool |
| 159 |
zl3073x_dev_is_ref_phase_comp_32bit(struct zl3073x_dev *zldev) |
| 160 |
{ |
| 161 |
switch (zldev->chip_id) { |
| 162 |
case 0x0E30: |
| 163 |
case 0x0E93: |
| 164 |
case 0x0E94: |
| 165 |
case 0x0E95: |
| 166 |
case 0x0E96: |
| 167 |
case 0x0E97: |
| 168 |
case 0x1F60: |
| 169 |
return true; |
| 170 |
default: |
| 171 |
return false; |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
static inline bool |
| 176 |
zl3073x_is_n_pin(u8 id) |
| 177 |
{ |
| 178 |
|
| 179 |
return id & 1; |
| 180 |
} |
| 181 |
|
| 182 |
static inline bool |
| 183 |
zl3073x_is_p_pin(u8 id) |
| 184 |
{ |
| 185 |
return !zl3073x_is_n_pin(id); |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
static inline u8 |
| 195 |
zl3073x_input_pin_ref_get(u8 id) |
| 196 |
{ |
| 197 |
return id; |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
static inline u8 |
| 207 |
zl3073x_output_pin_out_get(u8 id) |
| 208 |
{ |
| 209 |
|
| 210 |
return id / 2; |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
static inline u32 |
| 221 |
zl3073x_dev_ref_freq_get(struct zl3073x_dev *zldev, u8 index) |
| 222 |
{ |
| 223 |
const struct zl3073x_ref *ref = zl3073x_ref_state_get(zldev, index); |
| 224 |
|
| 225 |
return zl3073x_ref_freq_get(ref); |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
static inline bool |
| 236 |
zl3073x_dev_ref_is_diff(struct zl3073x_dev *zldev, u8 index) |
| 237 |
{ |
| 238 |
const struct zl3073x_ref *ref = zl3073x_ref_state_get(zldev, index); |
| 239 |
|
| 240 |
return zl3073x_ref_is_diff(ref); |
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
static inline bool |
| 251 |
zl3073x_dev_ref_is_status_ok(struct zl3073x_dev *zldev, u8 index) |
| 252 |
{ |
| 253 |
const struct zl3073x_ref *ref = zl3073x_ref_state_get(zldev, index); |
| 254 |
|
| 255 |
return zl3073x_ref_is_status_ok(ref); |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
static inline u32 |
| 266 |
zl3073x_dev_synth_freq_get(struct zl3073x_dev *zldev, u8 index) |
| 267 |
{ |
| 268 |
const struct zl3073x_synth *synth; |
| 269 |
|
| 270 |
synth = zl3073x_synth_state_get(zldev, index); |
| 271 |
return zl3073x_synth_freq_get(synth); |
| 272 |
} |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
static inline u8 |
| 282 |
zl3073x_dev_out_synth_get(struct zl3073x_dev *zldev, u8 index) |
| 283 |
{ |
| 284 |
const struct zl3073x_out *out = zl3073x_out_state_get(zldev, index); |
| 285 |
|
| 286 |
return zl3073x_out_synth_get(out); |
| 287 |
} |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
static inline bool |
| 297 |
zl3073x_dev_out_is_enabled(struct zl3073x_dev *zldev, u8 index) |
| 298 |
{ |
| 299 |
const struct zl3073x_out *out = zl3073x_out_state_get(zldev, index); |
| 300 |
const struct zl3073x_synth *synth; |
| 301 |
u8 synth_id; |
| 302 |
|
| 303 |
|
| 304 |
synth_id = zl3073x_out_synth_get(out); |
| 305 |
synth = zl3073x_synth_state_get(zldev, synth_id); |
| 306 |
|
| 307 |
return zl3073x_synth_is_enabled(synth) && zl3073x_out_is_enabled(out); |
| 308 |
} |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
static inline |
| 318 |
u8 zl3073x_dev_out_dpll_get(struct zl3073x_dev *zldev, u8 index) |
| 319 |
{ |
| 320 |
const struct zl3073x_out *out = zl3073x_out_state_get(zldev, index); |
| 321 |
const struct zl3073x_synth *synth; |
| 322 |
u8 synth_id; |
| 323 |
|
| 324 |
|
| 325 |
synth_id = zl3073x_out_synth_get(out); |
| 326 |
synth = zl3073x_synth_state_get(zldev, synth_id); |
| 327 |
|
| 328 |
|
| 329 |
return zl3073x_synth_dpll_get(synth); |
| 330 |
} |
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
static inline u32 |
| 344 |
zl3073x_dev_output_pin_freq_get(struct zl3073x_dev *zldev, u8 id) |
| 345 |
{ |
| 346 |
const struct zl3073x_synth *synth; |
| 347 |
const struct zl3073x_out *out; |
| 348 |
u8 out_id; |
| 349 |
u32 freq; |
| 350 |
|
| 351 |
out_id = zl3073x_output_pin_out_get(id); |
| 352 |
out = zl3073x_out_state_get(zldev, out_id); |
| 353 |
synth = zl3073x_synth_state_get(zldev, zl3073x_out_synth_get(out)); |
| 354 |
freq = zl3073x_synth_freq_get(synth) / out->div; |
| 355 |
|
| 356 |
if (zl3073x_out_is_ndiv(out) && zl3073x_is_n_pin(id)) |
| 357 |
freq /= out->esync_n_period; |
| 358 |
|
| 359 |
return freq; |
| 360 |
} |
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
static inline bool |
| 370 |
zl3073x_dev_out_is_diff(struct zl3073x_dev *zldev, u8 index) |
| 371 |
{ |
| 372 |
const struct zl3073x_out *out = zl3073x_out_state_get(zldev, index); |
| 373 |
|
| 374 |
return zl3073x_out_is_diff(out); |
| 375 |
} |
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
static inline bool |
| 388 |
zl3073x_dev_output_pin_is_enabled(struct zl3073x_dev *zldev, u8 id) |
| 389 |
{ |
| 390 |
u8 out_id = zl3073x_output_pin_out_get(id); |
| 391 |
const struct zl3073x_out *out; |
| 392 |
|
| 393 |
out = zl3073x_out_state_get(zldev, out_id); |
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
if (!zl3073x_dev_out_is_enabled(zldev, out_id)) |
| 399 |
return false; |
| 400 |
|
| 401 |
|
| 402 |
switch (zl3073x_out_signal_format_get(out)) { |
| 403 |
case ZL_OUTPUT_MODE_SIGNAL_FORMAT_DISABLED: |
| 404 |
|
| 405 |
return false; |
| 406 |
|
| 407 |
case ZL_OUTPUT_MODE_SIGNAL_FORMAT_1P: |
| 408 |
|
| 409 |
if (zl3073x_is_n_pin(id)) |
| 410 |
return false; |
| 411 |
break; |
| 412 |
case ZL_OUTPUT_MODE_SIGNAL_FORMAT_1N: |
| 413 |
|
| 414 |
if (zl3073x_is_p_pin(id)) |
| 415 |
return false; |
| 416 |
break; |
| 417 |
default: |
| 418 |
|
| 419 |
break; |
| 420 |
} |
| 421 |
|
| 422 |
return true; |
| 423 |
} |
| 424 |
|
| 425 |
#endif |