@@ -142,9 +142,9 @@ func ParseDeviceReplies(msgs []genetlink.Message) ([]*DoDeviceGetReply, error) {
142
142
case DPLL_A_MODULE_NAME :
143
143
reply .ModuleName = ad .String ()
144
144
case DPLL_A_MODE :
145
- // reply.Mode = ad.Uint32()
145
+ reply .Mode = ad .Uint32 ()
146
146
case DPLL_A_MODE_SUPPORTED :
147
- // reply.ModeSupported = append(reply.ModeSupported, ad.Uint32())
147
+ reply .ModeSupported = append (reply .ModeSupported , ad .Uint32 ())
148
148
case DPLL_A_LOCK_STATUS :
149
149
reply .LockStatus = ad .Uint32 ()
150
150
case DPLL_A_PAD :
@@ -158,11 +158,9 @@ func ParseDeviceReplies(msgs []genetlink.Message) ([]*DoDeviceGetReply, error) {
158
158
log .Println ("default" , ad .Type (), len (ad .Bytes ()), ad .Bytes ())
159
159
}
160
160
}
161
-
162
161
if err := ad .Err (); err != nil {
163
162
return nil , err
164
163
}
165
-
166
164
replies = append (replies , & reply )
167
165
}
168
166
return replies , nil
@@ -245,27 +243,23 @@ type DoDeviceGetReply struct {
245
243
Id uint32
246
244
ModuleName string
247
245
Mode uint32
248
- ModeSupported uint32
246
+ ModeSupported [] uint32
249
247
LockStatus uint32
250
248
Temp int32
251
249
ClockId uint64
252
250
Type uint32
253
251
}
254
252
255
- func ParsePinReplies (msgs []genetlink.Message ) ([]* DoPinGetReply , error ) {
256
- replies := make ([]* DoPinGetReply , 0 , len (msgs ))
253
+ func ParsePinReplies (msgs []genetlink.Message ) ([]* PinInfo , error ) {
254
+ replies := make ([]* PinInfo , 0 , len (msgs ))
257
255
258
256
for _ , m := range msgs {
259
257
ad , err := netlink .NewAttributeDecoder (m .Data )
260
258
if err != nil {
261
259
return nil , err
262
260
}
263
- // Initialize phase offset to a max value, so later we can detect it has been updated
264
- reply := DoPinGetReply {
265
- ParentDevice : PinParentDevice {
266
- PhaseOffset : math .MaxInt64 ,
267
- },
268
- }
261
+ var reply PinInfo
262
+
269
263
for ad .Next () {
270
264
switch ad .Type () {
271
265
case DPLL_A_PIN_CLOCK_ID :
@@ -284,47 +278,58 @@ func ParsePinReplies(msgs []genetlink.Message) ([]*DoPinGetReply, error) {
284
278
reply .Frequency = ad .Uint64 ()
285
279
case DPLL_A_PIN_FREQUENCY_SUPPORTED :
286
280
ad .Nested (func (ad * netlink.AttributeDecoder ) error {
281
+ var temp FrequencyRange
287
282
for ad .Next () {
288
283
switch ad .Type () {
289
284
case DPLL_A_PIN_FREQUENCY_MIN :
290
- reply . FrequencySupported .FrequencyMin = ad .Uint64 ()
285
+ temp .FrequencyMin = ad .Uint64 ()
291
286
case DPLL_A_PIN_FREQUENCY_MAX :
292
- reply . FrequencySupported .FrequencyMax = ad .Uint64 ()
287
+ temp .FrequencyMax = ad .Uint64 ()
293
288
}
294
289
}
290
+ reply .FrequencySupported = append (reply .FrequencySupported , temp )
295
291
return nil
296
292
})
297
293
case DPLL_A_PIN_CAPABILITIES :
298
294
reply .Capabilities = ad .Uint32 ()
299
295
case DPLL_A_PIN_PARENT_DEVICE :
300
296
ad .Nested (func (ad * netlink.AttributeDecoder ) error {
297
+ temp := PinParentDevice {
298
+ // Initialize phase offset to a max value, so later we can detect it has been updated
299
+ PhaseOffset : math .MaxInt64 ,
300
+ }
301
301
for ad .Next () {
302
302
switch ad .Type () {
303
303
case DPLL_A_PIN_PARENT_ID :
304
- reply . ParentDevice .ParentId = ad .Uint32 ()
304
+ temp .ParentId = ad .Uint32 ()
305
305
case DPLL_A_PIN_DIRECTION :
306
- reply . ParentDevice .Direction = ad .Uint32 ()
306
+ temp .Direction = ad .Uint32 ()
307
307
case DPLL_A_PIN_PRIO :
308
- reply . ParentDevice .Prio = ad .Uint32 ()
308
+ temp .Prio = ad .Uint32 ()
309
309
case DPLL_A_PIN_STATE :
310
- reply . ParentDevice .State = ad .Uint32 ()
310
+ temp .State = ad .Uint32 ()
311
311
case DPLL_A_PIN_PHASE_OFFSET :
312
- reply . ParentDevice .PhaseOffset = ad .Int64 ()
312
+ temp .PhaseOffset = ad .Int64 ()
313
313
}
314
+
314
315
}
316
+ reply .ParentDevice = append (reply .ParentDevice , temp )
315
317
return nil
316
318
})
317
319
case DPLL_A_PIN_PARENT_PIN :
318
320
ad .Nested (func (ad * netlink.AttributeDecoder ) error {
321
+ var temp PinParentPin
319
322
for ad .Next () {
323
+
320
324
switch ad .Type () {
321
325
case DPLL_A_PIN_PARENT_ID :
322
- reply . ParentPin .ParentId = ad .Uint32 ()
326
+ temp .ParentId = ad .Uint32 ()
323
327
case DPLL_A_PIN_STATE :
324
- reply . ParentPin .State = ad .Uint32 ()
328
+ temp .State = ad .Uint32 ()
325
329
}
326
- }
327
330
331
+ }
332
+ reply .ParentPin = append (reply .ParentPin , temp )
328
333
return nil
329
334
})
330
335
case DPLL_A_PIN_PHASE_ADJUST_MIN :
@@ -350,11 +355,9 @@ func ParsePinReplies(msgs []genetlink.Message) ([]*DoPinGetReply, error) {
350
355
}
351
356
352
357
// DoPinGet wraps the "pin-get" operation:
353
- func (c * Conn ) DoPinGet (req DoPinGetRequest ) (* DoPinGetReply , error ) {
358
+ func (c * Conn ) DoPinGet (req DoPinGetRequest ) (* PinInfo , error ) {
354
359
ae := netlink .NewAttributeEncoder ()
355
- if req .Id != 0 {
356
- ae .Uint32 (DPLL_A_PIN_ID , req .Id )
357
- }
360
+ ae .Uint32 (DPLL_A_PIN_ID , req .Id )
358
361
359
362
b , err := ae .Encode ()
360
363
if err != nil {
@@ -378,26 +381,18 @@ func (c *Conn) DoPinGet(req DoPinGetRequest) (*DoPinGetReply, error) {
378
381
return nil , err
379
382
}
380
383
if len (replies ) != 1 {
381
- return nil , errors .New ("dpll: expected exactly one DoPinGetReply " )
384
+ return nil , errors .New ("dpll: expected exactly one PinInfo " )
382
385
}
383
386
384
387
return replies [0 ], nil
385
388
}
386
389
387
- func (c * Conn ) DumpPinGet () ([]* DoPinGetReply , error ) {
388
- ae := netlink .NewAttributeEncoder ()
389
-
390
- b , err := ae .Encode ()
391
- if err != nil {
392
- return nil , err
393
- }
394
-
390
+ func (c * Conn ) DumpPinGet () ([]* PinInfo , error ) {
395
391
msg := genetlink.Message {
396
392
Header : genetlink.Header {
397
393
Command : DPLL_CMD_PIN_GET ,
398
394
Version : c .f .Version ,
399
395
},
400
- Data : b ,
401
396
}
402
397
403
398
msgs , err := c .c .Execute (msg , c .f .ID , netlink .Request | netlink .Dump )
@@ -418,19 +413,19 @@ type DoPinGetRequest struct {
418
413
Id uint32
419
414
}
420
415
421
- // DoPinGetReply is used with the DoPinGet method.
422
- type DoPinGetReply struct {
416
+ // PinInfo is used with the DoPinGet method.
417
+ type PinInfo struct {
423
418
Id uint32
424
419
ClockId uint64
425
420
BoardLabel string
426
421
PanelLabel string
427
422
PackageLabel string
428
423
Type uint32
429
424
Frequency uint64
430
- FrequencySupported FrequencyRange
425
+ FrequencySupported [] FrequencyRange
431
426
Capabilities uint32
432
- ParentDevice PinParentDevice
433
- ParentPin PinParentPin
427
+ ParentDevice [] PinParentDevice
428
+ ParentPin [] PinParentPin
434
429
PhaseAdjustMin int32
435
430
PhaseAdjustMax int32
436
431
PhaseAdjust int32
@@ -489,3 +484,57 @@ func (c *Conn) PinPhaseAdjust(req PinPhaseAdjustRequest) error {
489
484
_ , err = c .c .Send (msg , c .f .ID , netlink .Request )
490
485
return err
491
486
}
487
+
488
+ type PinParentDeviceCtl struct {
489
+ Id uint32
490
+ PhaseAdjust * int32
491
+ PinParentCtl []PinControl
492
+ }
493
+ type PinControl struct {
494
+ PinParentId uint32
495
+ Direction * uint32
496
+ Prio * uint32
497
+ State * uint32
498
+ }
499
+
500
+ func EncodePinControl (req PinParentDeviceCtl ) ([]byte , error ) {
501
+ ae := netlink .NewAttributeEncoder ()
502
+ ae .Uint32 (DPLL_A_PIN_ID , req .Id )
503
+ if req .PhaseAdjust != nil {
504
+ ae .Int32 (DPLL_A_PIN_PHASE_ADJUST , * req .PhaseAdjust )
505
+ }
506
+ for _ , pp := range req .PinParentCtl {
507
+ ae .Nested (DPLL_A_PIN_PARENT_DEVICE , func (ae * netlink.AttributeEncoder ) error {
508
+ ae .Uint32 (DPLL_A_PIN_PARENT_ID , pp .PinParentId )
509
+ if pp .State != nil {
510
+ ae .Uint32 (DPLL_A_PIN_STATE , * pp .State )
511
+ }
512
+ if pp .Prio != nil {
513
+ ae .Uint32 (DPLL_A_PIN_PRIO , * pp .Prio )
514
+ }
515
+ if pp .Direction != nil {
516
+ ae .Uint32 (DPLL_A_PIN_DIRECTION , * pp .Direction )
517
+ }
518
+ return nil
519
+ })
520
+ }
521
+ b , err := ae .Encode ()
522
+ if err != nil {
523
+ return []byte {}, err
524
+ }
525
+ return b , nil
526
+ }
527
+
528
+ // SendCommand sends DPLL commands that don't require waiting for a reply
529
+ func (c * Conn ) SendCommand (command uint8 , data []byte ) error {
530
+ msg := genetlink.Message {
531
+ Header : genetlink.Header {
532
+ Command : command ,
533
+ Version : c .f .Version ,
534
+ },
535
+ Data : data ,
536
+ }
537
+ // No replies.
538
+ _ , err := c .c .Send (msg , c .f .ID , netlink .Request )
539
+ return err
540
+ }
0 commit comments