cs2100-cp.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /********************************************************************************************
  2. * include/nuttx/timers/cs2100-cp.h
  3. *
  4. * Copyright (C) 2015 Gregory Nutt. All rights reserved.
  5. * Authors: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ********************************************************************************************/
  35. #ifndef __INCLUDE_NUTTX_TIMERS_CS2100_CP_H
  36. #define __INCLUDE_NUTTX_TIMERS_CS2100_CP_H
  37. /********************************************************************************************
  38. * Included Files
  39. ********************************************************************************************/
  40. #include <nuttx/config.h>
  41. #include <stdint.h>
  42. #include <nuttx/i2c/i2c_master.h>
  43. #ifdef CONFIG_TIMERS_CS2100CP
  44. /********************************************************************************************
  45. * Pre-processor Definitions
  46. ********************************************************************************************/
  47. /* Configuration ************************************************************/
  48. #ifndef CONFIG_I2C
  49. # error I2C driver support is required (CONFIG_I2C)
  50. #endif
  51. #ifndef CONFIG_TIMERS_CS2100CP_CLKINBW
  52. # define CONFIG_TIMERS_CS2100CP_CLKINBW 16
  53. #endif
  54. #ifndef CONFIG_DEBUG_FEATURES
  55. # undef CONFIG_CS2100CP_DEBUG
  56. # undef CONFIG_CS2100CP_REGDEBUG
  57. #endif
  58. /* Register Addresses ***********************************************************************/
  59. #define CS2100_DEVID 0x01 /* Device ID and Revision */
  60. #define CS2100_DEVCTL 0x02 /* Device Control */
  61. #define CS2100_DEVCFG1 0x03 /* Device Configuration 1 */
  62. #define CS2100_GBLCFG 0x05 /* Global Configuration */
  63. #define CS2100_RATIO0 0x06 /* Ratio: Bits 24-31 */
  64. #define CS2100_RATIO1 0x07 /* Ratio: Bits 16-23 */
  65. #define CS2100_RATIO2 0x08 /* Ratio: Bits 8-15 */
  66. #define CS2100_RATIO3 0x09 /* Ratio: Bits 0- 7 */
  67. #define CS2100_FNCCFG1 0x16 /* Function Configuration 1 */
  68. #define CS2100_FNCCFG2 0x17 /* Function Configuration 2 */
  69. #define CS2100_FNCCFG3 0x1e /* Function Configuration 3 */
  70. /* Register Bit Field Definitions ***********************************************************/
  71. /* Device ID and Revision */
  72. #define CS2100_DEVID_REVISION_SHIFT (0) /* Bits 0-2: Device REVISION */
  73. #define CS2100_DEVID_REVISION_MASK (7 << CS2100_DEVID_REVISION_SHIFT)
  74. #define CS2100_DEVID_DEVICE_SHIFT (3) /* Bits 3-7: Device ID */
  75. #define CS2100_DEVID_DEVICE_MASK (31 << CS2100_DEVID_DEVICE_SHIFT)
  76. # define CS2100_DEVID_DEVICE (0 << CS2100_DEVID_DEVICE_SHIFT)
  77. /* Device Control */
  78. #define CS2100_DEVCTL_CLKOUTDIS (1 << 0) /* Bit 0: CLK_OUT disable */
  79. #define CS2100_DEVCTL_AUXOUTDIS (1 << 1) /* Bit 1: AUX_OUT disable */
  80. #define CS2100_DEVCTL_UNLOCK (1 << 7) /* Bit 7: Unlock PLL */
  81. /* Device Configuration 1 */
  82. #define CS2100_DEVCFG1_ENDEVCFG1 (1 << 0) /* Bit 0: Enable 1 */
  83. #define CS2100_DEVCFG1_AUXOUTSRC_SHIFT (1) /* Bits 1-2: Source of AUX_OUT signal */
  84. #define CS2100_DEVCFG1_AUXOUTSRC_MASK (3 << CS2100_DEVCFG1_AUXOUTSRC_SHIFT)
  85. # define CS2100_DEVCFG1_AUXOUTSRC_REFCLK (0 << CS2100_DEVCFG1_AUXOUTSRC_SHIFT) /* RefClk */
  86. # define CS2100_DEVCFG1_AUXOUTSRC_CLKIN (1 << CS2100_DEVCFG1_AUXOUTSRC_SHIFT) /* CLK_IN */
  87. # define CS2100_DEVCFG1_AUXOUTSRC_CLKOUT (2 << CS2100_DEVCFG1_AUXOUTSRC_SHIFT) /* CLK_OUT */
  88. # define CS2100_DEVCFG1_AUXOUTSRC_PLLLOCK (3 << CS2100_DEVCFG1_AUXOUTSRC_SHIFT) /* PLL Lock Status Indicator*/
  89. #define CS2100_DEVCFG1_RMODSEL_SHIFT (5) /* Bit 5-7: Selects R-Mod value */
  90. #define CS2100_DEVCFG1_RMODSEL_MASK (7 << CS2100_DEVCFG1_RMODSEL_SHIFT)
  91. # define CS2100_DEVCFG1_RMODSEL_NONE (0 << CS2100_DEVCFG1_RMODSEL_SHIFT) /* Left-shift R-value by 0 (x 1) */
  92. # define CS2100_DEVCFG1_RMODSEL_MUL2 (1 << CS2100_DEVCFG1_RMODSEL_SHIFT) /* Left-shift R-value by 1 (x 2) */
  93. # define CS2100_DEVCFG1_RMODSEL_MUL4 (2 << CS2100_DEVCFG1_RMODSEL_SHIFT) /* Left-shift R-value by 2 (x 4) */
  94. # define CS2100_DEVCFG1_RMODSEL_MUL8 (3 << CS2100_DEVCFG1_RMODSEL_SHIFT) /* Left-shift R-value by 3 (x 8) */
  95. # define CS2100_DEVCFG1_RMODSEL_DIV2 (4 << CS2100_DEVCFG1_RMODSEL_SHIFT) /* Right-shift R-value by 1 (÷ 2) */
  96. # define CS2100_DEVCFG1_RMODSEL_DIV4 (5 << CS2100_DEVCFG1_RMODSEL_SHIFT) /* Right-shift R-value by 2 (÷ 4) */
  97. # define CS2100_DEVCFG1_RMODSEL_DIV8 (6 << CS2100_DEVCFG1_RMODSEL_SHIFT) /* Right-shift R-value by 3 (÷ 8) */
  98. # define CS2100_DEVCFG1_RMODSEL_DIV16 (7 << CS2100_DEVCFG1_RMODSEL_SHIFT) /* Right-shift R-value by 4 (÷ 16) */
  99. /* Global Configuration */
  100. #define CS2100_GBLCFG_ENDEVCFG2 (1 << 0) /* Bit 0: Enable 2 */
  101. #define CS2100_GBLCFG_FREEZE (1 << 3) /* Bit 3: Mods not applied until unfrozen */
  102. /* Ratio: Bits 0-31 (4 x 8-bit values) */
  103. /* Function Configuration 1 */
  104. #define CS2100_FNCCFG1_REFCLKDIV_SHIFT (3) /* Bits 3-4: Reference Clock Input Divider */
  105. #define CS2100_FNCCFG1_REFCLKDIV_MASK (3 << CS2100_FNCCFG1_REFCLKDIV_SHIFT)
  106. # define CS2100_FNCCFG1_REFCLKDIV_DIV4 (3 << CS2100_FNCCFG1_REFCLKDIV_SHIFT) /* ÷ 4. 32 MHz to 75 MHz (50 MHz with XTI) */
  107. # define CS2100_FNCCFG1_REFCLKDIV_DIV2 (3 << CS2100_FNCCFG1_REFCLKDIV_SHIFT) /* ÷ 2. 16 MHz to 37.5 MHz */
  108. # define CS2100_FNCCFG1_REFCLKDIV_NONE (3 << CS2100_FNCCFG1_REFCLKDIV_SHIFT) /* ÷ 1. 8 MHz to 18.75 MHz */
  109. #define CS2100_FNCCFG1_AUXLOCKCFG_MASK (1 << 6) /* Bit 6: AUX PLL Lock Output Configuration */
  110. # define CS2100_FNCCFG1_AUXLOCKCFG_PP (0 << 6) /* 0=Push-Pull */
  111. # define CS2100_FNCCFG1_AUXLOCKCFG_PP (1 << 6) /* 1=Open Drain */
  112. #define CS2100_FNCCFG1_CLKSKIPEN (1 << 7) /* Bit 7: Clock Skip Enable */
  113. /* Function Configuration 2 */
  114. #define CS2100_FNCCFG2_LFRATIOCFG (1 << 3) /* Bit 3: Low-Frequency Ratio Configuration */
  115. #define CS2100_FNCCFG2_CLKOUTUNL (1 << 4) /* Bit 4: Enable PLL Clock Output on Unlock */
  116. /* Function Configuration 3 */
  117. #define CS2100_FNCCFG3_CLKINBW_SHIFT (4) /* Bits 4-6: Clock Input Bandwidth */
  118. #define CS2100_FNCCFG3_CLKINBW_MASK (7 << CS2100_FNCCFG3_CLKINBW_SHIFT)
  119. # define CS2100_FNCCFG3_CLKINBW_1HZ (0 << CS2100_FNCCFG3_CLKINBW_SHIFT) /* 1 Hz */
  120. # define CS2100_FNCCFG3_CLKINBW_2HZ (1 << CS2100_FNCCFG3_CLKINBW_SHIFT) /* 2 Hz */
  121. # define CS2100_FNCCFG3_CLKINBW_4HZ (2 << CS2100_FNCCFG3_CLKINBW_SHIFT) /* 4 Hz */
  122. # define CS2100_FNCCFG3_CLKINBW_8HZ (3 << CS2100_FNCCFG3_CLKINBW_SHIFT) /* 8 Hz */
  123. # define CS2100_FNCCFG3_CLKINBW_16HZ (4 << CS2100_FNCCFG3_CLKINBW_SHIFT) /* 16 Hz */
  124. # define CS2100_FNCCFG3_CLKINBW_32HZ (5 << CS2100_FNCCFG3_CLKINBW_SHIFT) /* 32 Hz */
  125. # define CS2100_FNCCFG3_CLKINBW_64HZ (6 << CS2100_FNCCFG3_CLKINBW_SHIFT) /* 64 Hz */
  126. # define CS2100_FNCCFG3_CLKINBW_128HZ (7 << CS2100_FNCCFG3_CLKINBW_SHIFT) /* 128 Hz */
  127. /********************************************************************************************
  128. * Public Types
  129. ********************************************************************************************/
  130. struct cs2100_config_s
  131. {
  132. FAR struct i2c_master_s *i2c; /* Instance of an I2C interface */
  133. uint32_t i2cfreq; /* I2C frequency */
  134. uint32_t refclk; /* RefClk/XTAL frequency */
  135. uint32_t clkin; /* Frequency CLK_IN provided to the CS2100-CP */
  136. uint32_t clkout; /* Desired CLK_OUT frequency */
  137. uint8_t i2caddr; /* CP2100-CP I2C address */
  138. uint8_t loopbw; /* Minimum loop bandwidth: 1-128 */
  139. bool xtal; /* false: Refclck, true: Crystal on XTI/XTO */
  140. };
  141. /********************************************************************************************
  142. * Public Data
  143. ********************************************************************************************/
  144. #ifdef __cplusplus
  145. #define EXTERN extern "C"
  146. extern "C"
  147. {
  148. #else
  149. #define EXTERN extern
  150. #endif
  151. /********************************************************************************************
  152. * Public Function Prototypes
  153. ********************************************************************************************/
  154. struct i2c_master_s; /* Forward reference */
  155. /********************************************************************************************
  156. * Name: cs2100_enable
  157. *
  158. * Description:
  159. * Enable CS2100 CLK_OUT using the provide parameters
  160. *
  161. * Input Parameters:
  162. * config - CS2100-CP configuration
  163. *
  164. * Returned Value:
  165. * Zero (OK) on success; a negated errno value on failure.
  166. *
  167. ********************************************************************************************/
  168. int cs2100_enable(FAR const struct cs2100_config_s *config);
  169. /********************************************************************************************
  170. * Name: cs2100_disable
  171. *
  172. * Description:
  173. * Disable CS2100 CLK_OUT
  174. *
  175. * Input Parameters:
  176. * config - CS2100-CP configuration (Needed only for I2C access: i2c and i2caddr)
  177. *
  178. * Returned Value:
  179. * Zero (OK) on success; a negated errno value on failure.
  180. *
  181. ********************************************************************************************/
  182. int cs2100_disable(FAR const struct cs2100_config_s *config);
  183. /********************************************************************************************
  184. * Name: cs2100_dump
  185. *
  186. * Description:
  187. * Dump CS2100-CP registers to the SysLog
  188. *
  189. * Input Parameters:
  190. * config - CS2100-CP configuration (Needed only for I2C access: i2c and i2caddr)
  191. *
  192. * Returned Value:
  193. * Zero (OK) on success; a negated errno value on failure.
  194. *
  195. ********************************************************************************************/
  196. #ifdef CONFIG_CS2100CP_DEBUG
  197. int cs2100_dump(FAR const struct cs2100_config_s *config);
  198. #endif
  199. #undef EXTERN
  200. #ifdef __cplusplus
  201. }
  202. #endif
  203. #endif /* CONFIG_TIMERS_CS2100CP */
  204. #endif /* __INCLUDE_NUTTX_TIMERS_CS2100_CP_H */