dpll.rst 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ===============================
  3. The Linux kernel dpll subsystem
  4. ===============================
  5. DPLL
  6. ====
  7. PLL - Phase Locked Loop is an electronic circuit which syntonizes clock
  8. signal of a device with an external clock signal. Effectively enabling
  9. device to run on the same clock signal beat as provided on a PLL input.
  10. DPLL - Digital Phase Locked Loop is an integrated circuit which in
  11. addition to plain PLL behavior incorporates a digital phase detector
  12. and may have digital divider in the loop. As a result, the frequency on
  13. DPLL's input and output may be configurable.
  14. Subsystem
  15. =========
  16. The main purpose of dpll subsystem is to provide general interface
  17. to configure devices that use any kind of Digital PLL and could use
  18. different sources of input signal to synchronize to, as well as
  19. different types of outputs.
  20. The main interface is NETLINK_GENERIC based protocol with an event
  21. monitoring multicast group defined.
  22. Device object
  23. =============
  24. Single dpll device object means single Digital PLL circuit and bunch of
  25. connected pins.
  26. It reports the supported modes of operation and current status to the
  27. user in response to the `do` request of netlink command
  28. ``DPLL_CMD_DEVICE_GET`` and list of dplls registered in the subsystem
  29. with `dump` netlink request of the same command.
  30. Changing the configuration of dpll device is done with `do` request of
  31. netlink ``DPLL_CMD_DEVICE_SET`` command.
  32. A device handle is ``DPLL_A_ID``, it shall be provided to get or set
  33. configuration of particular device in the system. It can be obtained
  34. with a ``DPLL_CMD_DEVICE_GET`` `dump` request or
  35. a ``DPLL_CMD_DEVICE_ID_GET`` `do` request, where the one must provide
  36. attributes that result in single device match.
  37. Pin object
  38. ==========
  39. A pin is amorphic object which represents either input or output, it
  40. could be internal component of the device, as well as externally
  41. connected.
  42. The number of pins per dpll vary, but usually multiple pins shall be
  43. provided for a single dpll device.
  44. Pin's properties, capabilities and status is provided to the user in
  45. response to `do` request of netlink ``DPLL_CMD_PIN_GET`` command.
  46. It is also possible to list all the pins that were registered in the
  47. system with `dump` request of ``DPLL_CMD_PIN_GET`` command.
  48. Configuration of a pin can be changed by `do` request of netlink
  49. ``DPLL_CMD_PIN_SET`` command.
  50. Pin handle is a ``DPLL_A_PIN_ID``, it shall be provided to get or set
  51. configuration of particular pin in the system. It can be obtained with
  52. ``DPLL_CMD_PIN_GET`` `dump` request or ``DPLL_CMD_PIN_ID_GET`` `do`
  53. request, where user provides attributes that result in single pin match.
  54. Pin selection
  55. =============
  56. In general, selected pin (the one which signal is driving the dpll
  57. device) can be obtained from ``DPLL_A_PIN_STATE`` attribute, and only
  58. one pin shall be in ``DPLL_PIN_STATE_CONNECTED`` state for any dpll
  59. device.
  60. Pin selection can be done either manually or automatically, depending
  61. on hardware capabilities and active dpll device work mode
  62. (``DPLL_A_MODE`` attribute). The consequence is that there are
  63. differences for each mode in terms of available pin states, as well as
  64. for the states the user can request for a dpll device.
  65. In manual mode (``DPLL_MODE_MANUAL``) the user can request or receive
  66. one of following pin states:
  67. - ``DPLL_PIN_STATE_CONNECTED`` - the pin is used to drive dpll device
  68. - ``DPLL_PIN_STATE_DISCONNECTED`` - the pin is not used to drive dpll
  69. device
  70. In automatic mode (``DPLL_MODE_AUTOMATIC``) the user can request or
  71. receive one of following pin states:
  72. - ``DPLL_PIN_STATE_SELECTABLE`` - the pin shall be considered as valid
  73. input for automatic selection algorithm
  74. - ``DPLL_PIN_STATE_DISCONNECTED`` - the pin shall be not considered as
  75. a valid input for automatic selection algorithm
  76. In automatic mode (``DPLL_MODE_AUTOMATIC``) the user can only receive
  77. pin state ``DPLL_PIN_STATE_CONNECTED`` once automatic selection
  78. algorithm locks a dpll device with one of the inputs.
  79. Shared pins
  80. ===========
  81. A single pin object can be attached to multiple dpll devices.
  82. Then there are two groups of configuration knobs:
  83. 1) Set on a pin - the configuration affects all dpll devices pin is
  84. registered to (i.e., ``DPLL_A_PIN_FREQUENCY``),
  85. 2) Set on a pin-dpll tuple - the configuration affects only selected
  86. dpll device (i.e., ``DPLL_A_PIN_PRIO``, ``DPLL_A_PIN_STATE``,
  87. ``DPLL_A_PIN_DIRECTION``).
  88. MUX-type pins
  89. =============
  90. A pin can be MUX-type, it aggregates child pins and serves as a pin
  91. multiplexer. One or more pins are registered with MUX-type instead of
  92. being directly registered to a dpll device.
  93. Pins registered with a MUX-type pin provide user with additional nested
  94. attribute ``DPLL_A_PIN_PARENT_PIN`` for each parent they were registered
  95. with.
  96. If a pin was registered with multiple parent pins, they behave like a
  97. multiple output multiplexer. In this case output of a
  98. ``DPLL_CMD_PIN_GET`` would contain multiple pin-parent nested
  99. attributes with current state related to each parent, like::
  100. 'pin': [{{
  101. 'clock-id': 282574471561216,
  102. 'module-name': 'ice',
  103. 'capabilities': 4,
  104. 'id': 13,
  105. 'parent-pin': [
  106. {'parent-id': 2, 'state': 'connected'},
  107. {'parent-id': 3, 'state': 'disconnected'}
  108. ],
  109. 'type': 'synce-eth-port'
  110. }}]
  111. Only one child pin can provide its signal to the parent MUX-type pin at
  112. a time, the selection is done by requesting change of a child pin state
  113. on desired parent, with the use of ``DPLL_A_PIN_PARENT`` nested
  114. attribute. Example of netlink `set state on parent pin` message format:
  115. ========================== =============================================
  116. ``DPLL_A_PIN_ID`` child pin id
  117. ``DPLL_A_PIN_PARENT_PIN`` nested attribute for requesting configuration
  118. related to parent pin
  119. ``DPLL_A_PIN_PARENT_ID`` parent pin id
  120. ``DPLL_A_PIN_STATE`` requested pin state on parent
  121. ========================== =============================================
  122. Pin priority
  123. ============
  124. Some devices might offer a capability of automatic pin selection mode
  125. (enum value ``DPLL_MODE_AUTOMATIC`` of ``DPLL_A_MODE`` attribute).
  126. Usually, automatic selection is performed on the hardware level, which
  127. means only pins directly connected to the dpll can be used for automatic
  128. input pin selection.
  129. In automatic selection mode, the user cannot manually select a input
  130. pin for the device, instead the user shall provide all directly
  131. connected pins with a priority ``DPLL_A_PIN_PRIO``, the device would
  132. pick a highest priority valid signal and use it to control the DPLL
  133. device. Example of netlink `set priority on parent pin` message format:
  134. ============================ =============================================
  135. ``DPLL_A_PIN_ID`` configured pin id
  136. ``DPLL_A_PIN_PARENT_DEVICE`` nested attribute for requesting configuration
  137. related to parent dpll device
  138. ``DPLL_A_PIN_PARENT_ID`` parent dpll device id
  139. ``DPLL_A_PIN_PRIO`` requested pin prio on parent dpll
  140. ============================ =============================================
  141. Child pin of MUX-type pin is not capable of automatic input pin selection,
  142. in order to configure active input of a MUX-type pin, the user needs to
  143. request desired pin state of the child pin on the parent pin,
  144. as described in the ``MUX-type pins`` chapter.
  145. Phase offset measurement and adjustment
  146. ========================================
  147. Device may provide ability to measure a phase difference between signals
  148. on a pin and its parent dpll device. If pin-dpll phase offset measurement
  149. is supported, it shall be provided with ``DPLL_A_PIN_PHASE_OFFSET``
  150. attribute for each parent dpll device. The reported phase offset may be
  151. computed as the average of prior values and the current measurement, using
  152. the following formula:
  153. .. math::
  154. curr\_avg = prev\_avg * \frac{2^N-1}{2^N} + new\_val * \frac{1}{2^N}
  155. where `curr_avg` is the current reported phase offset, `prev_avg` is the
  156. previously reported value, `new_val` is the current measurement, and `N` is
  157. the averaging factor. Configured averaging factor value is provided with
  158. ``DPLL_A_PHASE_OFFSET_AVG_FACTOR`` attribute of a device and value change can
  159. be requested with the same attribute with ``DPLL_CMD_DEVICE_SET`` command.
  160. ================================== ======================================
  161. ``DPLL_A_PHASE_OFFSET_AVG_FACTOR`` attr configured value of phase offset
  162. averaging factor
  163. ================================== ======================================
  164. Device may also provide ability to adjust a signal phase on a pin.
  165. If pin phase adjustment is supported, minimal and maximal values and
  166. granularity that pin handle shall be provided to the user on
  167. ``DPLL_CMD_PIN_GET`` respond with ``DPLL_A_PIN_PHASE_ADJUST_MIN``,
  168. ``DPLL_A_PIN_PHASE_ADJUST_MAX`` and ``DPLL_A_PIN_PHASE_ADJUST_GRAN``
  169. attributes. Configured phase adjust value is provided with
  170. ``DPLL_A_PIN_PHASE_ADJUST`` attribute of a pin, and value change can be
  171. requested with the same attribute with ``DPLL_CMD_PIN_SET`` command.
  172. ================================ ==========================================
  173. ``DPLL_A_PIN_ID`` configured pin id
  174. ``DPLL_A_PIN_PHASE_ADJUST_GRAN`` attr granularity of phase adjustment value
  175. ``DPLL_A_PIN_PHASE_ADJUST_MIN`` attr minimum value of phase adjustment
  176. ``DPLL_A_PIN_PHASE_ADJUST_MAX`` attr maximum value of phase adjustment
  177. ``DPLL_A_PIN_PHASE_ADJUST`` attr configured value of phase
  178. adjustment on parent dpll device
  179. ``DPLL_A_PIN_PARENT_DEVICE`` nested attribute for requesting
  180. configuration on given parent dpll
  181. device
  182. ``DPLL_A_PIN_PARENT_ID`` parent dpll device id
  183. ``DPLL_A_PIN_PHASE_OFFSET`` attr measured phase difference
  184. between a pin and parent dpll device
  185. ================================ ==========================================
  186. All phase related values are provided in pico seconds, which represents
  187. time difference between signals phase. The negative value means that
  188. phase of signal on pin is earlier in time than dpll's signal. Positive
  189. value means that phase of signal on pin is later in time than signal of
  190. a dpll.
  191. Phase adjust (also min and max) values are integers, but measured phase
  192. offset values are fractional with 3-digit decimal places and shell be
  193. divided with ``DPLL_PIN_PHASE_OFFSET_DIVIDER`` to get integer part and
  194. modulo divided to get fractional part.
  195. Phase offset monitor
  196. ====================
  197. Phase offset measurement is typically performed against the current active
  198. source. However, some DPLL (Digital Phase-Locked Loop) devices may offer
  199. the capability to monitor phase offsets across all available inputs.
  200. The attribute and current feature state shall be included in the response
  201. message of the ``DPLL_CMD_DEVICE_GET`` command for supported DPLL devices.
  202. In such cases, users can also control the feature using the
  203. ``DPLL_CMD_DEVICE_SET`` command by setting the ``enum dpll_feature_state``
  204. values for the attribute.
  205. Once enabled the phase offset measurements for the input shall be returned
  206. in the ``DPLL_A_PIN_PHASE_OFFSET`` attribute.
  207. =============================== ========================
  208. ``DPLL_A_PHASE_OFFSET_MONITOR`` attr state of a feature
  209. =============================== ========================
  210. Embedded SYNC
  211. =============
  212. Device may provide ability to use Embedded SYNC feature. It allows
  213. to embed additional SYNC signal into the base frequency of a pin - a one
  214. special pulse of base frequency signal every time SYNC signal pulse
  215. happens. The user can configure the frequency of Embedded SYNC.
  216. The Embedded SYNC capability is always related to a given base frequency
  217. and HW capabilities. The user is provided a range of Embedded SYNC
  218. frequencies supported, depending on current base frequency configured for
  219. the pin.
  220. ========================================= =================================
  221. ``DPLL_A_PIN_ESYNC_FREQUENCY`` current Embedded SYNC frequency
  222. ``DPLL_A_PIN_ESYNC_FREQUENCY_SUPPORTED`` nest available Embedded SYNC
  223. frequency ranges
  224. ``DPLL_A_PIN_FREQUENCY_MIN`` attr minimum value of frequency
  225. ``DPLL_A_PIN_FREQUENCY_MAX`` attr maximum value of frequency
  226. ``DPLL_A_PIN_ESYNC_PULSE`` pulse type of Embedded SYNC
  227. ========================================= =================================
  228. Reference SYNC
  229. ==============
  230. The device may support the Reference SYNC feature, which allows the combination
  231. of two inputs into a input pair. In this configuration, clock signals
  232. from both inputs are used to synchronize the DPLL device. The higher frequency
  233. signal is utilized for the loop bandwidth of the DPLL, while the lower frequency
  234. signal is used to syntonize the output signal of the DPLL device. This feature
  235. enables the provision of a high-quality loop bandwidth signal from an external
  236. source.
  237. A capable input provides a list of inputs that can be bound with to create
  238. Reference SYNC. To control this feature, the user must request a desired
  239. state for a target pin: use ``DPLL_PIN_STATE_CONNECTED`` to enable or
  240. ``DPLL_PIN_STATE_DISCONNECTED`` to disable the feature. An input pin can be
  241. bound to only one other pin at any given time.
  242. ============================== ==========================================
  243. ``DPLL_A_PIN_REFERENCE_SYNC`` nested attribute for providing info or
  244. requesting configuration of the Reference
  245. SYNC feature
  246. ``DPLL_A_PIN_ID`` target pin id for Reference SYNC feature
  247. ``DPLL_A_PIN_STATE`` state of Reference SYNC connection
  248. ============================== ==========================================
  249. Configuration commands group
  250. ============================
  251. Configuration commands are used to get information about registered
  252. dpll devices (and pins), as well as set configuration of device or pins.
  253. As dpll devices must be abstracted and reflect real hardware,
  254. there is no way to add new dpll device via netlink from user space and
  255. each device should be registered by its driver.
  256. All netlink commands require ``GENL_ADMIN_PERM``. This is to prevent
  257. any spamming/DoS from unauthorized userspace applications.
  258. List of netlink commands with possible attributes
  259. =================================================
  260. Constants identifying command types for dpll device uses a
  261. ``DPLL_CMD_`` prefix and suffix according to command purpose.
  262. The dpll device related attributes use a ``DPLL_A_`` prefix and
  263. suffix according to attribute purpose.
  264. ==================================== =================================
  265. ``DPLL_CMD_DEVICE_ID_GET`` command to get device ID
  266. ``DPLL_A_MODULE_NAME`` attr module name of registerer
  267. ``DPLL_A_CLOCK_ID`` attr Unique Clock Identifier
  268. (EUI-64), as defined by the
  269. IEEE 1588 standard
  270. ``DPLL_A_TYPE`` attr type of dpll device
  271. ==================================== =================================
  272. ==================================== =================================
  273. ``DPLL_CMD_DEVICE_GET`` command to get device info or
  274. dump list of available devices
  275. ``DPLL_A_ID`` attr unique dpll device ID
  276. ``DPLL_A_MODULE_NAME`` attr module name of registerer
  277. ``DPLL_A_CLOCK_ID`` attr Unique Clock Identifier
  278. (EUI-64), as defined by the
  279. IEEE 1588 standard
  280. ``DPLL_A_MODE`` attr selection mode
  281. ``DPLL_A_MODE_SUPPORTED`` attr available selection modes
  282. ``DPLL_A_LOCK_STATUS`` attr dpll device lock status
  283. ``DPLL_A_TEMP`` attr device temperature info
  284. ``DPLL_A_TYPE`` attr type of dpll device
  285. ==================================== =================================
  286. ==================================== =================================
  287. ``DPLL_CMD_DEVICE_SET`` command to set dpll device config
  288. ``DPLL_A_ID`` attr internal dpll device index
  289. ``DPLL_A_MODE`` attr selection mode to configure
  290. ==================================== =================================
  291. Constants identifying command types for pins uses a
  292. ``DPLL_CMD_PIN_`` prefix and suffix according to command purpose.
  293. The pin related attributes use a ``DPLL_A_PIN_`` prefix and suffix
  294. according to attribute purpose.
  295. ==================================== =================================
  296. ``DPLL_CMD_PIN_ID_GET`` command to get pin ID
  297. ``DPLL_A_PIN_MODULE_NAME`` attr module name of registerer
  298. ``DPLL_A_PIN_CLOCK_ID`` attr Unique Clock Identifier
  299. (EUI-64), as defined by the
  300. IEEE 1588 standard
  301. ``DPLL_A_PIN_BOARD_LABEL`` attr pin board label provided
  302. by registerer
  303. ``DPLL_A_PIN_PANEL_LABEL`` attr pin panel label provided
  304. by registerer
  305. ``DPLL_A_PIN_PACKAGE_LABEL`` attr pin package label provided
  306. by registerer
  307. ``DPLL_A_PIN_TYPE`` attr type of a pin
  308. ==================================== =================================
  309. ==================================== ==================================
  310. ``DPLL_CMD_PIN_GET`` command to get pin info or dump
  311. list of available pins
  312. ``DPLL_A_PIN_ID`` attr unique a pin ID
  313. ``DPLL_A_PIN_MODULE_NAME`` attr module name of registerer
  314. ``DPLL_A_PIN_CLOCK_ID`` attr Unique Clock Identifier
  315. (EUI-64), as defined by the
  316. IEEE 1588 standard
  317. ``DPLL_A_PIN_BOARD_LABEL`` attr pin board label provided
  318. by registerer
  319. ``DPLL_A_PIN_PANEL_LABEL`` attr pin panel label provided
  320. by registerer
  321. ``DPLL_A_PIN_PACKAGE_LABEL`` attr pin package label provided
  322. by registerer
  323. ``DPLL_A_PIN_TYPE`` attr type of a pin
  324. ``DPLL_A_PIN_FREQUENCY`` attr current frequency of a pin
  325. ``DPLL_A_PIN_FREQUENCY_SUPPORTED`` nested attr provides supported
  326. frequencies
  327. ``DPLL_A_PIN_ANY_FREQUENCY_MIN`` attr minimum value of frequency
  328. ``DPLL_A_PIN_ANY_FREQUENCY_MAX`` attr maximum value of frequency
  329. ``DPLL_A_PIN_PHASE_ADJUST_GRAN`` attr granularity of phase
  330. adjustment value
  331. ``DPLL_A_PIN_PHASE_ADJUST_MIN`` attr minimum value of phase
  332. adjustment
  333. ``DPLL_A_PIN_PHASE_ADJUST_MAX`` attr maximum value of phase
  334. adjustment
  335. ``DPLL_A_PIN_PHASE_ADJUST`` attr configured value of phase
  336. adjustment on parent device
  337. ``DPLL_A_PIN_PARENT_DEVICE`` nested attr for each parent device
  338. the pin is connected with
  339. ``DPLL_A_PIN_PARENT_ID`` attr parent dpll device id
  340. ``DPLL_A_PIN_PRIO`` attr priority of pin on the
  341. dpll device
  342. ``DPLL_A_PIN_STATE`` attr state of pin on the parent
  343. dpll device
  344. ``DPLL_A_PIN_DIRECTION`` attr direction of a pin on the
  345. parent dpll device
  346. ``DPLL_A_PIN_PHASE_OFFSET`` attr measured phase difference
  347. between a pin and parent dpll
  348. ``DPLL_A_PIN_PARENT_PIN`` nested attr for each parent pin
  349. the pin is connected with
  350. ``DPLL_A_PIN_PARENT_ID`` attr parent pin id
  351. ``DPLL_A_PIN_STATE`` attr state of pin on the parent
  352. pin
  353. ``DPLL_A_PIN_CAPABILITIES`` attr bitmask of pin capabilities
  354. ==================================== ==================================
  355. ==================================== =================================
  356. ``DPLL_CMD_PIN_SET`` command to set pins configuration
  357. ``DPLL_A_PIN_ID`` attr unique a pin ID
  358. ``DPLL_A_PIN_FREQUENCY`` attr requested frequency of a pin
  359. ``DPLL_A_PIN_PHASE_ADJUST`` attr requested value of phase
  360. adjustment on parent device
  361. ``DPLL_A_PIN_PARENT_DEVICE`` nested attr for each parent dpll
  362. device configuration request
  363. ``DPLL_A_PIN_PARENT_ID`` attr parent dpll device id
  364. ``DPLL_A_PIN_DIRECTION`` attr requested direction of a pin
  365. ``DPLL_A_PIN_PRIO`` attr requested priority of pin on
  366. the dpll device
  367. ``DPLL_A_PIN_STATE`` attr requested state of pin on
  368. the dpll device
  369. ``DPLL_A_PIN_PARENT_PIN`` nested attr for each parent pin
  370. configuration request
  371. ``DPLL_A_PIN_PARENT_ID`` attr parent pin id
  372. ``DPLL_A_PIN_STATE`` attr requested state of pin on
  373. parent pin
  374. ==================================== =================================
  375. Netlink dump requests
  376. =====================
  377. The ``DPLL_CMD_DEVICE_GET`` and ``DPLL_CMD_PIN_GET`` commands are
  378. capable of dump type netlink requests, in which case the response is in
  379. the same format as for their ``do`` request, but every device or pin
  380. registered in the system is returned.
  381. SET commands format
  382. ===================
  383. ``DPLL_CMD_DEVICE_SET`` - to target a dpll device, the user provides
  384. ``DPLL_A_ID``, which is unique identifier of dpll device in the system,
  385. as well as parameter being configured (``DPLL_A_MODE``).
  386. ``DPLL_CMD_PIN_SET`` - to target a pin user must provide a
  387. ``DPLL_A_PIN_ID``, which is unique identifier of a pin in the system.
  388. Also configured pin parameters must be added.
  389. If ``DPLL_A_PIN_FREQUENCY`` is configured, this affects all the dpll
  390. devices that are connected with the pin, that is why frequency attribute
  391. shall not be enclosed in ``DPLL_A_PIN_PARENT_DEVICE``.
  392. Other attributes: ``DPLL_A_PIN_PRIO``, ``DPLL_A_PIN_STATE`` or
  393. ``DPLL_A_PIN_DIRECTION`` must be enclosed in
  394. ``DPLL_A_PIN_PARENT_DEVICE`` as their configuration relates to only one
  395. of parent dplls, targeted by ``DPLL_A_PIN_PARENT_ID`` attribute which is
  396. also required inside that nest.
  397. For MUX-type pins the ``DPLL_A_PIN_STATE`` attribute is configured in
  398. similar way, by enclosing required state in ``DPLL_A_PIN_PARENT_PIN``
  399. nested attribute and targeted parent pin id in ``DPLL_A_PIN_PARENT_ID``.
  400. In general, it is possible to configure multiple parameters at once, but
  401. internally each parameter change will be invoked separately, where order
  402. of configuration is not guaranteed by any means.
  403. Configuration pre-defined enums
  404. ===============================
  405. .. kernel-doc:: include/uapi/linux/dpll.h
  406. Notifications
  407. =============
  408. dpll device can provide notifications regarding status changes of the
  409. device, i.e. lock status changes, input/output changes or other alarms.
  410. There is one multicast group that is used to notify user-space apps via
  411. netlink socket: ``DPLL_MCGRP_MONITOR``
  412. Notifications messages:
  413. ============================== =====================================
  414. ``DPLL_CMD_DEVICE_CREATE_NTF`` dpll device was created
  415. ``DPLL_CMD_DEVICE_DELETE_NTF`` dpll device was deleted
  416. ``DPLL_CMD_DEVICE_CHANGE_NTF`` dpll device has changed
  417. ``DPLL_CMD_PIN_CREATE_NTF`` dpll pin was created
  418. ``DPLL_CMD_PIN_DELETE_NTF`` dpll pin was deleted
  419. ``DPLL_CMD_PIN_CHANGE_NTF`` dpll pin has changed
  420. ============================== =====================================
  421. Events format is the same as for the corresponding get command.
  422. Format of ``DPLL_CMD_DEVICE_`` events is the same as response of
  423. ``DPLL_CMD_DEVICE_GET``.
  424. Format of ``DPLL_CMD_PIN_`` events is same as response of
  425. ``DPLL_CMD_PIN_GET``.
  426. Device driver implementation
  427. ============================
  428. Device is allocated by dpll_device_get() call. Second call with the
  429. same arguments will not create new object but provides pointer to
  430. previously created device for given arguments, it also increases
  431. refcount of that object.
  432. Device is deallocated by dpll_device_put() call, which first
  433. decreases the refcount, once refcount is cleared the object is
  434. destroyed.
  435. Device should implement set of operations and register device via
  436. dpll_device_register() at which point it becomes available to the
  437. users. Multiple driver instances can obtain reference to it with
  438. dpll_device_get(), as well as register dpll device with their own
  439. ops and priv.
  440. The pins are allocated separately with dpll_pin_get(), it works
  441. similarly to dpll_device_get(). Function first creates object and then
  442. for each call with the same arguments only the object refcount
  443. increases. Also dpll_pin_put() works similarly to dpll_device_put().
  444. A pin can be registered with parent dpll device or parent pin, depending
  445. on hardware needs. Each registration requires registerer to provide set
  446. of pin callbacks, and private data pointer for calling them:
  447. - dpll_pin_register() - register pin with a dpll device,
  448. - dpll_pin_on_pin_register() - register pin with another MUX type pin.
  449. Notifications of adding or removing dpll devices are created within
  450. subsystem itself.
  451. Notifications about registering/deregistering pins are also invoked by
  452. the subsystem.
  453. Notifications about status changes either of dpll device or a pin are
  454. invoked in two ways:
  455. - after successful change was requested on dpll subsystem, the subsystem
  456. calls corresponding notification,
  457. - requested by device driver with dpll_device_change_ntf() or
  458. dpll_pin_change_ntf() when driver informs about the status change.
  459. The device driver using dpll interface is not required to implement all
  460. the callback operation. Nevertheless, there are few required to be
  461. implemented.
  462. Required dpll device level callback operations:
  463. - ``.mode_get``,
  464. - ``.lock_status_get``.
  465. Required pin level callback operations:
  466. - ``.state_on_dpll_get`` (pins registered with dpll device),
  467. - ``.state_on_pin_get`` (pins registered with parent pin),
  468. - ``.direction_get``.
  469. Every other operation handler is checked for existence and
  470. ``-EOPNOTSUPP`` is returned in case of absence of specific handler.
  471. The simplest implementation is in the OCP TimeCard driver. The ops
  472. structures are defined like this:
  473. .. code-block:: c
  474. static const struct dpll_device_ops dpll_ops = {
  475. .lock_status_get = ptp_ocp_dpll_lock_status_get,
  476. .mode_get = ptp_ocp_dpll_mode_get,
  477. .mode_supported = ptp_ocp_dpll_mode_supported,
  478. };
  479. static const struct dpll_pin_ops dpll_pins_ops = {
  480. .frequency_get = ptp_ocp_dpll_frequency_get,
  481. .frequency_set = ptp_ocp_dpll_frequency_set,
  482. .direction_get = ptp_ocp_dpll_direction_get,
  483. .direction_set = ptp_ocp_dpll_direction_set,
  484. .state_on_dpll_get = ptp_ocp_dpll_state_get,
  485. };
  486. The registration part is then looks like this part:
  487. .. code-block:: c
  488. clkid = pci_get_dsn(pdev);
  489. bp->dpll = dpll_device_get(clkid, 0, THIS_MODULE);
  490. if (IS_ERR(bp->dpll)) {
  491. err = PTR_ERR(bp->dpll);
  492. dev_err(&pdev->dev, "dpll_device_alloc failed\n");
  493. goto out;
  494. }
  495. err = dpll_device_register(bp->dpll, DPLL_TYPE_PPS, &dpll_ops, bp);
  496. if (err)
  497. goto out;
  498. for (i = 0; i < OCP_SMA_NUM; i++) {
  499. bp->sma[i].dpll_pin = dpll_pin_get(clkid, i, THIS_MODULE, &bp->sma[i].dpll_prop);
  500. if (IS_ERR(bp->sma[i].dpll_pin)) {
  501. err = PTR_ERR(bp->dpll);
  502. goto out_dpll;
  503. }
  504. err = dpll_pin_register(bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops,
  505. &bp->sma[i]);
  506. if (err) {
  507. dpll_pin_put(bp->sma[i].dpll_pin);
  508. goto out_dpll;
  509. }
  510. }
  511. In the error path we have to rewind every allocation in the reverse order:
  512. .. code-block:: c
  513. while (i) {
  514. --i;
  515. dpll_pin_unregister(bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, &bp->sma[i]);
  516. dpll_pin_put(bp->sma[i].dpll_pin);
  517. }
  518. dpll_device_put(bp->dpll);
  519. More complex example can be found in Intel's ICE driver or nVidia's mlx5 driver.
  520. SyncE enablement
  521. ================
  522. For SyncE enablement it is required to allow control over dpll device
  523. for a software application which monitors and configures the inputs of
  524. dpll device in response to current state of a dpll device and its
  525. inputs.
  526. In such scenario, dpll device input signal shall be also configurable
  527. to drive dpll with signal recovered from the PHY netdevice.
  528. This is done by exposing a pin to the netdevice - attaching pin to the
  529. netdevice itself with
  530. ``dpll_netdev_pin_set(struct net_device *dev, struct dpll_pin *dpll_pin)``.
  531. Exposed pin id handle ``DPLL_A_PIN_ID`` is then identifiable by the user
  532. as it is attached to rtnetlink respond to get ``RTM_NEWLINK`` command in
  533. nested attribute ``IFLA_DPLL_PIN``.