2
0

npcm7xx_mft.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. /*
  2. * Nuvoton NPCM7xx MFT Module
  3. *
  4. * Copyright 2021 Google LLC
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14. * for more details.
  15. */
  16. #include "qemu/osdep.h"
  17. #include "hw/irq.h"
  18. #include "hw/qdev-clock.h"
  19. #include "hw/qdev-properties.h"
  20. #include "hw/misc/npcm7xx_mft.h"
  21. #include "hw/misc/npcm7xx_pwm.h"
  22. #include "hw/registerfields.h"
  23. #include "migration/vmstate.h"
  24. #include "qapi/error.h"
  25. #include "qapi/visitor.h"
  26. #include "qemu/bitops.h"
  27. #include "qemu/error-report.h"
  28. #include "qemu/log.h"
  29. #include "qemu/module.h"
  30. #include "qemu/timer.h"
  31. #include "qemu/units.h"
  32. #include "trace.h"
  33. /*
  34. * Some of the registers can only accessed via 16-bit ops and some can only
  35. * be accessed via 8-bit ops. However we mark all of them using REG16 to
  36. * simplify implementation. npcm7xx_mft_check_mem_op checks the access length
  37. * of memory operations.
  38. */
  39. REG16(NPCM7XX_MFT_CNT1, 0x00);
  40. REG16(NPCM7XX_MFT_CRA, 0x02);
  41. REG16(NPCM7XX_MFT_CRB, 0x04);
  42. REG16(NPCM7XX_MFT_CNT2, 0x06);
  43. REG16(NPCM7XX_MFT_PRSC, 0x08);
  44. REG16(NPCM7XX_MFT_CKC, 0x0a);
  45. REG16(NPCM7XX_MFT_MCTRL, 0x0c);
  46. REG16(NPCM7XX_MFT_ICTRL, 0x0e);
  47. REG16(NPCM7XX_MFT_ICLR, 0x10);
  48. REG16(NPCM7XX_MFT_IEN, 0x12);
  49. REG16(NPCM7XX_MFT_CPA, 0x14);
  50. REG16(NPCM7XX_MFT_CPB, 0x16);
  51. REG16(NPCM7XX_MFT_CPCFG, 0x18);
  52. REG16(NPCM7XX_MFT_INASEL, 0x1a);
  53. REG16(NPCM7XX_MFT_INBSEL, 0x1c);
  54. /* Register Fields */
  55. #define NPCM7XX_MFT_CKC_C2CSEL BIT(3)
  56. #define NPCM7XX_MFT_CKC_C1CSEL BIT(0)
  57. #define NPCM7XX_MFT_MCTRL_TBEN BIT(6)
  58. #define NPCM7XX_MFT_MCTRL_TAEN BIT(5)
  59. #define NPCM7XX_MFT_MCTRL_TBEDG BIT(4)
  60. #define NPCM7XX_MFT_MCTRL_TAEDG BIT(3)
  61. #define NPCM7XX_MFT_MCTRL_MODE5 BIT(2)
  62. #define NPCM7XX_MFT_ICTRL_TFPND BIT(5)
  63. #define NPCM7XX_MFT_ICTRL_TEPND BIT(4)
  64. #define NPCM7XX_MFT_ICTRL_TDPND BIT(3)
  65. #define NPCM7XX_MFT_ICTRL_TCPND BIT(2)
  66. #define NPCM7XX_MFT_ICTRL_TBPND BIT(1)
  67. #define NPCM7XX_MFT_ICTRL_TAPND BIT(0)
  68. #define NPCM7XX_MFT_ICLR_TFCLR BIT(5)
  69. #define NPCM7XX_MFT_ICLR_TECLR BIT(4)
  70. #define NPCM7XX_MFT_ICLR_TDCLR BIT(3)
  71. #define NPCM7XX_MFT_ICLR_TCCLR BIT(2)
  72. #define NPCM7XX_MFT_ICLR_TBCLR BIT(1)
  73. #define NPCM7XX_MFT_ICLR_TACLR BIT(0)
  74. #define NPCM7XX_MFT_IEN_TFIEN BIT(5)
  75. #define NPCM7XX_MFT_IEN_TEIEN BIT(4)
  76. #define NPCM7XX_MFT_IEN_TDIEN BIT(3)
  77. #define NPCM7XX_MFT_IEN_TCIEN BIT(2)
  78. #define NPCM7XX_MFT_IEN_TBIEN BIT(1)
  79. #define NPCM7XX_MFT_IEN_TAIEN BIT(0)
  80. #define NPCM7XX_MFT_CPCFG_GET_B(rv) extract8((rv), 4, 4)
  81. #define NPCM7XX_MFT_CPCFG_GET_A(rv) extract8((rv), 0, 4)
  82. #define NPCM7XX_MFT_CPCFG_HIEN BIT(3)
  83. #define NPCM7XX_MFT_CPCFG_EQEN BIT(2)
  84. #define NPCM7XX_MFT_CPCFG_LOEN BIT(1)
  85. #define NPCM7XX_MFT_CPCFG_CPSEL BIT(0)
  86. #define NPCM7XX_MFT_INASEL_SELA BIT(0)
  87. #define NPCM7XX_MFT_INBSEL_SELB BIT(0)
  88. /* Max CNT values of the module. The CNT value is a countdown from it. */
  89. #define NPCM7XX_MFT_MAX_CNT 0xFFFF
  90. /* Each fan revolution should generated 2 pulses */
  91. #define NPCM7XX_MFT_PULSE_PER_REVOLUTION 2
  92. typedef enum NPCM7xxMFTCaptureState {
  93. /* capture succeeded with a valid CNT value. */
  94. NPCM7XX_CAPTURE_SUCCEED,
  95. /* capture stopped prematurely due to reaching CPCFG condition. */
  96. NPCM7XX_CAPTURE_COMPARE_HIT,
  97. /* capture fails since it reaches underflow condition for CNT. */
  98. NPCM7XX_CAPTURE_UNDERFLOW,
  99. } NPCM7xxMFTCaptureState;
  100. static void npcm7xx_mft_reset(NPCM7xxMFTState *s)
  101. {
  102. int i;
  103. /* Only registers PRSC ~ INBSEL need to be reset. */
  104. for (i = R_NPCM7XX_MFT_PRSC; i <= R_NPCM7XX_MFT_INBSEL; ++i) {
  105. s->regs[i] = 0;
  106. }
  107. }
  108. static void npcm7xx_mft_clear_interrupt(NPCM7xxMFTState *s, uint8_t iclr)
  109. {
  110. /*
  111. * Clear bits in ICTRL where corresponding bits in iclr is 1.
  112. * Both iclr and ictrl are 8-bit regs. (See npcm7xx_mft_check_mem_op)
  113. */
  114. s->regs[R_NPCM7XX_MFT_ICTRL] &= ~iclr;
  115. }
  116. /*
  117. * If the CPCFG's condition should be triggered during count down from
  118. * NPCM7XX_MFT_MAX_CNT to src if compared to tgt, return the count when
  119. * the condition is triggered.
  120. * Otherwise return -1.
  121. * Since tgt is uint16_t it must always <= NPCM7XX_MFT_MAX_CNT.
  122. */
  123. static int npcm7xx_mft_compare(int32_t src, uint16_t tgt, uint8_t cpcfg)
  124. {
  125. if (cpcfg & NPCM7XX_MFT_CPCFG_HIEN) {
  126. return NPCM7XX_MFT_MAX_CNT;
  127. }
  128. if ((cpcfg & NPCM7XX_MFT_CPCFG_EQEN) && (src <= tgt)) {
  129. return tgt;
  130. }
  131. if ((cpcfg & NPCM7XX_MFT_CPCFG_LOEN) && (tgt > 0) && (src < tgt)) {
  132. return tgt - 1;
  133. }
  134. return -1;
  135. }
  136. /* Compute CNT according to corresponding fan's RPM. */
  137. static NPCM7xxMFTCaptureState npcm7xx_mft_compute_cnt(
  138. Clock *clock, uint32_t max_rpm, uint32_t duty, uint16_t tgt,
  139. uint8_t cpcfg, uint16_t *cnt)
  140. {
  141. uint32_t rpm = (uint64_t)max_rpm * (uint64_t)duty / NPCM7XX_PWM_MAX_DUTY;
  142. int32_t count;
  143. int stopped;
  144. NPCM7xxMFTCaptureState state;
  145. if (rpm == 0) {
  146. /*
  147. * If RPM = 0, capture won't happen. CNT will continue count down.
  148. * So it's effective equivalent to have a cnt > NPCM7XX_MFT_MAX_CNT
  149. */
  150. count = NPCM7XX_MFT_MAX_CNT + 1;
  151. } else {
  152. /*
  153. * RPM = revolution/min. The time for one revlution (in ns) is
  154. * MINUTE_TO_NANOSECOND / RPM.
  155. */
  156. count = clock_ns_to_ticks(clock, (60 * NANOSECONDS_PER_SECOND) /
  157. (rpm * NPCM7XX_MFT_PULSE_PER_REVOLUTION));
  158. }
  159. if (count > NPCM7XX_MFT_MAX_CNT) {
  160. count = -1;
  161. } else {
  162. /* The CNT is a countdown value from NPCM7XX_MFT_MAX_CNT. */
  163. count = NPCM7XX_MFT_MAX_CNT - count;
  164. }
  165. stopped = npcm7xx_mft_compare(count, tgt, cpcfg);
  166. if (stopped == -1) {
  167. if (count == -1) {
  168. /* Underflow */
  169. state = NPCM7XX_CAPTURE_UNDERFLOW;
  170. } else {
  171. state = NPCM7XX_CAPTURE_SUCCEED;
  172. }
  173. } else {
  174. count = stopped;
  175. state = NPCM7XX_CAPTURE_COMPARE_HIT;
  176. }
  177. if (count != -1) {
  178. *cnt = count;
  179. }
  180. trace_npcm7xx_mft_rpm(clock->canonical_path, clock_get_hz(clock),
  181. state, count, rpm, duty);
  182. return state;
  183. }
  184. /*
  185. * Capture Fan RPM and update CNT and CR registers accordingly.
  186. * Raise IRQ if certain contidions are met in IEN.
  187. */
  188. static void npcm7xx_mft_capture(NPCM7xxMFTState *s)
  189. {
  190. int irq_level = 0;
  191. NPCM7xxMFTCaptureState state;
  192. int sel;
  193. uint8_t cpcfg;
  194. /*
  195. * If not mode 5, the behavior is undefined. We just do nothing in this
  196. * case.
  197. */
  198. if (!(s->regs[R_NPCM7XX_MFT_MCTRL] & NPCM7XX_MFT_MCTRL_MODE5)) {
  199. return;
  200. }
  201. /* Capture input A. */
  202. if (s->regs[R_NPCM7XX_MFT_MCTRL] & NPCM7XX_MFT_MCTRL_TAEN &&
  203. s->regs[R_NPCM7XX_MFT_CKC] & NPCM7XX_MFT_CKC_C1CSEL) {
  204. sel = s->regs[R_NPCM7XX_MFT_INASEL] & NPCM7XX_MFT_INASEL_SELA;
  205. cpcfg = NPCM7XX_MFT_CPCFG_GET_A(s->regs[R_NPCM7XX_MFT_CPCFG]);
  206. state = npcm7xx_mft_compute_cnt(s->clock_1,
  207. sel ? s->max_rpm[2] : s->max_rpm[0],
  208. sel ? s->duty[2] : s->duty[0],
  209. s->regs[R_NPCM7XX_MFT_CPA],
  210. cpcfg,
  211. &s->regs[R_NPCM7XX_MFT_CNT1]);
  212. switch (state) {
  213. case NPCM7XX_CAPTURE_SUCCEED:
  214. /* Interrupt on input capture on TAn transition - TAPND */
  215. s->regs[R_NPCM7XX_MFT_CRA] = s->regs[R_NPCM7XX_MFT_CNT1];
  216. s->regs[R_NPCM7XX_MFT_ICTRL] |= NPCM7XX_MFT_ICTRL_TAPND;
  217. if (s->regs[R_NPCM7XX_MFT_IEN] & NPCM7XX_MFT_IEN_TAIEN) {
  218. irq_level = 1;
  219. }
  220. break;
  221. case NPCM7XX_CAPTURE_COMPARE_HIT:
  222. /* Compare Hit - TEPND */
  223. s->regs[R_NPCM7XX_MFT_ICTRL] |= NPCM7XX_MFT_ICTRL_TEPND;
  224. if (s->regs[R_NPCM7XX_MFT_IEN] & NPCM7XX_MFT_IEN_TEIEN) {
  225. irq_level = 1;
  226. }
  227. break;
  228. case NPCM7XX_CAPTURE_UNDERFLOW:
  229. /* Underflow - TCPND */
  230. s->regs[R_NPCM7XX_MFT_ICTRL] |= NPCM7XX_MFT_ICTRL_TCPND;
  231. if (s->regs[R_NPCM7XX_MFT_IEN] & NPCM7XX_MFT_IEN_TCIEN) {
  232. irq_level = 1;
  233. }
  234. break;
  235. default:
  236. g_assert_not_reached();
  237. }
  238. }
  239. /* Capture input B. */
  240. if (s->regs[R_NPCM7XX_MFT_MCTRL] & NPCM7XX_MFT_MCTRL_TBEN &&
  241. s->regs[R_NPCM7XX_MFT_CKC] & NPCM7XX_MFT_CKC_C2CSEL) {
  242. sel = s->regs[R_NPCM7XX_MFT_INBSEL] & NPCM7XX_MFT_INBSEL_SELB;
  243. cpcfg = NPCM7XX_MFT_CPCFG_GET_B(s->regs[R_NPCM7XX_MFT_CPCFG]);
  244. state = npcm7xx_mft_compute_cnt(s->clock_2,
  245. sel ? s->max_rpm[3] : s->max_rpm[1],
  246. sel ? s->duty[3] : s->duty[1],
  247. s->regs[R_NPCM7XX_MFT_CPB],
  248. cpcfg,
  249. &s->regs[R_NPCM7XX_MFT_CNT2]);
  250. switch (state) {
  251. case NPCM7XX_CAPTURE_SUCCEED:
  252. /* Interrupt on input capture on TBn transition - TBPND */
  253. s->regs[R_NPCM7XX_MFT_CRB] = s->regs[R_NPCM7XX_MFT_CNT2];
  254. s->regs[R_NPCM7XX_MFT_ICTRL] |= NPCM7XX_MFT_ICTRL_TBPND;
  255. if (s->regs[R_NPCM7XX_MFT_IEN] & NPCM7XX_MFT_IEN_TBIEN) {
  256. irq_level = 1;
  257. }
  258. break;
  259. case NPCM7XX_CAPTURE_COMPARE_HIT:
  260. /* Compare Hit - TFPND */
  261. s->regs[R_NPCM7XX_MFT_ICTRL] |= NPCM7XX_MFT_ICTRL_TFPND;
  262. if (s->regs[R_NPCM7XX_MFT_IEN] & NPCM7XX_MFT_IEN_TFIEN) {
  263. irq_level = 1;
  264. }
  265. break;
  266. case NPCM7XX_CAPTURE_UNDERFLOW:
  267. /* Underflow - TDPND */
  268. s->regs[R_NPCM7XX_MFT_ICTRL] |= NPCM7XX_MFT_ICTRL_TDPND;
  269. if (s->regs[R_NPCM7XX_MFT_IEN] & NPCM7XX_MFT_IEN_TDIEN) {
  270. irq_level = 1;
  271. }
  272. break;
  273. default:
  274. g_assert_not_reached();
  275. }
  276. }
  277. trace_npcm7xx_mft_capture(DEVICE(s)->canonical_path, irq_level);
  278. qemu_set_irq(s->irq, irq_level);
  279. }
  280. /* Update clock for counters. */
  281. static void npcm7xx_mft_update_clock(void *opaque, ClockEvent event)
  282. {
  283. NPCM7xxMFTState *s = NPCM7XX_MFT(opaque);
  284. uint64_t prescaled_clock_period;
  285. prescaled_clock_period = clock_get(s->clock_in) *
  286. (s->regs[R_NPCM7XX_MFT_PRSC] + 1ULL);
  287. trace_npcm7xx_mft_update_clock(s->clock_in->canonical_path,
  288. s->regs[R_NPCM7XX_MFT_CKC],
  289. clock_get(s->clock_in),
  290. prescaled_clock_period);
  291. /* Update clock 1 */
  292. if (s->regs[R_NPCM7XX_MFT_CKC] & NPCM7XX_MFT_CKC_C1CSEL) {
  293. /* Clock is prescaled. */
  294. clock_update(s->clock_1, prescaled_clock_period);
  295. } else {
  296. /* Clock stopped. */
  297. clock_update(s->clock_1, 0);
  298. }
  299. /* Update clock 2 */
  300. if (s->regs[R_NPCM7XX_MFT_CKC] & NPCM7XX_MFT_CKC_C2CSEL) {
  301. /* Clock is prescaled. */
  302. clock_update(s->clock_2, prescaled_clock_period);
  303. } else {
  304. /* Clock stopped. */
  305. clock_update(s->clock_2, 0);
  306. }
  307. npcm7xx_mft_capture(s);
  308. }
  309. static uint64_t npcm7xx_mft_read(void *opaque, hwaddr offset, unsigned size)
  310. {
  311. NPCM7xxMFTState *s = NPCM7XX_MFT(opaque);
  312. uint16_t value = 0;
  313. switch (offset) {
  314. case A_NPCM7XX_MFT_ICLR:
  315. qemu_log_mask(LOG_GUEST_ERROR,
  316. "%s: register @ 0x%04" HWADDR_PRIx " is write-only\n",
  317. __func__, offset);
  318. break;
  319. default:
  320. value = s->regs[offset / 2];
  321. }
  322. trace_npcm7xx_mft_read(DEVICE(s)->canonical_path, offset, value);
  323. return value;
  324. }
  325. static void npcm7xx_mft_write(void *opaque, hwaddr offset,
  326. uint64_t v, unsigned size)
  327. {
  328. NPCM7xxMFTState *s = NPCM7XX_MFT(opaque);
  329. trace_npcm7xx_mft_write(DEVICE(s)->canonical_path, offset, v);
  330. switch (offset) {
  331. case A_NPCM7XX_MFT_ICLR:
  332. npcm7xx_mft_clear_interrupt(s, v);
  333. break;
  334. case A_NPCM7XX_MFT_CKC:
  335. case A_NPCM7XX_MFT_PRSC:
  336. s->regs[offset / 2] = v;
  337. npcm7xx_mft_update_clock(s, ClockUpdate);
  338. break;
  339. default:
  340. s->regs[offset / 2] = v;
  341. npcm7xx_mft_capture(s);
  342. break;
  343. }
  344. }
  345. static bool npcm7xx_mft_check_mem_op(void *opaque, hwaddr offset,
  346. unsigned size, bool is_write,
  347. MemTxAttrs attrs)
  348. {
  349. switch (offset) {
  350. /* 16-bit registers. Must be accessed with 16-bit read/write.*/
  351. case A_NPCM7XX_MFT_CNT1:
  352. case A_NPCM7XX_MFT_CRA:
  353. case A_NPCM7XX_MFT_CRB:
  354. case A_NPCM7XX_MFT_CNT2:
  355. case A_NPCM7XX_MFT_CPA:
  356. case A_NPCM7XX_MFT_CPB:
  357. return size == 2;
  358. /* 8-bit registers. Must be accessed with 8-bit read/write.*/
  359. case A_NPCM7XX_MFT_PRSC:
  360. case A_NPCM7XX_MFT_CKC:
  361. case A_NPCM7XX_MFT_MCTRL:
  362. case A_NPCM7XX_MFT_ICTRL:
  363. case A_NPCM7XX_MFT_ICLR:
  364. case A_NPCM7XX_MFT_IEN:
  365. case A_NPCM7XX_MFT_CPCFG:
  366. case A_NPCM7XX_MFT_INASEL:
  367. case A_NPCM7XX_MFT_INBSEL:
  368. return size == 1;
  369. default:
  370. /* Invalid registers. */
  371. return false;
  372. }
  373. }
  374. static void npcm7xx_mft_get_max_rpm(Object *obj, Visitor *v, const char *name,
  375. void *opaque, Error **errp)
  376. {
  377. visit_type_uint32(v, name, (uint32_t *)opaque, errp);
  378. }
  379. static void npcm7xx_mft_set_max_rpm(Object *obj, Visitor *v, const char *name,
  380. void *opaque, Error **errp)
  381. {
  382. NPCM7xxMFTState *s = NPCM7XX_MFT(obj);
  383. uint32_t *max_rpm = opaque;
  384. uint32_t value;
  385. if (!visit_type_uint32(v, name, &value, errp)) {
  386. return;
  387. }
  388. *max_rpm = value;
  389. npcm7xx_mft_capture(s);
  390. }
  391. static void npcm7xx_mft_duty_handler(void *opaque, int n, int value)
  392. {
  393. NPCM7xxMFTState *s = NPCM7XX_MFT(opaque);
  394. trace_npcm7xx_mft_set_duty(DEVICE(s)->canonical_path, n, value);
  395. s->duty[n] = value;
  396. npcm7xx_mft_capture(s);
  397. }
  398. static const struct MemoryRegionOps npcm7xx_mft_ops = {
  399. .read = npcm7xx_mft_read,
  400. .write = npcm7xx_mft_write,
  401. .endianness = DEVICE_LITTLE_ENDIAN,
  402. .valid = {
  403. .min_access_size = 1,
  404. .max_access_size = 2,
  405. .unaligned = false,
  406. .accepts = npcm7xx_mft_check_mem_op,
  407. },
  408. };
  409. static void npcm7xx_mft_enter_reset(Object *obj, ResetType type)
  410. {
  411. NPCM7xxMFTState *s = NPCM7XX_MFT(obj);
  412. npcm7xx_mft_reset(s);
  413. }
  414. static void npcm7xx_mft_hold_reset(Object *obj, ResetType type)
  415. {
  416. NPCM7xxMFTState *s = NPCM7XX_MFT(obj);
  417. qemu_irq_lower(s->irq);
  418. }
  419. static void npcm7xx_mft_init(Object *obj)
  420. {
  421. NPCM7xxMFTState *s = NPCM7XX_MFT(obj);
  422. SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
  423. DeviceState *dev = DEVICE(obj);
  424. memory_region_init_io(&s->iomem, obj, &npcm7xx_mft_ops, s,
  425. TYPE_NPCM7XX_MFT, 4 * KiB);
  426. sysbus_init_mmio(sbd, &s->iomem);
  427. sysbus_init_irq(sbd, &s->irq);
  428. s->clock_in = qdev_init_clock_in(dev, "clock-in", npcm7xx_mft_update_clock,
  429. s, ClockUpdate);
  430. s->clock_1 = qdev_init_clock_out(dev, "clock1");
  431. s->clock_2 = qdev_init_clock_out(dev, "clock2");
  432. for (int i = 0; i < NPCM7XX_PWM_PER_MODULE; ++i) {
  433. object_property_add(obj, "max_rpm[*]", "uint32",
  434. npcm7xx_mft_get_max_rpm,
  435. npcm7xx_mft_set_max_rpm,
  436. NULL, &s->max_rpm[i]);
  437. }
  438. qdev_init_gpio_in_named(dev, npcm7xx_mft_duty_handler, "duty",
  439. NPCM7XX_MFT_FANIN_COUNT);
  440. }
  441. static const VMStateDescription vmstate_npcm7xx_mft = {
  442. .name = "npcm7xx-mft-module",
  443. .version_id = 0,
  444. .minimum_version_id = 0,
  445. .fields = (const VMStateField[]) {
  446. VMSTATE_CLOCK(clock_in, NPCM7xxMFTState),
  447. VMSTATE_CLOCK(clock_1, NPCM7xxMFTState),
  448. VMSTATE_CLOCK(clock_2, NPCM7xxMFTState),
  449. VMSTATE_UINT16_ARRAY(regs, NPCM7xxMFTState, NPCM7XX_MFT_NR_REGS),
  450. VMSTATE_UINT32_ARRAY(max_rpm, NPCM7xxMFTState, NPCM7XX_MFT_FANIN_COUNT),
  451. VMSTATE_UINT32_ARRAY(duty, NPCM7xxMFTState, NPCM7XX_MFT_FANIN_COUNT),
  452. VMSTATE_END_OF_LIST(),
  453. },
  454. };
  455. static void npcm7xx_mft_class_init(ObjectClass *klass, void *data)
  456. {
  457. ResettableClass *rc = RESETTABLE_CLASS(klass);
  458. DeviceClass *dc = DEVICE_CLASS(klass);
  459. dc->desc = "NPCM7xx MFT Controller";
  460. dc->vmsd = &vmstate_npcm7xx_mft;
  461. rc->phases.enter = npcm7xx_mft_enter_reset;
  462. rc->phases.hold = npcm7xx_mft_hold_reset;
  463. }
  464. static const TypeInfo npcm7xx_mft_info = {
  465. .name = TYPE_NPCM7XX_MFT,
  466. .parent = TYPE_SYS_BUS_DEVICE,
  467. .instance_size = sizeof(NPCM7xxMFTState),
  468. .class_init = npcm7xx_mft_class_init,
  469. .instance_init = npcm7xx_mft_init,
  470. };
  471. static void npcm7xx_mft_register_type(void)
  472. {
  473. type_register_static(&npcm7xx_mft_info);
  474. }
  475. type_init(npcm7xx_mft_register_type);