ccf.txt 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. Introduction:
  2. =============
  3. This documentation entry describes the Common Clock Framework [CCF] port from
  4. Linux kernel (v5.1.12) to U-Boot.
  5. This code is supposed to bring CCF to IMX based devices (imx6q, imx7 imx8).
  6. Moreover, it also provides some common clock code, which would allow easy
  7. porting of CCF Linux code to other platforms.
  8. Design decisions:
  9. =================
  10. * U-Boot's driver model [DM] for clk differs from Linux CCF. The most notably
  11. difference is the lack of support for hierarchical clocks and "clock as a
  12. manager driver" (single clock DTS node acts as a starting point for all other
  13. clocks).
  14. * The clk_get_rate() caches the previously read data if CLK_GET_RATE_NOCACHE is
  15. not set (no need for recursive access).
  16. * On purpose the "manager" clk driver (clk-imx6q.c) is not using large table to
  17. store pointers to clocks - e.g. clk[IMX6QDL_CLK_USDHC2_SEL] = .... Instead we
  18. use udevice's linked list for the same class (UCLASS_CLK).
  19. Rationale:
  20. ----------
  21. When porting the code as is from Linux, one would need ~1KiB of RAM to store
  22. it. This is way too much if we do plan to use this driver in SPL.
  23. * The "central" structure of this patch series is struct udevice and its
  24. uclass_priv field contains the struct clk pointer (to the originally created
  25. one).
  26. * To keep things simple the struct udevice's uclass_priv pointer is used to
  27. store back pointer to corresponding struct clk. However, it is possible to
  28. modify clk-uclass.c file and add there struct uc_clk_priv, which would have
  29. clock related members (like pointer to clk). As of this writing there is no
  30. such need, so to avoid extra allocations (as it can be auto allocated by
  31. setting .per_device_auto_alloc_size = sizeof(struct uc_clk_priv)) the
  32. uclass_priv stores the pointer to struct clk.
  33. * Non-CCF clocks do not have a pointer to a clock in clk->dev->priv. In the case
  34. of composite clocks, clk->dev->priv may not match clk. Drivers should always
  35. use the struct clk which is passed to them, and not clk->dev->priv.
  36. * It is advised to add common clock code (like already added rate and flags) to
  37. the struct clk, which is a top level description of the clock.
  38. * U-Boot's driver model already provides the facility to automatically allocate
  39. (via private_alloc_size) device private data (accessible via dev->priv). It
  40. may look appealing to use this feature to allocate private structures for CCF
  41. clk devices e.g. divider (struct clk_divider *divider) for IMX6Q clock.
  42. The above feature had not been used for following reasons:
  43. - The original CCF Linux kernel driver is the "manager" for clocks - it
  44. decides when clock is instantiated (and when memory for it is allocated).
  45. - Using it would change the original structure of the CCF code.
  46. - To bind (via clk_register()) the clock device with U-Boot driver model we
  47. first need udevice for it (the "chicken and egg problem").
  48. * I've added the clk_get_parent(), which reads parent's dev->uclass_priv to
  49. provide parent's struct clk pointer. This seems the easiest way to get
  50. child/parent relationship for struct clk in U-Boot's udevice based clocks. In
  51. the future arbitrary parents may be supported by adding a get_parent function
  52. to clk_ops.
  53. * Linux's CCF 'struct clk_core' corresponds to U-Boot's udevice in 'struct clk'.
  54. Clock IP block agnostic flags from 'struct clk_core' (e.g. NOCACHE) have been
  55. moved from this struct one level up to 'struct clk'. Many flags are
  56. unimplemented at the moment.
  57. * For tests the new ./test/dm/clk_ccf.c and ./drivers/clk/clk_sandbox_ccf.c
  58. files have been introduced. The latter setups the CCF clock structure for
  59. sandbox by reusing, if possible, generic clock primitives - like divier and
  60. mux. The former file provides code to tests this setup.
  61. For sandbox new CONFIG_SANDBOX_CLK_CCF Kconfig define has been introduced.
  62. All new primitives added for new architectures must have corresponding test in
  63. the two aforementioned files.
  64. Testing (sandbox):
  65. ==================
  66. make mrproper; make sandbox_defconfig; make -j4
  67. ./u-boot -i -d arch/sandbox/dts/test.dtb
  68. => ut dm clk
  69. or in a more "scriptable" way (with -v to print debug output):
  70. ./u-boot --fdt arch/sandbox/dts/test.dtb --command "ut dm clk_ccf" -v
  71. To do:
  72. ------
  73. * Use of OF_PLATDATA in the SPL setup for CCF - as it is now - the SPL grows
  74. considerably and using CCF in boards with tiny resources (OCRAM) is
  75. problematic.
  76. * On demand port other parts of CCF to U-Boot - as now only features _really_
  77. needed by DM/DTS converted drivers are used.