1dbb291f1SVadim Fedorenko.. SPDX-License-Identifier: GPL-2.0 2dbb291f1SVadim Fedorenko 3dbb291f1SVadim Fedorenko=============================== 4dbb291f1SVadim FedorenkoThe Linux kernel dpll subsystem 5dbb291f1SVadim Fedorenko=============================== 6dbb291f1SVadim Fedorenko 7dbb291f1SVadim FedorenkoDPLL 8dbb291f1SVadim Fedorenko==== 9dbb291f1SVadim Fedorenko 10dbb291f1SVadim FedorenkoPLL - Phase Locked Loop is an electronic circuit which syntonizes clock 11dbb291f1SVadim Fedorenkosignal of a device with an external clock signal. Effectively enabling 12dbb291f1SVadim Fedorenkodevice to run on the same clock signal beat as provided on a PLL input. 13dbb291f1SVadim Fedorenko 14dbb291f1SVadim FedorenkoDPLL - Digital Phase Locked Loop is an integrated circuit which in 15dbb291f1SVadim Fedorenkoaddition to plain PLL behavior incorporates a digital phase detector 16dbb291f1SVadim Fedorenkoand may have digital divider in the loop. As a result, the frequency on 17dbb291f1SVadim FedorenkoDPLL's input and output may be configurable. 18dbb291f1SVadim Fedorenko 19dbb291f1SVadim FedorenkoSubsystem 20dbb291f1SVadim Fedorenko========= 21dbb291f1SVadim Fedorenko 22dbb291f1SVadim FedorenkoThe main purpose of dpll subsystem is to provide general interface 23dbb291f1SVadim Fedorenkoto configure devices that use any kind of Digital PLL and could use 24dbb291f1SVadim Fedorenkodifferent sources of input signal to synchronize to, as well as 25dbb291f1SVadim Fedorenkodifferent types of outputs. 26dbb291f1SVadim FedorenkoThe main interface is NETLINK_GENERIC based protocol with an event 27dbb291f1SVadim Fedorenkomonitoring multicast group defined. 28dbb291f1SVadim Fedorenko 29dbb291f1SVadim FedorenkoDevice object 30dbb291f1SVadim Fedorenko============= 31dbb291f1SVadim Fedorenko 32dbb291f1SVadim FedorenkoSingle dpll device object means single Digital PLL circuit and bunch of 33dbb291f1SVadim Fedorenkoconnected pins. 34dbb291f1SVadim FedorenkoIt reports the supported modes of operation and current status to the 35dbb291f1SVadim Fedorenkouser in response to the `do` request of netlink command 36dbb291f1SVadim Fedorenko``DPLL_CMD_DEVICE_GET`` and list of dplls registered in the subsystem 37dbb291f1SVadim Fedorenkowith `dump` netlink request of the same command. 38dbb291f1SVadim FedorenkoChanging the configuration of dpll device is done with `do` request of 39dbb291f1SVadim Fedorenkonetlink ``DPLL_CMD_DEVICE_SET`` command. 40dbb291f1SVadim FedorenkoA device handle is ``DPLL_A_ID``, it shall be provided to get or set 41dbb291f1SVadim Fedorenkoconfiguration of particular device in the system. It can be obtained 42dbb291f1SVadim Fedorenkowith a ``DPLL_CMD_DEVICE_GET`` `dump` request or 43dbb291f1SVadim Fedorenkoa ``DPLL_CMD_DEVICE_ID_GET`` `do` request, where the one must provide 44dbb291f1SVadim Fedorenkoattributes that result in single device match. 45dbb291f1SVadim Fedorenko 46dbb291f1SVadim FedorenkoPin object 47dbb291f1SVadim Fedorenko========== 48dbb291f1SVadim Fedorenko 49dbb291f1SVadim FedorenkoA pin is amorphic object which represents either input or output, it 50dbb291f1SVadim Fedorenkocould be internal component of the device, as well as externally 51dbb291f1SVadim Fedorenkoconnected. 52dbb291f1SVadim FedorenkoThe number of pins per dpll vary, but usually multiple pins shall be 53dbb291f1SVadim Fedorenkoprovided for a single dpll device. 54dbb291f1SVadim FedorenkoPin's properties, capabilities and status is provided to the user in 55dbb291f1SVadim Fedorenkoresponse to `do` request of netlink ``DPLL_CMD_PIN_GET`` command. 56dbb291f1SVadim FedorenkoIt is also possible to list all the pins that were registered in the 57dbb291f1SVadim Fedorenkosystem with `dump` request of ``DPLL_CMD_PIN_GET`` command. 58dbb291f1SVadim FedorenkoConfiguration of a pin can be changed by `do` request of netlink 59dbb291f1SVadim Fedorenko``DPLL_CMD_PIN_SET`` command. 60dbb291f1SVadim FedorenkoPin handle is a ``DPLL_A_PIN_ID``, it shall be provided to get or set 61dbb291f1SVadim Fedorenkoconfiguration of particular pin in the system. It can be obtained with 62dbb291f1SVadim Fedorenko``DPLL_CMD_PIN_GET`` `dump` request or ``DPLL_CMD_PIN_ID_GET`` `do` 63dbb291f1SVadim Fedorenkorequest, where user provides attributes that result in single pin match. 64dbb291f1SVadim Fedorenko 65dbb291f1SVadim FedorenkoPin selection 66dbb291f1SVadim Fedorenko============= 67dbb291f1SVadim Fedorenko 68dbb291f1SVadim FedorenkoIn general, selected pin (the one which signal is driving the dpll 69dbb291f1SVadim Fedorenkodevice) can be obtained from ``DPLL_A_PIN_STATE`` attribute, and only 70dbb291f1SVadim Fedorenkoone pin shall be in ``DPLL_PIN_STATE_CONNECTED`` state for any dpll 71dbb291f1SVadim Fedorenkodevice. 72dbb291f1SVadim Fedorenko 73dbb291f1SVadim FedorenkoPin selection can be done either manually or automatically, depending 74dbb291f1SVadim Fedorenkoon hardware capabilities and active dpll device work mode 75dbb291f1SVadim Fedorenko(``DPLL_A_MODE`` attribute). The consequence is that there are 76dbb291f1SVadim Fedorenkodifferences for each mode in terms of available pin states, as well as 77dbb291f1SVadim Fedorenkofor the states the user can request for a dpll device. 78dbb291f1SVadim Fedorenko 79dbb291f1SVadim FedorenkoIn manual mode (``DPLL_MODE_MANUAL``) the user can request or receive 80dbb291f1SVadim Fedorenkoone of following pin states: 81dbb291f1SVadim Fedorenko 82dbb291f1SVadim Fedorenko- ``DPLL_PIN_STATE_CONNECTED`` - the pin is used to drive dpll device 83dbb291f1SVadim Fedorenko- ``DPLL_PIN_STATE_DISCONNECTED`` - the pin is not used to drive dpll 84dbb291f1SVadim Fedorenko device 85dbb291f1SVadim Fedorenko 86dbb291f1SVadim FedorenkoIn automatic mode (``DPLL_MODE_AUTOMATIC``) the user can request or 87dbb291f1SVadim Fedorenkoreceive one of following pin states: 88dbb291f1SVadim Fedorenko 89dbb291f1SVadim Fedorenko- ``DPLL_PIN_STATE_SELECTABLE`` - the pin shall be considered as valid 90dbb291f1SVadim Fedorenko input for automatic selection algorithm 91dbb291f1SVadim Fedorenko- ``DPLL_PIN_STATE_DISCONNECTED`` - the pin shall be not considered as 92dbb291f1SVadim Fedorenko a valid input for automatic selection algorithm 93dbb291f1SVadim Fedorenko 94dbb291f1SVadim FedorenkoIn automatic mode (``DPLL_MODE_AUTOMATIC``) the user can only receive 95dbb291f1SVadim Fedorenkopin state ``DPLL_PIN_STATE_CONNECTED`` once automatic selection 96dbb291f1SVadim Fedorenkoalgorithm locks a dpll device with one of the inputs. 97dbb291f1SVadim Fedorenko 98dbb291f1SVadim FedorenkoShared pins 99dbb291f1SVadim Fedorenko=========== 100dbb291f1SVadim Fedorenko 101dbb291f1SVadim FedorenkoA single pin object can be attached to multiple dpll devices. 102dbb291f1SVadim FedorenkoThen there are two groups of configuration knobs: 103dbb291f1SVadim Fedorenko 104dbb291f1SVadim Fedorenko1) Set on a pin - the configuration affects all dpll devices pin is 105dbb291f1SVadim Fedorenko registered to (i.e., ``DPLL_A_PIN_FREQUENCY``), 106dbb291f1SVadim Fedorenko2) Set on a pin-dpll tuple - the configuration affects only selected 107dbb291f1SVadim Fedorenko dpll device (i.e., ``DPLL_A_PIN_PRIO``, ``DPLL_A_PIN_STATE``, 108dbb291f1SVadim Fedorenko ``DPLL_A_PIN_DIRECTION``). 109dbb291f1SVadim Fedorenko 110dbb291f1SVadim FedorenkoMUX-type pins 111dbb291f1SVadim Fedorenko============= 112dbb291f1SVadim Fedorenko 113dbb291f1SVadim FedorenkoA pin can be MUX-type, it aggregates child pins and serves as a pin 114dbb291f1SVadim Fedorenkomultiplexer. One or more pins are registered with MUX-type instead of 115dbb291f1SVadim Fedorenkobeing directly registered to a dpll device. 116dbb291f1SVadim FedorenkoPins registered with a MUX-type pin provide user with additional nested 117dbb291f1SVadim Fedorenkoattribute ``DPLL_A_PIN_PARENT_PIN`` for each parent they were registered 118dbb291f1SVadim Fedorenkowith. 119dbb291f1SVadim FedorenkoIf a pin was registered with multiple parent pins, they behave like a 120dbb291f1SVadim Fedorenkomultiple output multiplexer. In this case output of a 121dbb291f1SVadim Fedorenko``DPLL_CMD_PIN_GET`` would contain multiple pin-parent nested 122c8afdc01SBagas Sanjayaattributes with current state related to each parent, like:: 123dbb291f1SVadim Fedorenko 124dbb291f1SVadim Fedorenko 'pin': [{{ 125dbb291f1SVadim Fedorenko 'clock-id': 282574471561216, 126dbb291f1SVadim Fedorenko 'module-name': 'ice', 127dbb291f1SVadim Fedorenko 'capabilities': 4, 128dbb291f1SVadim Fedorenko 'id': 13, 129dbb291f1SVadim Fedorenko 'parent-pin': [ 130dbb291f1SVadim Fedorenko {'parent-id': 2, 'state': 'connected'}, 131dbb291f1SVadim Fedorenko {'parent-id': 3, 'state': 'disconnected'} 132dbb291f1SVadim Fedorenko ], 133dbb291f1SVadim Fedorenko 'type': 'synce-eth-port' 134dbb291f1SVadim Fedorenko }}] 135dbb291f1SVadim Fedorenko 136dbb291f1SVadim FedorenkoOnly one child pin can provide its signal to the parent MUX-type pin at 137dbb291f1SVadim Fedorenkoa time, the selection is done by requesting change of a child pin state 138dbb291f1SVadim Fedorenkoon desired parent, with the use of ``DPLL_A_PIN_PARENT`` nested 139dbb291f1SVadim Fedorenkoattribute. Example of netlink `set state on parent pin` message format: 140dbb291f1SVadim Fedorenko 141dbb291f1SVadim Fedorenko ========================== ============================================= 142dbb291f1SVadim Fedorenko ``DPLL_A_PIN_ID`` child pin id 143dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PARENT_PIN`` nested attribute for requesting configuration 144dbb291f1SVadim Fedorenko related to parent pin 145dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PARENT_ID`` parent pin id 146dbb291f1SVadim Fedorenko ``DPLL_A_PIN_STATE`` requested pin state on parent 147dbb291f1SVadim Fedorenko ========================== ============================================= 148dbb291f1SVadim Fedorenko 149dbb291f1SVadim FedorenkoPin priority 150dbb291f1SVadim Fedorenko============ 151dbb291f1SVadim Fedorenko 152dbb291f1SVadim FedorenkoSome devices might offer a capability of automatic pin selection mode 153dbb291f1SVadim Fedorenko(enum value ``DPLL_MODE_AUTOMATIC`` of ``DPLL_A_MODE`` attribute). 154dbb291f1SVadim FedorenkoUsually, automatic selection is performed on the hardware level, which 155dbb291f1SVadim Fedorenkomeans only pins directly connected to the dpll can be used for automatic 156dbb291f1SVadim Fedorenkoinput pin selection. 157dbb291f1SVadim FedorenkoIn automatic selection mode, the user cannot manually select a input 158dbb291f1SVadim Fedorenkopin for the device, instead the user shall provide all directly 159dbb291f1SVadim Fedorenkoconnected pins with a priority ``DPLL_A_PIN_PRIO``, the device would 160dbb291f1SVadim Fedorenkopick a highest priority valid signal and use it to control the DPLL 161dbb291f1SVadim Fedorenkodevice. Example of netlink `set priority on parent pin` message format: 162dbb291f1SVadim Fedorenko 163dbb291f1SVadim Fedorenko ============================ ============================================= 164dbb291f1SVadim Fedorenko ``DPLL_A_PIN_ID`` configured pin id 165dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PARENT_DEVICE`` nested attribute for requesting configuration 166dbb291f1SVadim Fedorenko related to parent dpll device 167dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PARENT_ID`` parent dpll device id 168dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PRIO`` requested pin prio on parent dpll 169dbb291f1SVadim Fedorenko ============================ ============================================= 170dbb291f1SVadim Fedorenko 171dbb291f1SVadim FedorenkoChild pin of MUX-type pin is not capable of automatic input pin selection, 172dbb291f1SVadim Fedorenkoin order to configure active input of a MUX-type pin, the user needs to 173dbb291f1SVadim Fedorenkorequest desired pin state of the child pin on the parent pin, 174dbb291f1SVadim Fedorenkoas described in the ``MUX-type pins`` chapter. 175dbb291f1SVadim Fedorenko 17627ed30d1SArkadiusz KubalewskiPhase offset measurement and adjustment 17727ed30d1SArkadiusz Kubalewski======================================== 17827ed30d1SArkadiusz Kubalewski 17927ed30d1SArkadiusz KubalewskiDevice may provide ability to measure a phase difference between signals 18027ed30d1SArkadiusz Kubalewskion a pin and its parent dpll device. If pin-dpll phase offset measurement 18127ed30d1SArkadiusz Kubalewskiis supported, it shall be provided with ``DPLL_A_PIN_PHASE_OFFSET`` 18227ed30d1SArkadiusz Kubalewskiattribute for each parent dpll device. 18327ed30d1SArkadiusz Kubalewski 18427ed30d1SArkadiusz KubalewskiDevice may also provide ability to adjust a signal phase on a pin. 18527ed30d1SArkadiusz KubalewskiIf pin phase adjustment is supported, minimal and maximal values that pin 18627ed30d1SArkadiusz Kubalewskihandle shall be provide to the user on ``DPLL_CMD_PIN_GET`` respond 18727ed30d1SArkadiusz Kubalewskiwith ``DPLL_A_PIN_PHASE_ADJUST_MIN`` and ``DPLL_A_PIN_PHASE_ADJUST_MAX`` 18827ed30d1SArkadiusz Kubalewskiattributes. Configured phase adjust value is provided with 18927ed30d1SArkadiusz Kubalewski``DPLL_A_PIN_PHASE_ADJUST`` attribute of a pin, and value change can be 19027ed30d1SArkadiusz Kubalewskirequested with the same attribute with ``DPLL_CMD_PIN_SET`` command. 19127ed30d1SArkadiusz Kubalewski 19227ed30d1SArkadiusz Kubalewski =============================== ====================================== 19327ed30d1SArkadiusz Kubalewski ``DPLL_A_PIN_ID`` configured pin id 19427ed30d1SArkadiusz Kubalewski ``DPLL_A_PIN_PHASE_ADJUST_MIN`` attr minimum value of phase adjustment 19527ed30d1SArkadiusz Kubalewski ``DPLL_A_PIN_PHASE_ADJUST_MAX`` attr maximum value of phase adjustment 19627ed30d1SArkadiusz Kubalewski ``DPLL_A_PIN_PHASE_ADJUST`` attr configured value of phase 19727ed30d1SArkadiusz Kubalewski adjustment on parent dpll device 19827ed30d1SArkadiusz Kubalewski ``DPLL_A_PIN_PARENT_DEVICE`` nested attribute for requesting 19927ed30d1SArkadiusz Kubalewski configuration on given parent dpll 20027ed30d1SArkadiusz Kubalewski device 20127ed30d1SArkadiusz Kubalewski ``DPLL_A_PIN_PARENT_ID`` parent dpll device id 20227ed30d1SArkadiusz Kubalewski ``DPLL_A_PIN_PHASE_OFFSET`` attr measured phase difference 20327ed30d1SArkadiusz Kubalewski between a pin and parent dpll device 20427ed30d1SArkadiusz Kubalewski =============================== ====================================== 20527ed30d1SArkadiusz Kubalewski 20627ed30d1SArkadiusz KubalewskiAll phase related values are provided in pico seconds, which represents 20727ed30d1SArkadiusz Kubalewskitime difference between signals phase. The negative value means that 20827ed30d1SArkadiusz Kubalewskiphase of signal on pin is earlier in time than dpll's signal. Positive 20927ed30d1SArkadiusz Kubalewskivalue means that phase of signal on pin is later in time than signal of 21027ed30d1SArkadiusz Kubalewskia dpll. 21127ed30d1SArkadiusz Kubalewski 21227ed30d1SArkadiusz KubalewskiPhase adjust (also min and max) values are integers, but measured phase 21327ed30d1SArkadiusz Kubalewskioffset values are fractional with 3-digit decimal places and shell be 21427ed30d1SArkadiusz Kubalewskidivided with ``DPLL_PIN_PHASE_OFFSET_DIVIDER`` to get integer part and 21527ed30d1SArkadiusz Kubalewskimodulo divided to get fractional part. 21627ed30d1SArkadiusz Kubalewski 217*cda1fba1SArkadiusz KubalewskiEmbedded SYNC 218*cda1fba1SArkadiusz Kubalewski============= 219*cda1fba1SArkadiusz Kubalewski 220*cda1fba1SArkadiusz KubalewskiDevice may provide ability to use Embedded SYNC feature. It allows 221*cda1fba1SArkadiusz Kubalewskito embed additional SYNC signal into the base frequency of a pin - a one 222*cda1fba1SArkadiusz Kubalewskispecial pulse of base frequency signal every time SYNC signal pulse 223*cda1fba1SArkadiusz Kubalewskihappens. The user can configure the frequency of Embedded SYNC. 224*cda1fba1SArkadiusz KubalewskiThe Embedded SYNC capability is always related to a given base frequency 225*cda1fba1SArkadiusz Kubalewskiand HW capabilities. The user is provided a range of Embedded SYNC 226*cda1fba1SArkadiusz Kubalewskifrequencies supported, depending on current base frequency configured for 227*cda1fba1SArkadiusz Kubalewskithe pin. 228*cda1fba1SArkadiusz Kubalewski 229*cda1fba1SArkadiusz Kubalewski ========================================= ================================= 230*cda1fba1SArkadiusz Kubalewski ``DPLL_A_PIN_ESYNC_FREQUENCY`` current Embedded SYNC frequency 231*cda1fba1SArkadiusz Kubalewski ``DPLL_A_PIN_ESYNC_FREQUENCY_SUPPORTED`` nest available Embedded SYNC 232*cda1fba1SArkadiusz Kubalewski frequency ranges 233*cda1fba1SArkadiusz Kubalewski ``DPLL_A_PIN_FREQUENCY_MIN`` attr minimum value of frequency 234*cda1fba1SArkadiusz Kubalewski ``DPLL_A_PIN_FREQUENCY_MAX`` attr maximum value of frequency 235*cda1fba1SArkadiusz Kubalewski ``DPLL_A_PIN_ESYNC_PULSE`` pulse type of Embedded SYNC 236*cda1fba1SArkadiusz Kubalewski ========================================= ================================= 237*cda1fba1SArkadiusz Kubalewski 238dbb291f1SVadim FedorenkoConfiguration commands group 239dbb291f1SVadim Fedorenko============================ 240dbb291f1SVadim Fedorenko 241dbb291f1SVadim FedorenkoConfiguration commands are used to get information about registered 242dbb291f1SVadim Fedorenkodpll devices (and pins), as well as set configuration of device or pins. 243dbb291f1SVadim FedorenkoAs dpll devices must be abstracted and reflect real hardware, 244dbb291f1SVadim Fedorenkothere is no way to add new dpll device via netlink from user space and 245dbb291f1SVadim Fedorenkoeach device should be registered by its driver. 246dbb291f1SVadim Fedorenko 247dbb291f1SVadim FedorenkoAll netlink commands require ``GENL_ADMIN_PERM``. This is to prevent 248dbb291f1SVadim Fedorenkoany spamming/DoS from unauthorized userspace applications. 249dbb291f1SVadim Fedorenko 250dbb291f1SVadim FedorenkoList of netlink commands with possible attributes 251dbb291f1SVadim Fedorenko================================================= 252dbb291f1SVadim Fedorenko 253dbb291f1SVadim FedorenkoConstants identifying command types for dpll device uses a 254dbb291f1SVadim Fedorenko``DPLL_CMD_`` prefix and suffix according to command purpose. 255dbb291f1SVadim FedorenkoThe dpll device related attributes use a ``DPLL_A_`` prefix and 256dbb291f1SVadim Fedorenkosuffix according to attribute purpose. 257dbb291f1SVadim Fedorenko 258dbb291f1SVadim Fedorenko ==================================== ================================= 259dbb291f1SVadim Fedorenko ``DPLL_CMD_DEVICE_ID_GET`` command to get device ID 260dbb291f1SVadim Fedorenko ``DPLL_A_MODULE_NAME`` attr module name of registerer 261dbb291f1SVadim Fedorenko ``DPLL_A_CLOCK_ID`` attr Unique Clock Identifier 262dbb291f1SVadim Fedorenko (EUI-64), as defined by the 263dbb291f1SVadim Fedorenko IEEE 1588 standard 264dbb291f1SVadim Fedorenko ``DPLL_A_TYPE`` attr type of dpll device 265dbb291f1SVadim Fedorenko ==================================== ================================= 266dbb291f1SVadim Fedorenko 267dbb291f1SVadim Fedorenko ==================================== ================================= 268dbb291f1SVadim Fedorenko ``DPLL_CMD_DEVICE_GET`` command to get device info or 269dbb291f1SVadim Fedorenko dump list of available devices 270dbb291f1SVadim Fedorenko ``DPLL_A_ID`` attr unique dpll device ID 271dbb291f1SVadim Fedorenko ``DPLL_A_MODULE_NAME`` attr module name of registerer 272dbb291f1SVadim Fedorenko ``DPLL_A_CLOCK_ID`` attr Unique Clock Identifier 273dbb291f1SVadim Fedorenko (EUI-64), as defined by the 274dbb291f1SVadim Fedorenko IEEE 1588 standard 275dbb291f1SVadim Fedorenko ``DPLL_A_MODE`` attr selection mode 276dbb291f1SVadim Fedorenko ``DPLL_A_MODE_SUPPORTED`` attr available selection modes 277dbb291f1SVadim Fedorenko ``DPLL_A_LOCK_STATUS`` attr dpll device lock status 278dbb291f1SVadim Fedorenko ``DPLL_A_TEMP`` attr device temperature info 279dbb291f1SVadim Fedorenko ``DPLL_A_TYPE`` attr type of dpll device 280dbb291f1SVadim Fedorenko ==================================== ================================= 281dbb291f1SVadim Fedorenko 282dbb291f1SVadim Fedorenko ==================================== ================================= 283dbb291f1SVadim Fedorenko ``DPLL_CMD_DEVICE_SET`` command to set dpll device config 284dbb291f1SVadim Fedorenko ``DPLL_A_ID`` attr internal dpll device index 285dbb291f1SVadim Fedorenko ``DPLL_A_MODE`` attr selection mode to configure 286dbb291f1SVadim Fedorenko ==================================== ================================= 287dbb291f1SVadim Fedorenko 288dbb291f1SVadim FedorenkoConstants identifying command types for pins uses a 289dbb291f1SVadim Fedorenko``DPLL_CMD_PIN_`` prefix and suffix according to command purpose. 290dbb291f1SVadim FedorenkoThe pin related attributes use a ``DPLL_A_PIN_`` prefix and suffix 291dbb291f1SVadim Fedorenkoaccording to attribute purpose. 292dbb291f1SVadim Fedorenko 293dbb291f1SVadim Fedorenko ==================================== ================================= 294dbb291f1SVadim Fedorenko ``DPLL_CMD_PIN_ID_GET`` command to get pin ID 295dbb291f1SVadim Fedorenko ``DPLL_A_PIN_MODULE_NAME`` attr module name of registerer 296dbb291f1SVadim Fedorenko ``DPLL_A_PIN_CLOCK_ID`` attr Unique Clock Identifier 297dbb291f1SVadim Fedorenko (EUI-64), as defined by the 298dbb291f1SVadim Fedorenko IEEE 1588 standard 299dbb291f1SVadim Fedorenko ``DPLL_A_PIN_BOARD_LABEL`` attr pin board label provided 300dbb291f1SVadim Fedorenko by registerer 301dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PANEL_LABEL`` attr pin panel label provided 302dbb291f1SVadim Fedorenko by registerer 303dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PACKAGE_LABEL`` attr pin package label provided 304dbb291f1SVadim Fedorenko by registerer 305dbb291f1SVadim Fedorenko ``DPLL_A_PIN_TYPE`` attr type of a pin 306dbb291f1SVadim Fedorenko ==================================== ================================= 307dbb291f1SVadim Fedorenko 308dbb291f1SVadim Fedorenko ==================================== ================================== 309dbb291f1SVadim Fedorenko ``DPLL_CMD_PIN_GET`` command to get pin info or dump 310dbb291f1SVadim Fedorenko list of available pins 311dbb291f1SVadim Fedorenko ``DPLL_A_PIN_ID`` attr unique a pin ID 312dbb291f1SVadim Fedorenko ``DPLL_A_PIN_MODULE_NAME`` attr module name of registerer 313dbb291f1SVadim Fedorenko ``DPLL_A_PIN_CLOCK_ID`` attr Unique Clock Identifier 314dbb291f1SVadim Fedorenko (EUI-64), as defined by the 315dbb291f1SVadim Fedorenko IEEE 1588 standard 316dbb291f1SVadim Fedorenko ``DPLL_A_PIN_BOARD_LABEL`` attr pin board label provided 317dbb291f1SVadim Fedorenko by registerer 318dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PANEL_LABEL`` attr pin panel label provided 319dbb291f1SVadim Fedorenko by registerer 320dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PACKAGE_LABEL`` attr pin package label provided 321dbb291f1SVadim Fedorenko by registerer 322dbb291f1SVadim Fedorenko ``DPLL_A_PIN_TYPE`` attr type of a pin 323dbb291f1SVadim Fedorenko ``DPLL_A_PIN_FREQUENCY`` attr current frequency of a pin 324dbb291f1SVadim Fedorenko ``DPLL_A_PIN_FREQUENCY_SUPPORTED`` nested attr provides supported 325dbb291f1SVadim Fedorenko frequencies 326dbb291f1SVadim Fedorenko ``DPLL_A_PIN_ANY_FREQUENCY_MIN`` attr minimum value of frequency 327dbb291f1SVadim Fedorenko ``DPLL_A_PIN_ANY_FREQUENCY_MAX`` attr maximum value of frequency 32827ed30d1SArkadiusz Kubalewski ``DPLL_A_PIN_PHASE_ADJUST_MIN`` attr minimum value of phase 32927ed30d1SArkadiusz Kubalewski adjustment 33027ed30d1SArkadiusz Kubalewski ``DPLL_A_PIN_PHASE_ADJUST_MAX`` attr maximum value of phase 33127ed30d1SArkadiusz Kubalewski adjustment 33227ed30d1SArkadiusz Kubalewski ``DPLL_A_PIN_PHASE_ADJUST`` attr configured value of phase 33327ed30d1SArkadiusz Kubalewski adjustment on parent device 334dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PARENT_DEVICE`` nested attr for each parent device 335dbb291f1SVadim Fedorenko the pin is connected with 336dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PARENT_ID`` attr parent dpll device id 337dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PRIO`` attr priority of pin on the 338dbb291f1SVadim Fedorenko dpll device 339dbb291f1SVadim Fedorenko ``DPLL_A_PIN_STATE`` attr state of pin on the parent 340dbb291f1SVadim Fedorenko dpll device 341dbb291f1SVadim Fedorenko ``DPLL_A_PIN_DIRECTION`` attr direction of a pin on the 342dbb291f1SVadim Fedorenko parent dpll device 34327ed30d1SArkadiusz Kubalewski ``DPLL_A_PIN_PHASE_OFFSET`` attr measured phase difference 34427ed30d1SArkadiusz Kubalewski between a pin and parent dpll 345dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PARENT_PIN`` nested attr for each parent pin 346dbb291f1SVadim Fedorenko the pin is connected with 347dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PARENT_ID`` attr parent pin id 348dbb291f1SVadim Fedorenko ``DPLL_A_PIN_STATE`` attr state of pin on the parent 349dbb291f1SVadim Fedorenko pin 350dbb291f1SVadim Fedorenko ``DPLL_A_PIN_CAPABILITIES`` attr bitmask of pin capabilities 351dbb291f1SVadim Fedorenko ==================================== ================================== 352dbb291f1SVadim Fedorenko 353dbb291f1SVadim Fedorenko ==================================== ================================= 354dbb291f1SVadim Fedorenko ``DPLL_CMD_PIN_SET`` command to set pins configuration 355dbb291f1SVadim Fedorenko ``DPLL_A_PIN_ID`` attr unique a pin ID 356dbb291f1SVadim Fedorenko ``DPLL_A_PIN_FREQUENCY`` attr requested frequency of a pin 35727ed30d1SArkadiusz Kubalewski ``DPLL_A_PIN_PHASE_ADJUST`` attr requested value of phase 35827ed30d1SArkadiusz Kubalewski adjustment on parent device 359dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PARENT_DEVICE`` nested attr for each parent dpll 360dbb291f1SVadim Fedorenko device configuration request 361dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PARENT_ID`` attr parent dpll device id 362dbb291f1SVadim Fedorenko ``DPLL_A_PIN_DIRECTION`` attr requested direction of a pin 363dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PRIO`` attr requested priority of pin on 364dbb291f1SVadim Fedorenko the dpll device 365dbb291f1SVadim Fedorenko ``DPLL_A_PIN_STATE`` attr requested state of pin on 366dbb291f1SVadim Fedorenko the dpll device 367dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PARENT_PIN`` nested attr for each parent pin 368dbb291f1SVadim Fedorenko configuration request 369dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PARENT_ID`` attr parent pin id 370dbb291f1SVadim Fedorenko ``DPLL_A_PIN_STATE`` attr requested state of pin on 371dbb291f1SVadim Fedorenko parent pin 372dbb291f1SVadim Fedorenko ==================================== ================================= 373dbb291f1SVadim Fedorenko 374dbb291f1SVadim FedorenkoNetlink dump requests 375dbb291f1SVadim Fedorenko===================== 376dbb291f1SVadim Fedorenko 377dbb291f1SVadim FedorenkoThe ``DPLL_CMD_DEVICE_GET`` and ``DPLL_CMD_PIN_GET`` commands are 378dbb291f1SVadim Fedorenkocapable of dump type netlink requests, in which case the response is in 379dbb291f1SVadim Fedorenkothe same format as for their ``do`` request, but every device or pin 380dbb291f1SVadim Fedorenkoregistered in the system is returned. 381dbb291f1SVadim Fedorenko 382dbb291f1SVadim FedorenkoSET commands format 383dbb291f1SVadim Fedorenko=================== 384dbb291f1SVadim Fedorenko 385dbb291f1SVadim Fedorenko``DPLL_CMD_DEVICE_SET`` - to target a dpll device, the user provides 386dbb291f1SVadim Fedorenko``DPLL_A_ID``, which is unique identifier of dpll device in the system, 387dbb291f1SVadim Fedorenkoas well as parameter being configured (``DPLL_A_MODE``). 388dbb291f1SVadim Fedorenko 389dbb291f1SVadim Fedorenko``DPLL_CMD_PIN_SET`` - to target a pin user must provide a 390dbb291f1SVadim Fedorenko``DPLL_A_PIN_ID``, which is unique identifier of a pin in the system. 391dbb291f1SVadim FedorenkoAlso configured pin parameters must be added. 392dbb291f1SVadim FedorenkoIf ``DPLL_A_PIN_FREQUENCY`` is configured, this affects all the dpll 393dbb291f1SVadim Fedorenkodevices that are connected with the pin, that is why frequency attribute 394dbb291f1SVadim Fedorenkoshall not be enclosed in ``DPLL_A_PIN_PARENT_DEVICE``. 395dbb291f1SVadim FedorenkoOther attributes: ``DPLL_A_PIN_PRIO``, ``DPLL_A_PIN_STATE`` or 396dbb291f1SVadim Fedorenko``DPLL_A_PIN_DIRECTION`` must be enclosed in 397dbb291f1SVadim Fedorenko``DPLL_A_PIN_PARENT_DEVICE`` as their configuration relates to only one 398dbb291f1SVadim Fedorenkoof parent dplls, targeted by ``DPLL_A_PIN_PARENT_ID`` attribute which is 399dbb291f1SVadim Fedorenkoalso required inside that nest. 400dbb291f1SVadim FedorenkoFor MUX-type pins the ``DPLL_A_PIN_STATE`` attribute is configured in 401dbb291f1SVadim Fedorenkosimilar way, by enclosing required state in ``DPLL_A_PIN_PARENT_PIN`` 402dbb291f1SVadim Fedorenkonested attribute and targeted parent pin id in ``DPLL_A_PIN_PARENT_ID``. 403dbb291f1SVadim Fedorenko 404dbb291f1SVadim FedorenkoIn general, it is possible to configure multiple parameters at once, but 405dbb291f1SVadim Fedorenkointernally each parameter change will be invoked separately, where order 406dbb291f1SVadim Fedorenkoof configuration is not guaranteed by any means. 407dbb291f1SVadim Fedorenko 408dbb291f1SVadim FedorenkoConfiguration pre-defined enums 409dbb291f1SVadim Fedorenko=============================== 410dbb291f1SVadim Fedorenko 411dbb291f1SVadim Fedorenko.. kernel-doc:: include/uapi/linux/dpll.h 412dbb291f1SVadim Fedorenko 413dbb291f1SVadim FedorenkoNotifications 414dbb291f1SVadim Fedorenko============= 415dbb291f1SVadim Fedorenko 416dbb291f1SVadim Fedorenkodpll device can provide notifications regarding status changes of the 417dbb291f1SVadim Fedorenkodevice, i.e. lock status changes, input/output changes or other alarms. 418dbb291f1SVadim FedorenkoThere is one multicast group that is used to notify user-space apps via 419dbb291f1SVadim Fedorenkonetlink socket: ``DPLL_MCGRP_MONITOR`` 420dbb291f1SVadim Fedorenko 421dbb291f1SVadim FedorenkoNotifications messages: 422dbb291f1SVadim Fedorenko 423dbb291f1SVadim Fedorenko ============================== ===================================== 424dbb291f1SVadim Fedorenko ``DPLL_CMD_DEVICE_CREATE_NTF`` dpll device was created 425dbb291f1SVadim Fedorenko ``DPLL_CMD_DEVICE_DELETE_NTF`` dpll device was deleted 426dbb291f1SVadim Fedorenko ``DPLL_CMD_DEVICE_CHANGE_NTF`` dpll device has changed 427dbb291f1SVadim Fedorenko ``DPLL_CMD_PIN_CREATE_NTF`` dpll pin was created 428dbb291f1SVadim Fedorenko ``DPLL_CMD_PIN_DELETE_NTF`` dpll pin was deleted 429dbb291f1SVadim Fedorenko ``DPLL_CMD_PIN_CHANGE_NTF`` dpll pin has changed 430dbb291f1SVadim Fedorenko ============================== ===================================== 431dbb291f1SVadim Fedorenko 432dbb291f1SVadim FedorenkoEvents format is the same as for the corresponding get command. 433dbb291f1SVadim FedorenkoFormat of ``DPLL_CMD_DEVICE_`` events is the same as response of 434dbb291f1SVadim Fedorenko``DPLL_CMD_DEVICE_GET``. 435dbb291f1SVadim FedorenkoFormat of ``DPLL_CMD_PIN_`` events is same as response of 436dbb291f1SVadim Fedorenko``DPLL_CMD_PIN_GET``. 437dbb291f1SVadim Fedorenko 438dbb291f1SVadim FedorenkoDevice driver implementation 439dbb291f1SVadim Fedorenko============================ 440dbb291f1SVadim Fedorenko 441dbb291f1SVadim FedorenkoDevice is allocated by dpll_device_get() call. Second call with the 442dbb291f1SVadim Fedorenkosame arguments will not create new object but provides pointer to 443dbb291f1SVadim Fedorenkopreviously created device for given arguments, it also increases 444dbb291f1SVadim Fedorenkorefcount of that object. 445dbb291f1SVadim FedorenkoDevice is deallocated by dpll_device_put() call, which first 446dbb291f1SVadim Fedorenkodecreases the refcount, once refcount is cleared the object is 447dbb291f1SVadim Fedorenkodestroyed. 448dbb291f1SVadim Fedorenko 449dbb291f1SVadim FedorenkoDevice should implement set of operations and register device via 450dbb291f1SVadim Fedorenkodpll_device_register() at which point it becomes available to the 451dbb291f1SVadim Fedorenkousers. Multiple driver instances can obtain reference to it with 452dbb291f1SVadim Fedorenkodpll_device_get(), as well as register dpll device with their own 453dbb291f1SVadim Fedorenkoops and priv. 454dbb291f1SVadim Fedorenko 455dbb291f1SVadim FedorenkoThe pins are allocated separately with dpll_pin_get(), it works 456dbb291f1SVadim Fedorenkosimilarly to dpll_device_get(). Function first creates object and then 457dbb291f1SVadim Fedorenkofor each call with the same arguments only the object refcount 458dbb291f1SVadim Fedorenkoincreases. Also dpll_pin_put() works similarly to dpll_device_put(). 459dbb291f1SVadim Fedorenko 460dbb291f1SVadim FedorenkoA pin can be registered with parent dpll device or parent pin, depending 461dbb291f1SVadim Fedorenkoon hardware needs. Each registration requires registerer to provide set 462dbb291f1SVadim Fedorenkoof pin callbacks, and private data pointer for calling them: 463dbb291f1SVadim Fedorenko 464dbb291f1SVadim Fedorenko- dpll_pin_register() - register pin with a dpll device, 465dbb291f1SVadim Fedorenko- dpll_pin_on_pin_register() - register pin with another MUX type pin. 466dbb291f1SVadim Fedorenko 467dbb291f1SVadim FedorenkoNotifications of adding or removing dpll devices are created within 468dbb291f1SVadim Fedorenkosubsystem itself. 469dbb291f1SVadim FedorenkoNotifications about registering/deregistering pins are also invoked by 470dbb291f1SVadim Fedorenkothe subsystem. 471dbb291f1SVadim FedorenkoNotifications about status changes either of dpll device or a pin are 472dbb291f1SVadim Fedorenkoinvoked in two ways: 473dbb291f1SVadim Fedorenko 474dbb291f1SVadim Fedorenko- after successful change was requested on dpll subsystem, the subsystem 475dbb291f1SVadim Fedorenko calls corresponding notification, 476dbb291f1SVadim Fedorenko- requested by device driver with dpll_device_change_ntf() or 477dbb291f1SVadim Fedorenko dpll_pin_change_ntf() when driver informs about the status change. 478dbb291f1SVadim Fedorenko 479dbb291f1SVadim FedorenkoThe device driver using dpll interface is not required to implement all 480dbb291f1SVadim Fedorenkothe callback operation. Nevertheless, there are few required to be 481dbb291f1SVadim Fedorenkoimplemented. 482dbb291f1SVadim FedorenkoRequired dpll device level callback operations: 483dbb291f1SVadim Fedorenko 484dbb291f1SVadim Fedorenko- ``.mode_get``, 485dbb291f1SVadim Fedorenko- ``.lock_status_get``. 486dbb291f1SVadim Fedorenko 487dbb291f1SVadim FedorenkoRequired pin level callback operations: 488dbb291f1SVadim Fedorenko 489dbb291f1SVadim Fedorenko- ``.state_on_dpll_get`` (pins registered with dpll device), 490dbb291f1SVadim Fedorenko- ``.state_on_pin_get`` (pins registered with parent pin), 491dbb291f1SVadim Fedorenko- ``.direction_get``. 492dbb291f1SVadim Fedorenko 493dbb291f1SVadim FedorenkoEvery other operation handler is checked for existence and 494dbb291f1SVadim Fedorenko``-EOPNOTSUPP`` is returned in case of absence of specific handler. 495dbb291f1SVadim Fedorenko 496dbb291f1SVadim FedorenkoThe simplest implementation is in the OCP TimeCard driver. The ops 497dbb291f1SVadim Fedorenkostructures are defined like this: 498dbb291f1SVadim Fedorenko 499dbb291f1SVadim Fedorenko.. code-block:: c 50092425d08SBagas Sanjaya 501dbb291f1SVadim Fedorenko static const struct dpll_device_ops dpll_ops = { 502dbb291f1SVadim Fedorenko .lock_status_get = ptp_ocp_dpll_lock_status_get, 503dbb291f1SVadim Fedorenko .mode_get = ptp_ocp_dpll_mode_get, 504dbb291f1SVadim Fedorenko .mode_supported = ptp_ocp_dpll_mode_supported, 505dbb291f1SVadim Fedorenko }; 506dbb291f1SVadim Fedorenko 507dbb291f1SVadim Fedorenko static const struct dpll_pin_ops dpll_pins_ops = { 508dbb291f1SVadim Fedorenko .frequency_get = ptp_ocp_dpll_frequency_get, 509dbb291f1SVadim Fedorenko .frequency_set = ptp_ocp_dpll_frequency_set, 510dbb291f1SVadim Fedorenko .direction_get = ptp_ocp_dpll_direction_get, 511dbb291f1SVadim Fedorenko .direction_set = ptp_ocp_dpll_direction_set, 512dbb291f1SVadim Fedorenko .state_on_dpll_get = ptp_ocp_dpll_state_get, 513dbb291f1SVadim Fedorenko }; 514dbb291f1SVadim Fedorenko 515dbb291f1SVadim FedorenkoThe registration part is then looks like this part: 516dbb291f1SVadim Fedorenko 517dbb291f1SVadim Fedorenko.. code-block:: c 51892425d08SBagas Sanjaya 519dbb291f1SVadim Fedorenko clkid = pci_get_dsn(pdev); 520dbb291f1SVadim Fedorenko bp->dpll = dpll_device_get(clkid, 0, THIS_MODULE); 521dbb291f1SVadim Fedorenko if (IS_ERR(bp->dpll)) { 522dbb291f1SVadim Fedorenko err = PTR_ERR(bp->dpll); 523dbb291f1SVadim Fedorenko dev_err(&pdev->dev, "dpll_device_alloc failed\n"); 524dbb291f1SVadim Fedorenko goto out; 525dbb291f1SVadim Fedorenko } 526dbb291f1SVadim Fedorenko 527dbb291f1SVadim Fedorenko err = dpll_device_register(bp->dpll, DPLL_TYPE_PPS, &dpll_ops, bp); 528dbb291f1SVadim Fedorenko if (err) 529dbb291f1SVadim Fedorenko goto out; 530dbb291f1SVadim Fedorenko 531dbb291f1SVadim Fedorenko for (i = 0; i < OCP_SMA_NUM; i++) { 532dbb291f1SVadim Fedorenko bp->sma[i].dpll_pin = dpll_pin_get(clkid, i, THIS_MODULE, &bp->sma[i].dpll_prop); 533dbb291f1SVadim Fedorenko if (IS_ERR(bp->sma[i].dpll_pin)) { 534dbb291f1SVadim Fedorenko err = PTR_ERR(bp->dpll); 535dbb291f1SVadim Fedorenko goto out_dpll; 536dbb291f1SVadim Fedorenko } 537dbb291f1SVadim Fedorenko 538dbb291f1SVadim Fedorenko err = dpll_pin_register(bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, 539dbb291f1SVadim Fedorenko &bp->sma[i]); 540dbb291f1SVadim Fedorenko if (err) { 541dbb291f1SVadim Fedorenko dpll_pin_put(bp->sma[i].dpll_pin); 542dbb291f1SVadim Fedorenko goto out_dpll; 543dbb291f1SVadim Fedorenko } 544dbb291f1SVadim Fedorenko } 545dbb291f1SVadim Fedorenko 546dbb291f1SVadim FedorenkoIn the error path we have to rewind every allocation in the reverse order: 547dbb291f1SVadim Fedorenko 548dbb291f1SVadim Fedorenko.. code-block:: c 54992425d08SBagas Sanjaya 550dbb291f1SVadim Fedorenko while (i) { 551dbb291f1SVadim Fedorenko --i; 552dbb291f1SVadim Fedorenko dpll_pin_unregister(bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, &bp->sma[i]); 553dbb291f1SVadim Fedorenko dpll_pin_put(bp->sma[i].dpll_pin); 554dbb291f1SVadim Fedorenko } 555dbb291f1SVadim Fedorenko dpll_device_put(bp->dpll); 556dbb291f1SVadim Fedorenko 557dbb291f1SVadim FedorenkoMore complex example can be found in Intel's ICE driver or nVidia's mlx5 driver. 558dbb291f1SVadim Fedorenko 559dbb291f1SVadim FedorenkoSyncE enablement 560dbb291f1SVadim Fedorenko================ 561dbb291f1SVadim FedorenkoFor SyncE enablement it is required to allow control over dpll device 562dbb291f1SVadim Fedorenkofor a software application which monitors and configures the inputs of 563dbb291f1SVadim Fedorenkodpll device in response to current state of a dpll device and its 564dbb291f1SVadim Fedorenkoinputs. 565dbb291f1SVadim FedorenkoIn such scenario, dpll device input signal shall be also configurable 566dbb291f1SVadim Fedorenkoto drive dpll with signal recovered from the PHY netdevice. 567dbb291f1SVadim FedorenkoThis is done by exposing a pin to the netdevice - attaching pin to the 568dbb291f1SVadim Fedorenkonetdevice itself with 569289e9225SJakub Kicinski``dpll_netdev_pin_set(struct net_device *dev, struct dpll_pin *dpll_pin)``. 570dbb291f1SVadim FedorenkoExposed pin id handle ``DPLL_A_PIN_ID`` is then identifiable by the user 571dbb291f1SVadim Fedorenkoas it is attached to rtnetlink respond to get ``RTM_NEWLINK`` command in 572dbb291f1SVadim Fedorenkonested attribute ``IFLA_DPLL_PIN``. 573