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 176*27ed30d1SArkadiusz KubalewskiPhase offset measurement and adjustment 177*27ed30d1SArkadiusz Kubalewski======================================== 178*27ed30d1SArkadiusz Kubalewski 179*27ed30d1SArkadiusz KubalewskiDevice may provide ability to measure a phase difference between signals 180*27ed30d1SArkadiusz Kubalewskion a pin and its parent dpll device. If pin-dpll phase offset measurement 181*27ed30d1SArkadiusz Kubalewskiis supported, it shall be provided with ``DPLL_A_PIN_PHASE_OFFSET`` 182*27ed30d1SArkadiusz Kubalewskiattribute for each parent dpll device. 183*27ed30d1SArkadiusz Kubalewski 184*27ed30d1SArkadiusz KubalewskiDevice may also provide ability to adjust a signal phase on a pin. 185*27ed30d1SArkadiusz KubalewskiIf pin phase adjustment is supported, minimal and maximal values that pin 186*27ed30d1SArkadiusz Kubalewskihandle shall be provide to the user on ``DPLL_CMD_PIN_GET`` respond 187*27ed30d1SArkadiusz Kubalewskiwith ``DPLL_A_PIN_PHASE_ADJUST_MIN`` and ``DPLL_A_PIN_PHASE_ADJUST_MAX`` 188*27ed30d1SArkadiusz Kubalewskiattributes. Configured phase adjust value is provided with 189*27ed30d1SArkadiusz Kubalewski``DPLL_A_PIN_PHASE_ADJUST`` attribute of a pin, and value change can be 190*27ed30d1SArkadiusz Kubalewskirequested with the same attribute with ``DPLL_CMD_PIN_SET`` command. 191*27ed30d1SArkadiusz Kubalewski 192*27ed30d1SArkadiusz Kubalewski =============================== ====================================== 193*27ed30d1SArkadiusz Kubalewski ``DPLL_A_PIN_ID`` configured pin id 194*27ed30d1SArkadiusz Kubalewski ``DPLL_A_PIN_PHASE_ADJUST_MIN`` attr minimum value of phase adjustment 195*27ed30d1SArkadiusz Kubalewski ``DPLL_A_PIN_PHASE_ADJUST_MAX`` attr maximum value of phase adjustment 196*27ed30d1SArkadiusz Kubalewski ``DPLL_A_PIN_PHASE_ADJUST`` attr configured value of phase 197*27ed30d1SArkadiusz Kubalewski adjustment on parent dpll device 198*27ed30d1SArkadiusz Kubalewski ``DPLL_A_PIN_PARENT_DEVICE`` nested attribute for requesting 199*27ed30d1SArkadiusz Kubalewski configuration on given parent dpll 200*27ed30d1SArkadiusz Kubalewski device 201*27ed30d1SArkadiusz Kubalewski ``DPLL_A_PIN_PARENT_ID`` parent dpll device id 202*27ed30d1SArkadiusz Kubalewski ``DPLL_A_PIN_PHASE_OFFSET`` attr measured phase difference 203*27ed30d1SArkadiusz Kubalewski between a pin and parent dpll device 204*27ed30d1SArkadiusz Kubalewski =============================== ====================================== 205*27ed30d1SArkadiusz Kubalewski 206*27ed30d1SArkadiusz KubalewskiAll phase related values are provided in pico seconds, which represents 207*27ed30d1SArkadiusz Kubalewskitime difference between signals phase. The negative value means that 208*27ed30d1SArkadiusz Kubalewskiphase of signal on pin is earlier in time than dpll's signal. Positive 209*27ed30d1SArkadiusz Kubalewskivalue means that phase of signal on pin is later in time than signal of 210*27ed30d1SArkadiusz Kubalewskia dpll. 211*27ed30d1SArkadiusz Kubalewski 212*27ed30d1SArkadiusz KubalewskiPhase adjust (also min and max) values are integers, but measured phase 213*27ed30d1SArkadiusz Kubalewskioffset values are fractional with 3-digit decimal places and shell be 214*27ed30d1SArkadiusz Kubalewskidivided with ``DPLL_PIN_PHASE_OFFSET_DIVIDER`` to get integer part and 215*27ed30d1SArkadiusz Kubalewskimodulo divided to get fractional part. 216*27ed30d1SArkadiusz Kubalewski 217dbb291f1SVadim FedorenkoConfiguration commands group 218dbb291f1SVadim Fedorenko============================ 219dbb291f1SVadim Fedorenko 220dbb291f1SVadim FedorenkoConfiguration commands are used to get information about registered 221dbb291f1SVadim Fedorenkodpll devices (and pins), as well as set configuration of device or pins. 222dbb291f1SVadim FedorenkoAs dpll devices must be abstracted and reflect real hardware, 223dbb291f1SVadim Fedorenkothere is no way to add new dpll device via netlink from user space and 224dbb291f1SVadim Fedorenkoeach device should be registered by its driver. 225dbb291f1SVadim Fedorenko 226dbb291f1SVadim FedorenkoAll netlink commands require ``GENL_ADMIN_PERM``. This is to prevent 227dbb291f1SVadim Fedorenkoany spamming/DoS from unauthorized userspace applications. 228dbb291f1SVadim Fedorenko 229dbb291f1SVadim FedorenkoList of netlink commands with possible attributes 230dbb291f1SVadim Fedorenko================================================= 231dbb291f1SVadim Fedorenko 232dbb291f1SVadim FedorenkoConstants identifying command types for dpll device uses a 233dbb291f1SVadim Fedorenko``DPLL_CMD_`` prefix and suffix according to command purpose. 234dbb291f1SVadim FedorenkoThe dpll device related attributes use a ``DPLL_A_`` prefix and 235dbb291f1SVadim Fedorenkosuffix according to attribute purpose. 236dbb291f1SVadim Fedorenko 237dbb291f1SVadim Fedorenko ==================================== ================================= 238dbb291f1SVadim Fedorenko ``DPLL_CMD_DEVICE_ID_GET`` command to get device ID 239dbb291f1SVadim Fedorenko ``DPLL_A_MODULE_NAME`` attr module name of registerer 240dbb291f1SVadim Fedorenko ``DPLL_A_CLOCK_ID`` attr Unique Clock Identifier 241dbb291f1SVadim Fedorenko (EUI-64), as defined by the 242dbb291f1SVadim Fedorenko IEEE 1588 standard 243dbb291f1SVadim Fedorenko ``DPLL_A_TYPE`` attr type of dpll device 244dbb291f1SVadim Fedorenko ==================================== ================================= 245dbb291f1SVadim Fedorenko 246dbb291f1SVadim Fedorenko ==================================== ================================= 247dbb291f1SVadim Fedorenko ``DPLL_CMD_DEVICE_GET`` command to get device info or 248dbb291f1SVadim Fedorenko dump list of available devices 249dbb291f1SVadim Fedorenko ``DPLL_A_ID`` attr unique dpll device ID 250dbb291f1SVadim Fedorenko ``DPLL_A_MODULE_NAME`` attr module name of registerer 251dbb291f1SVadim Fedorenko ``DPLL_A_CLOCK_ID`` attr Unique Clock Identifier 252dbb291f1SVadim Fedorenko (EUI-64), as defined by the 253dbb291f1SVadim Fedorenko IEEE 1588 standard 254dbb291f1SVadim Fedorenko ``DPLL_A_MODE`` attr selection mode 255dbb291f1SVadim Fedorenko ``DPLL_A_MODE_SUPPORTED`` attr available selection modes 256dbb291f1SVadim Fedorenko ``DPLL_A_LOCK_STATUS`` attr dpll device lock status 257dbb291f1SVadim Fedorenko ``DPLL_A_TEMP`` attr device temperature info 258dbb291f1SVadim Fedorenko ``DPLL_A_TYPE`` attr type of dpll device 259dbb291f1SVadim Fedorenko ==================================== ================================= 260dbb291f1SVadim Fedorenko 261dbb291f1SVadim Fedorenko ==================================== ================================= 262dbb291f1SVadim Fedorenko ``DPLL_CMD_DEVICE_SET`` command to set dpll device config 263dbb291f1SVadim Fedorenko ``DPLL_A_ID`` attr internal dpll device index 264dbb291f1SVadim Fedorenko ``DPLL_A_MODE`` attr selection mode to configure 265dbb291f1SVadim Fedorenko ==================================== ================================= 266dbb291f1SVadim Fedorenko 267dbb291f1SVadim FedorenkoConstants identifying command types for pins uses a 268dbb291f1SVadim Fedorenko``DPLL_CMD_PIN_`` prefix and suffix according to command purpose. 269dbb291f1SVadim FedorenkoThe pin related attributes use a ``DPLL_A_PIN_`` prefix and suffix 270dbb291f1SVadim Fedorenkoaccording to attribute purpose. 271dbb291f1SVadim Fedorenko 272dbb291f1SVadim Fedorenko ==================================== ================================= 273dbb291f1SVadim Fedorenko ``DPLL_CMD_PIN_ID_GET`` command to get pin ID 274dbb291f1SVadim Fedorenko ``DPLL_A_PIN_MODULE_NAME`` attr module name of registerer 275dbb291f1SVadim Fedorenko ``DPLL_A_PIN_CLOCK_ID`` attr Unique Clock Identifier 276dbb291f1SVadim Fedorenko (EUI-64), as defined by the 277dbb291f1SVadim Fedorenko IEEE 1588 standard 278dbb291f1SVadim Fedorenko ``DPLL_A_PIN_BOARD_LABEL`` attr pin board label provided 279dbb291f1SVadim Fedorenko by registerer 280dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PANEL_LABEL`` attr pin panel label provided 281dbb291f1SVadim Fedorenko by registerer 282dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PACKAGE_LABEL`` attr pin package label provided 283dbb291f1SVadim Fedorenko by registerer 284dbb291f1SVadim Fedorenko ``DPLL_A_PIN_TYPE`` attr type of a pin 285dbb291f1SVadim Fedorenko ==================================== ================================= 286dbb291f1SVadim Fedorenko 287dbb291f1SVadim Fedorenko ==================================== ================================== 288dbb291f1SVadim Fedorenko ``DPLL_CMD_PIN_GET`` command to get pin info or dump 289dbb291f1SVadim Fedorenko list of available pins 290dbb291f1SVadim Fedorenko ``DPLL_A_PIN_ID`` attr unique a pin ID 291dbb291f1SVadim Fedorenko ``DPLL_A_PIN_MODULE_NAME`` attr module name of registerer 292dbb291f1SVadim Fedorenko ``DPLL_A_PIN_CLOCK_ID`` attr Unique Clock Identifier 293dbb291f1SVadim Fedorenko (EUI-64), as defined by the 294dbb291f1SVadim Fedorenko IEEE 1588 standard 295dbb291f1SVadim Fedorenko ``DPLL_A_PIN_BOARD_LABEL`` attr pin board label provided 296dbb291f1SVadim Fedorenko by registerer 297dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PANEL_LABEL`` attr pin panel label provided 298dbb291f1SVadim Fedorenko by registerer 299dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PACKAGE_LABEL`` attr pin package label provided 300dbb291f1SVadim Fedorenko by registerer 301dbb291f1SVadim Fedorenko ``DPLL_A_PIN_TYPE`` attr type of a pin 302dbb291f1SVadim Fedorenko ``DPLL_A_PIN_FREQUENCY`` attr current frequency of a pin 303dbb291f1SVadim Fedorenko ``DPLL_A_PIN_FREQUENCY_SUPPORTED`` nested attr provides supported 304dbb291f1SVadim Fedorenko frequencies 305dbb291f1SVadim Fedorenko ``DPLL_A_PIN_ANY_FREQUENCY_MIN`` attr minimum value of frequency 306dbb291f1SVadim Fedorenko ``DPLL_A_PIN_ANY_FREQUENCY_MAX`` attr maximum value of frequency 307*27ed30d1SArkadiusz Kubalewski ``DPLL_A_PIN_PHASE_ADJUST_MIN`` attr minimum value of phase 308*27ed30d1SArkadiusz Kubalewski adjustment 309*27ed30d1SArkadiusz Kubalewski ``DPLL_A_PIN_PHASE_ADJUST_MAX`` attr maximum value of phase 310*27ed30d1SArkadiusz Kubalewski adjustment 311*27ed30d1SArkadiusz Kubalewski ``DPLL_A_PIN_PHASE_ADJUST`` attr configured value of phase 312*27ed30d1SArkadiusz Kubalewski adjustment on parent device 313dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PARENT_DEVICE`` nested attr for each parent device 314dbb291f1SVadim Fedorenko the pin is connected with 315dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PARENT_ID`` attr parent dpll device id 316dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PRIO`` attr priority of pin on the 317dbb291f1SVadim Fedorenko dpll device 318dbb291f1SVadim Fedorenko ``DPLL_A_PIN_STATE`` attr state of pin on the parent 319dbb291f1SVadim Fedorenko dpll device 320dbb291f1SVadim Fedorenko ``DPLL_A_PIN_DIRECTION`` attr direction of a pin on the 321dbb291f1SVadim Fedorenko parent dpll device 322*27ed30d1SArkadiusz Kubalewski ``DPLL_A_PIN_PHASE_OFFSET`` attr measured phase difference 323*27ed30d1SArkadiusz Kubalewski between a pin and parent dpll 324dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PARENT_PIN`` nested attr for each parent pin 325dbb291f1SVadim Fedorenko the pin is connected with 326dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PARENT_ID`` attr parent pin id 327dbb291f1SVadim Fedorenko ``DPLL_A_PIN_STATE`` attr state of pin on the parent 328dbb291f1SVadim Fedorenko pin 329dbb291f1SVadim Fedorenko ``DPLL_A_PIN_CAPABILITIES`` attr bitmask of pin capabilities 330dbb291f1SVadim Fedorenko ==================================== ================================== 331dbb291f1SVadim Fedorenko 332dbb291f1SVadim Fedorenko ==================================== ================================= 333dbb291f1SVadim Fedorenko ``DPLL_CMD_PIN_SET`` command to set pins configuration 334dbb291f1SVadim Fedorenko ``DPLL_A_PIN_ID`` attr unique a pin ID 335dbb291f1SVadim Fedorenko ``DPLL_A_PIN_FREQUENCY`` attr requested frequency of a pin 336*27ed30d1SArkadiusz Kubalewski ``DPLL_A_PIN_PHASE_ADJUST`` attr requested value of phase 337*27ed30d1SArkadiusz Kubalewski adjustment on parent device 338dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PARENT_DEVICE`` nested attr for each parent dpll 339dbb291f1SVadim Fedorenko device configuration request 340dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PARENT_ID`` attr parent dpll device id 341dbb291f1SVadim Fedorenko ``DPLL_A_PIN_DIRECTION`` attr requested direction of a pin 342dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PRIO`` attr requested priority of pin on 343dbb291f1SVadim Fedorenko the dpll device 344dbb291f1SVadim Fedorenko ``DPLL_A_PIN_STATE`` attr requested state of pin on 345dbb291f1SVadim Fedorenko the dpll device 346dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PARENT_PIN`` nested attr for each parent pin 347dbb291f1SVadim Fedorenko configuration request 348dbb291f1SVadim Fedorenko ``DPLL_A_PIN_PARENT_ID`` attr parent pin id 349dbb291f1SVadim Fedorenko ``DPLL_A_PIN_STATE`` attr requested state of pin on 350dbb291f1SVadim Fedorenko parent pin 351dbb291f1SVadim Fedorenko ==================================== ================================= 352dbb291f1SVadim Fedorenko 353dbb291f1SVadim FedorenkoNetlink dump requests 354dbb291f1SVadim Fedorenko===================== 355dbb291f1SVadim Fedorenko 356dbb291f1SVadim FedorenkoThe ``DPLL_CMD_DEVICE_GET`` and ``DPLL_CMD_PIN_GET`` commands are 357dbb291f1SVadim Fedorenkocapable of dump type netlink requests, in which case the response is in 358dbb291f1SVadim Fedorenkothe same format as for their ``do`` request, but every device or pin 359dbb291f1SVadim Fedorenkoregistered in the system is returned. 360dbb291f1SVadim Fedorenko 361dbb291f1SVadim FedorenkoSET commands format 362dbb291f1SVadim Fedorenko=================== 363dbb291f1SVadim Fedorenko 364dbb291f1SVadim Fedorenko``DPLL_CMD_DEVICE_SET`` - to target a dpll device, the user provides 365dbb291f1SVadim Fedorenko``DPLL_A_ID``, which is unique identifier of dpll device in the system, 366dbb291f1SVadim Fedorenkoas well as parameter being configured (``DPLL_A_MODE``). 367dbb291f1SVadim Fedorenko 368dbb291f1SVadim Fedorenko``DPLL_CMD_PIN_SET`` - to target a pin user must provide a 369dbb291f1SVadim Fedorenko``DPLL_A_PIN_ID``, which is unique identifier of a pin in the system. 370dbb291f1SVadim FedorenkoAlso configured pin parameters must be added. 371dbb291f1SVadim FedorenkoIf ``DPLL_A_PIN_FREQUENCY`` is configured, this affects all the dpll 372dbb291f1SVadim Fedorenkodevices that are connected with the pin, that is why frequency attribute 373dbb291f1SVadim Fedorenkoshall not be enclosed in ``DPLL_A_PIN_PARENT_DEVICE``. 374dbb291f1SVadim FedorenkoOther attributes: ``DPLL_A_PIN_PRIO``, ``DPLL_A_PIN_STATE`` or 375dbb291f1SVadim Fedorenko``DPLL_A_PIN_DIRECTION`` must be enclosed in 376dbb291f1SVadim Fedorenko``DPLL_A_PIN_PARENT_DEVICE`` as their configuration relates to only one 377dbb291f1SVadim Fedorenkoof parent dplls, targeted by ``DPLL_A_PIN_PARENT_ID`` attribute which is 378dbb291f1SVadim Fedorenkoalso required inside that nest. 379dbb291f1SVadim FedorenkoFor MUX-type pins the ``DPLL_A_PIN_STATE`` attribute is configured in 380dbb291f1SVadim Fedorenkosimilar way, by enclosing required state in ``DPLL_A_PIN_PARENT_PIN`` 381dbb291f1SVadim Fedorenkonested attribute and targeted parent pin id in ``DPLL_A_PIN_PARENT_ID``. 382dbb291f1SVadim Fedorenko 383dbb291f1SVadim FedorenkoIn general, it is possible to configure multiple parameters at once, but 384dbb291f1SVadim Fedorenkointernally each parameter change will be invoked separately, where order 385dbb291f1SVadim Fedorenkoof configuration is not guaranteed by any means. 386dbb291f1SVadim Fedorenko 387dbb291f1SVadim FedorenkoConfiguration pre-defined enums 388dbb291f1SVadim Fedorenko=============================== 389dbb291f1SVadim Fedorenko 390dbb291f1SVadim Fedorenko.. kernel-doc:: include/uapi/linux/dpll.h 391dbb291f1SVadim Fedorenko 392dbb291f1SVadim FedorenkoNotifications 393dbb291f1SVadim Fedorenko============= 394dbb291f1SVadim Fedorenko 395dbb291f1SVadim Fedorenkodpll device can provide notifications regarding status changes of the 396dbb291f1SVadim Fedorenkodevice, i.e. lock status changes, input/output changes or other alarms. 397dbb291f1SVadim FedorenkoThere is one multicast group that is used to notify user-space apps via 398dbb291f1SVadim Fedorenkonetlink socket: ``DPLL_MCGRP_MONITOR`` 399dbb291f1SVadim Fedorenko 400dbb291f1SVadim FedorenkoNotifications messages: 401dbb291f1SVadim Fedorenko 402dbb291f1SVadim Fedorenko ============================== ===================================== 403dbb291f1SVadim Fedorenko ``DPLL_CMD_DEVICE_CREATE_NTF`` dpll device was created 404dbb291f1SVadim Fedorenko ``DPLL_CMD_DEVICE_DELETE_NTF`` dpll device was deleted 405dbb291f1SVadim Fedorenko ``DPLL_CMD_DEVICE_CHANGE_NTF`` dpll device has changed 406dbb291f1SVadim Fedorenko ``DPLL_CMD_PIN_CREATE_NTF`` dpll pin was created 407dbb291f1SVadim Fedorenko ``DPLL_CMD_PIN_DELETE_NTF`` dpll pin was deleted 408dbb291f1SVadim Fedorenko ``DPLL_CMD_PIN_CHANGE_NTF`` dpll pin has changed 409dbb291f1SVadim Fedorenko ============================== ===================================== 410dbb291f1SVadim Fedorenko 411dbb291f1SVadim FedorenkoEvents format is the same as for the corresponding get command. 412dbb291f1SVadim FedorenkoFormat of ``DPLL_CMD_DEVICE_`` events is the same as response of 413dbb291f1SVadim Fedorenko``DPLL_CMD_DEVICE_GET``. 414dbb291f1SVadim FedorenkoFormat of ``DPLL_CMD_PIN_`` events is same as response of 415dbb291f1SVadim Fedorenko``DPLL_CMD_PIN_GET``. 416dbb291f1SVadim Fedorenko 417dbb291f1SVadim FedorenkoDevice driver implementation 418dbb291f1SVadim Fedorenko============================ 419dbb291f1SVadim Fedorenko 420dbb291f1SVadim FedorenkoDevice is allocated by dpll_device_get() call. Second call with the 421dbb291f1SVadim Fedorenkosame arguments will not create new object but provides pointer to 422dbb291f1SVadim Fedorenkopreviously created device for given arguments, it also increases 423dbb291f1SVadim Fedorenkorefcount of that object. 424dbb291f1SVadim FedorenkoDevice is deallocated by dpll_device_put() call, which first 425dbb291f1SVadim Fedorenkodecreases the refcount, once refcount is cleared the object is 426dbb291f1SVadim Fedorenkodestroyed. 427dbb291f1SVadim Fedorenko 428dbb291f1SVadim FedorenkoDevice should implement set of operations and register device via 429dbb291f1SVadim Fedorenkodpll_device_register() at which point it becomes available to the 430dbb291f1SVadim Fedorenkousers. Multiple driver instances can obtain reference to it with 431dbb291f1SVadim Fedorenkodpll_device_get(), as well as register dpll device with their own 432dbb291f1SVadim Fedorenkoops and priv. 433dbb291f1SVadim Fedorenko 434dbb291f1SVadim FedorenkoThe pins are allocated separately with dpll_pin_get(), it works 435dbb291f1SVadim Fedorenkosimilarly to dpll_device_get(). Function first creates object and then 436dbb291f1SVadim Fedorenkofor each call with the same arguments only the object refcount 437dbb291f1SVadim Fedorenkoincreases. Also dpll_pin_put() works similarly to dpll_device_put(). 438dbb291f1SVadim Fedorenko 439dbb291f1SVadim FedorenkoA pin can be registered with parent dpll device or parent pin, depending 440dbb291f1SVadim Fedorenkoon hardware needs. Each registration requires registerer to provide set 441dbb291f1SVadim Fedorenkoof pin callbacks, and private data pointer for calling them: 442dbb291f1SVadim Fedorenko 443dbb291f1SVadim Fedorenko- dpll_pin_register() - register pin with a dpll device, 444dbb291f1SVadim Fedorenko- dpll_pin_on_pin_register() - register pin with another MUX type pin. 445dbb291f1SVadim Fedorenko 446dbb291f1SVadim FedorenkoNotifications of adding or removing dpll devices are created within 447dbb291f1SVadim Fedorenkosubsystem itself. 448dbb291f1SVadim FedorenkoNotifications about registering/deregistering pins are also invoked by 449dbb291f1SVadim Fedorenkothe subsystem. 450dbb291f1SVadim FedorenkoNotifications about status changes either of dpll device or a pin are 451dbb291f1SVadim Fedorenkoinvoked in two ways: 452dbb291f1SVadim Fedorenko 453dbb291f1SVadim Fedorenko- after successful change was requested on dpll subsystem, the subsystem 454dbb291f1SVadim Fedorenko calls corresponding notification, 455dbb291f1SVadim Fedorenko- requested by device driver with dpll_device_change_ntf() or 456dbb291f1SVadim Fedorenko dpll_pin_change_ntf() when driver informs about the status change. 457dbb291f1SVadim Fedorenko 458dbb291f1SVadim FedorenkoThe device driver using dpll interface is not required to implement all 459dbb291f1SVadim Fedorenkothe callback operation. Nevertheless, there are few required to be 460dbb291f1SVadim Fedorenkoimplemented. 461dbb291f1SVadim FedorenkoRequired dpll device level callback operations: 462dbb291f1SVadim Fedorenko 463dbb291f1SVadim Fedorenko- ``.mode_get``, 464dbb291f1SVadim Fedorenko- ``.lock_status_get``. 465dbb291f1SVadim Fedorenko 466dbb291f1SVadim FedorenkoRequired pin level callback operations: 467dbb291f1SVadim Fedorenko 468dbb291f1SVadim Fedorenko- ``.state_on_dpll_get`` (pins registered with dpll device), 469dbb291f1SVadim Fedorenko- ``.state_on_pin_get`` (pins registered with parent pin), 470dbb291f1SVadim Fedorenko- ``.direction_get``. 471dbb291f1SVadim Fedorenko 472dbb291f1SVadim FedorenkoEvery other operation handler is checked for existence and 473dbb291f1SVadim Fedorenko``-EOPNOTSUPP`` is returned in case of absence of specific handler. 474dbb291f1SVadim Fedorenko 475dbb291f1SVadim FedorenkoThe simplest implementation is in the OCP TimeCard driver. The ops 476dbb291f1SVadim Fedorenkostructures are defined like this: 477dbb291f1SVadim Fedorenko 478dbb291f1SVadim Fedorenko.. code-block:: c 47992425d08SBagas Sanjaya 480dbb291f1SVadim Fedorenko static const struct dpll_device_ops dpll_ops = { 481dbb291f1SVadim Fedorenko .lock_status_get = ptp_ocp_dpll_lock_status_get, 482dbb291f1SVadim Fedorenko .mode_get = ptp_ocp_dpll_mode_get, 483dbb291f1SVadim Fedorenko .mode_supported = ptp_ocp_dpll_mode_supported, 484dbb291f1SVadim Fedorenko }; 485dbb291f1SVadim Fedorenko 486dbb291f1SVadim Fedorenko static const struct dpll_pin_ops dpll_pins_ops = { 487dbb291f1SVadim Fedorenko .frequency_get = ptp_ocp_dpll_frequency_get, 488dbb291f1SVadim Fedorenko .frequency_set = ptp_ocp_dpll_frequency_set, 489dbb291f1SVadim Fedorenko .direction_get = ptp_ocp_dpll_direction_get, 490dbb291f1SVadim Fedorenko .direction_set = ptp_ocp_dpll_direction_set, 491dbb291f1SVadim Fedorenko .state_on_dpll_get = ptp_ocp_dpll_state_get, 492dbb291f1SVadim Fedorenko }; 493dbb291f1SVadim Fedorenko 494dbb291f1SVadim FedorenkoThe registration part is then looks like this part: 495dbb291f1SVadim Fedorenko 496dbb291f1SVadim Fedorenko.. code-block:: c 49792425d08SBagas Sanjaya 498dbb291f1SVadim Fedorenko clkid = pci_get_dsn(pdev); 499dbb291f1SVadim Fedorenko bp->dpll = dpll_device_get(clkid, 0, THIS_MODULE); 500dbb291f1SVadim Fedorenko if (IS_ERR(bp->dpll)) { 501dbb291f1SVadim Fedorenko err = PTR_ERR(bp->dpll); 502dbb291f1SVadim Fedorenko dev_err(&pdev->dev, "dpll_device_alloc failed\n"); 503dbb291f1SVadim Fedorenko goto out; 504dbb291f1SVadim Fedorenko } 505dbb291f1SVadim Fedorenko 506dbb291f1SVadim Fedorenko err = dpll_device_register(bp->dpll, DPLL_TYPE_PPS, &dpll_ops, bp); 507dbb291f1SVadim Fedorenko if (err) 508dbb291f1SVadim Fedorenko goto out; 509dbb291f1SVadim Fedorenko 510dbb291f1SVadim Fedorenko for (i = 0; i < OCP_SMA_NUM; i++) { 511dbb291f1SVadim Fedorenko bp->sma[i].dpll_pin = dpll_pin_get(clkid, i, THIS_MODULE, &bp->sma[i].dpll_prop); 512dbb291f1SVadim Fedorenko if (IS_ERR(bp->sma[i].dpll_pin)) { 513dbb291f1SVadim Fedorenko err = PTR_ERR(bp->dpll); 514dbb291f1SVadim Fedorenko goto out_dpll; 515dbb291f1SVadim Fedorenko } 516dbb291f1SVadim Fedorenko 517dbb291f1SVadim Fedorenko err = dpll_pin_register(bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, 518dbb291f1SVadim Fedorenko &bp->sma[i]); 519dbb291f1SVadim Fedorenko if (err) { 520dbb291f1SVadim Fedorenko dpll_pin_put(bp->sma[i].dpll_pin); 521dbb291f1SVadim Fedorenko goto out_dpll; 522dbb291f1SVadim Fedorenko } 523dbb291f1SVadim Fedorenko } 524dbb291f1SVadim Fedorenko 525dbb291f1SVadim FedorenkoIn the error path we have to rewind every allocation in the reverse order: 526dbb291f1SVadim Fedorenko 527dbb291f1SVadim Fedorenko.. code-block:: c 52892425d08SBagas Sanjaya 529dbb291f1SVadim Fedorenko while (i) { 530dbb291f1SVadim Fedorenko --i; 531dbb291f1SVadim Fedorenko dpll_pin_unregister(bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, &bp->sma[i]); 532dbb291f1SVadim Fedorenko dpll_pin_put(bp->sma[i].dpll_pin); 533dbb291f1SVadim Fedorenko } 534dbb291f1SVadim Fedorenko dpll_device_put(bp->dpll); 535dbb291f1SVadim Fedorenko 536dbb291f1SVadim FedorenkoMore complex example can be found in Intel's ICE driver or nVidia's mlx5 driver. 537dbb291f1SVadim Fedorenko 538dbb291f1SVadim FedorenkoSyncE enablement 539dbb291f1SVadim Fedorenko================ 540dbb291f1SVadim FedorenkoFor SyncE enablement it is required to allow control over dpll device 541dbb291f1SVadim Fedorenkofor a software application which monitors and configures the inputs of 542dbb291f1SVadim Fedorenkodpll device in response to current state of a dpll device and its 543dbb291f1SVadim Fedorenkoinputs. 544dbb291f1SVadim FedorenkoIn such scenario, dpll device input signal shall be also configurable 545dbb291f1SVadim Fedorenkoto drive dpll with signal recovered from the PHY netdevice. 546dbb291f1SVadim FedorenkoThis is done by exposing a pin to the netdevice - attaching pin to the 547dbb291f1SVadim Fedorenkonetdevice itself with 548dbb291f1SVadim Fedorenko``netdev_dpll_pin_set(struct net_device *dev, struct dpll_pin *dpll_pin)``. 549dbb291f1SVadim FedorenkoExposed pin id handle ``DPLL_A_PIN_ID`` is then identifiable by the user 550dbb291f1SVadim Fedorenkoas it is attached to rtnetlink respond to get ``RTM_NEWLINK`` command in 551dbb291f1SVadim Fedorenkonested attribute ``IFLA_DPLL_PIN``. 552