npcm7xx_mft.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  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,
  157. (uint64_t)(60 * NANOSECONDS_PER_SECOND) /
  158. ((uint64_t)rpm * NPCM7XX_MFT_PULSE_PER_REVOLUTION));
  159. }
  160. if (count > NPCM7XX_MFT_MAX_CNT) {
  161. count = -1;
  162. } else {
  163. /* The CNT is a countdown value from NPCM7XX_MFT_MAX_CNT. */
  164. count = NPCM7XX_MFT_MAX_CNT - count;
  165. }
  166. stopped = npcm7xx_mft_compare(count, tgt, cpcfg);
  167. if (stopped == -1) {
  168. if (count == -1) {
  169. /* Underflow */
  170. state = NPCM7XX_CAPTURE_UNDERFLOW;
  171. } else {
  172. state = NPCM7XX_CAPTURE_SUCCEED;
  173. }
  174. } else {
  175. count = stopped;
  176. state = NPCM7XX_CAPTURE_COMPARE_HIT;
  177. }
  178. if (count != -1) {
  179. *cnt = count;
  180. }
  181. trace_npcm7xx_mft_rpm(clock->canonical_path, clock_get_hz(clock),
  182. state, count, rpm, duty);
  183. return state;
  184. }
  185. /*
  186. * Capture Fan RPM and update CNT and CR registers accordingly.
  187. * Raise IRQ if certain contidions are met in IEN.
  188. */
  189. static void npcm7xx_mft_capture(NPCM7xxMFTState *s)
  190. {
  191. int irq_level = 0;
  192. NPCM7xxMFTCaptureState state;
  193. int sel;
  194. uint8_t cpcfg;
  195. /*
  196. * If not mode 5, the behavior is undefined. We just do nothing in this
  197. * case.
  198. */
  199. if (!(s->regs[R_NPCM7XX_MFT_MCTRL] & NPCM7XX_MFT_MCTRL_MODE5)) {
  200. return;
  201. }
  202. /* Capture input A. */
  203. if (s->regs[R_NPCM7XX_MFT_MCTRL] & NPCM7XX_MFT_MCTRL_TAEN &&
  204. s->regs[R_NPCM7XX_MFT_CKC] & NPCM7XX_MFT_CKC_C1CSEL) {
  205. sel = s->regs[R_NPCM7XX_MFT_INASEL] & NPCM7XX_MFT_INASEL_SELA;
  206. cpcfg = NPCM7XX_MFT_CPCFG_GET_A(s->regs[R_NPCM7XX_MFT_CPCFG]);
  207. state = npcm7xx_mft_compute_cnt(s->clock_1,
  208. sel ? s->max_rpm[2] : s->max_rpm[0],
  209. sel ? s->duty[2] : s->duty[0],
  210. s->regs[R_NPCM7XX_MFT_CPA],
  211. cpcfg,
  212. &s->regs[R_NPCM7XX_MFT_CNT1]);
  213. switch (state) {
  214. case NPCM7XX_CAPTURE_SUCCEED:
  215. /* Interrupt on input capture on TAn transition - TAPND */
  216. s->regs[R_NPCM7XX_MFT_CRA] = s->regs[R_NPCM7XX_MFT_CNT1];
  217. s->regs[R_NPCM7XX_MFT_ICTRL] |= NPCM7XX_MFT_ICTRL_TAPND;
  218. if (s->regs[R_NPCM7XX_MFT_IEN] & NPCM7XX_MFT_IEN_TAIEN) {
  219. irq_level = 1;
  220. }
  221. break;
  222. case NPCM7XX_CAPTURE_COMPARE_HIT:
  223. /* Compare Hit - TEPND */
  224. s->regs[R_NPCM7XX_MFT_ICTRL] |= NPCM7XX_MFT_ICTRL_TEPND;
  225. if (s->regs[R_NPCM7XX_MFT_IEN] & NPCM7XX_MFT_IEN_TEIEN) {
  226. irq_level = 1;
  227. }
  228. break;
  229. case NPCM7XX_CAPTURE_UNDERFLOW:
  230. /* Underflow - TCPND */
  231. s->regs[R_NPCM7XX_MFT_ICTRL] |= NPCM7XX_MFT_ICTRL_TCPND;
  232. if (s->regs[R_NPCM7XX_MFT_IEN] & NPCM7XX_MFT_IEN_TCIEN) {
  233. irq_level = 1;
  234. }
  235. break;
  236. default:
  237. g_assert_not_reached();
  238. }
  239. }
  240. /* Capture input B. */
  241. if (s->regs[R_NPCM7XX_MFT_MCTRL] & NPCM7XX_MFT_MCTRL_TBEN &&
  242. s->regs[R_NPCM7XX_MFT_CKC] & NPCM7XX_MFT_CKC_C2CSEL) {
  243. sel = s->regs[R_NPCM7XX_MFT_INBSEL] & NPCM7XX_MFT_INBSEL_SELB;
  244. cpcfg = NPCM7XX_MFT_CPCFG_GET_B(s->regs[R_NPCM7XX_MFT_CPCFG]);
  245. state = npcm7xx_mft_compute_cnt(s->clock_2,
  246. sel ? s->max_rpm[3] : s->max_rpm[1],
  247. sel ? s->duty[3] : s->duty[1],
  248. s->regs[R_NPCM7XX_MFT_CPB],
  249. cpcfg,
  250. &s->regs[R_NPCM7XX_MFT_CNT2]);
  251. switch (state) {
  252. case NPCM7XX_CAPTURE_SUCCEED:
  253. /* Interrupt on input capture on TBn transition - TBPND */
  254. s->regs[R_NPCM7XX_MFT_CRB] = s->regs[R_NPCM7XX_MFT_CNT2];
  255. s->regs[R_NPCM7XX_MFT_ICTRL] |= NPCM7XX_MFT_ICTRL_TBPND;
  256. if (s->regs[R_NPCM7XX_MFT_IEN] & NPCM7XX_MFT_IEN_TBIEN) {
  257. irq_level = 1;
  258. }
  259. break;
  260. case NPCM7XX_CAPTURE_COMPARE_HIT:
  261. /* Compare Hit - TFPND */
  262. s->regs[R_NPCM7XX_MFT_ICTRL] |= NPCM7XX_MFT_ICTRL_TFPND;
  263. if (s->regs[R_NPCM7XX_MFT_IEN] & NPCM7XX_MFT_IEN_TFIEN) {
  264. irq_level = 1;
  265. }
  266. break;
  267. case NPCM7XX_CAPTURE_UNDERFLOW:
  268. /* Underflow - TDPND */
  269. s->regs[R_NPCM7XX_MFT_ICTRL] |= NPCM7XX_MFT_ICTRL_TDPND;
  270. if (s->regs[R_NPCM7XX_MFT_IEN] & NPCM7XX_MFT_IEN_TDIEN) {
  271. irq_level = 1;
  272. }
  273. break;
  274. default:
  275. g_assert_not_reached();
  276. }
  277. }
  278. trace_npcm7xx_mft_capture(DEVICE(s)->canonical_path, irq_level);
  279. qemu_set_irq(s->irq, irq_level);
  280. }
  281. /* Update clock for counters. */
  282. static void npcm7xx_mft_update_clock(void *opaque, ClockEvent event)
  283. {
  284. NPCM7xxMFTState *s = NPCM7XX_MFT(opaque);
  285. uint64_t prescaled_clock_period;
  286. prescaled_clock_period = clock_get(s->clock_in) *
  287. (s->regs[R_NPCM7XX_MFT_PRSC] + 1ULL);
  288. trace_npcm7xx_mft_update_clock(s->clock_in->canonical_path,
  289. s->regs[R_NPCM7XX_MFT_CKC],
  290. clock_get(s->clock_in),
  291. prescaled_clock_period);
  292. /* Update clock 1 */
  293. if (s->regs[R_NPCM7XX_MFT_CKC] & NPCM7XX_MFT_CKC_C1CSEL) {
  294. /* Clock is prescaled. */
  295. clock_update(s->clock_1, prescaled_clock_period);
  296. } else {
  297. /* Clock stopped. */
  298. clock_update(s->clock_1, 0);
  299. }
  300. /* Update clock 2 */
  301. if (s->regs[R_NPCM7XX_MFT_CKC] & NPCM7XX_MFT_CKC_C2CSEL) {
  302. /* Clock is prescaled. */
  303. clock_update(s->clock_2, prescaled_clock_period);
  304. } else {
  305. /* Clock stopped. */
  306. clock_update(s->clock_2, 0);
  307. }
  308. npcm7xx_mft_capture(s);
  309. }
  310. static uint64_t npcm7xx_mft_read(void *opaque, hwaddr offset, unsigned size)
  311. {
  312. NPCM7xxMFTState *s = NPCM7XX_MFT(opaque);
  313. uint16_t value = 0;
  314. switch (offset) {
  315. case A_NPCM7XX_MFT_ICLR:
  316. qemu_log_mask(LOG_GUEST_ERROR,
  317. "%s: register @ 0x%04" HWADDR_PRIx " is write-only\n",
  318. __func__, offset);
  319. break;
  320. default:
  321. value = s->regs[offset / 2];
  322. }
  323. trace_npcm7xx_mft_read(DEVICE(s)->canonical_path, offset, value);
  324. return value;
  325. }
  326. static void npcm7xx_mft_write(void *opaque, hwaddr offset,
  327. uint64_t v, unsigned size)
  328. {
  329. NPCM7xxMFTState *s = NPCM7XX_MFT(opaque);
  330. trace_npcm7xx_mft_write(DEVICE(s)->canonical_path, offset, v);
  331. switch (offset) {
  332. case A_NPCM7XX_MFT_ICLR:
  333. npcm7xx_mft_clear_interrupt(s, v);
  334. break;
  335. case A_NPCM7XX_MFT_CKC:
  336. case A_NPCM7XX_MFT_PRSC:
  337. s->regs[offset / 2] = v;
  338. npcm7xx_mft_update_clock(s, ClockUpdate);
  339. break;
  340. default:
  341. s->regs[offset / 2] = v;
  342. npcm7xx_mft_capture(s);
  343. break;
  344. }
  345. }
  346. static bool npcm7xx_mft_check_mem_op(void *opaque, hwaddr offset,
  347. unsigned size, bool is_write,
  348. MemTxAttrs attrs)
  349. {
  350. switch (offset) {
  351. /* 16-bit registers. Must be accessed with 16-bit read/write.*/
  352. case A_NPCM7XX_MFT_CNT1:
  353. case A_NPCM7XX_MFT_CRA:
  354. case A_NPCM7XX_MFT_CRB:
  355. case A_NPCM7XX_MFT_CNT2:
  356. case A_NPCM7XX_MFT_CPA:
  357. case A_NPCM7XX_MFT_CPB:
  358. return size == 2;
  359. /* 8-bit registers. Must be accessed with 8-bit read/write.*/
  360. case A_NPCM7XX_MFT_PRSC:
  361. case A_NPCM7XX_MFT_CKC:
  362. case A_NPCM7XX_MFT_MCTRL:
  363. case A_NPCM7XX_MFT_ICTRL:
  364. case A_NPCM7XX_MFT_ICLR:
  365. case A_NPCM7XX_MFT_IEN:
  366. case A_NPCM7XX_MFT_CPCFG:
  367. case A_NPCM7XX_MFT_INASEL:
  368. case A_NPCM7XX_MFT_INBSEL:
  369. return size == 1;
  370. default:
  371. /* Invalid registers. */
  372. return false;
  373. }
  374. }
  375. static void npcm7xx_mft_get_max_rpm(Object *obj, Visitor *v, const char *name,
  376. void *opaque, Error **errp)
  377. {
  378. visit_type_uint32(v, name, (uint32_t *)opaque, errp);
  379. }
  380. static void npcm7xx_mft_set_max_rpm(Object *obj, Visitor *v, const char *name,
  381. void *opaque, Error **errp)
  382. {
  383. NPCM7xxMFTState *s = NPCM7XX_MFT(obj);
  384. uint32_t *max_rpm = opaque;
  385. uint32_t value;
  386. if (!visit_type_uint32(v, name, &value, errp)) {
  387. return;
  388. }
  389. *max_rpm = value;
  390. npcm7xx_mft_capture(s);
  391. }
  392. static void npcm7xx_mft_duty_handler(void *opaque, int n, int value)
  393. {
  394. NPCM7xxMFTState *s = NPCM7XX_MFT(opaque);
  395. trace_npcm7xx_mft_set_duty(DEVICE(s)->canonical_path, n, value);
  396. s->duty[n] = value;
  397. npcm7xx_mft_capture(s);
  398. }
  399. static const struct MemoryRegionOps npcm7xx_mft_ops = {
  400. .read = npcm7xx_mft_read,
  401. .write = npcm7xx_mft_write,
  402. .endianness = DEVICE_LITTLE_ENDIAN,
  403. .valid = {
  404. .min_access_size = 1,
  405. .max_access_size = 2,
  406. .unaligned = false,
  407. .accepts = npcm7xx_mft_check_mem_op,
  408. },
  409. };
  410. static void npcm7xx_mft_enter_reset(Object *obj, ResetType type)
  411. {
  412. NPCM7xxMFTState *s = NPCM7XX_MFT(obj);
  413. npcm7xx_mft_reset(s);
  414. }
  415. static void npcm7xx_mft_hold_reset(Object *obj, ResetType type)
  416. {
  417. NPCM7xxMFTState *s = NPCM7XX_MFT(obj);
  418. qemu_irq_lower(s->irq);
  419. }
  420. static void npcm7xx_mft_init(Object *obj)
  421. {
  422. NPCM7xxMFTState *s = NPCM7XX_MFT(obj);
  423. SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
  424. DeviceState *dev = DEVICE(obj);
  425. memory_region_init_io(&s->iomem, obj, &npcm7xx_mft_ops, s,
  426. TYPE_NPCM7XX_MFT, 4 * KiB);
  427. sysbus_init_mmio(sbd, &s->iomem);
  428. sysbus_init_irq(sbd, &s->irq);
  429. s->clock_in = qdev_init_clock_in(dev, "clock-in", npcm7xx_mft_update_clock,
  430. s, ClockUpdate);
  431. s->clock_1 = qdev_init_clock_out(dev, "clock1");
  432. s->clock_2 = qdev_init_clock_out(dev, "clock2");
  433. for (int i = 0; i < NPCM7XX_PWM_PER_MODULE; ++i) {
  434. object_property_add(obj, "max_rpm[*]", "uint32",
  435. npcm7xx_mft_get_max_rpm,
  436. npcm7xx_mft_set_max_rpm,
  437. NULL, &s->max_rpm[i]);
  438. }
  439. qdev_init_gpio_in_named(dev, npcm7xx_mft_duty_handler, "duty",
  440. NPCM7XX_MFT_FANIN_COUNT);
  441. }
  442. static const VMStateDescription vmstate_npcm7xx_mft = {
  443. .name = "npcm7xx-mft-module",
  444. .version_id = 0,
  445. .minimum_version_id = 0,
  446. .fields = (const VMStateField[]) {
  447. VMSTATE_CLOCK(clock_in, NPCM7xxMFTState),
  448. VMSTATE_CLOCK(clock_1, NPCM7xxMFTState),
  449. VMSTATE_CLOCK(clock_2, NPCM7xxMFTState),
  450. VMSTATE_UINT16_ARRAY(regs, NPCM7xxMFTState, NPCM7XX_MFT_NR_REGS),
  451. VMSTATE_UINT32_ARRAY(max_rpm, NPCM7xxMFTState, NPCM7XX_MFT_FANIN_COUNT),
  452. VMSTATE_UINT32_ARRAY(duty, NPCM7xxMFTState, NPCM7XX_MFT_FANIN_COUNT),
  453. VMSTATE_END_OF_LIST(),
  454. },
  455. };
  456. static void npcm7xx_mft_class_init(ObjectClass *klass, void *data)
  457. {
  458. ResettableClass *rc = RESETTABLE_CLASS(klass);
  459. DeviceClass *dc = DEVICE_CLASS(klass);
  460. dc->desc = "NPCM7xx MFT Controller";
  461. dc->vmsd = &vmstate_npcm7xx_mft;
  462. rc->phases.enter = npcm7xx_mft_enter_reset;
  463. rc->phases.hold = npcm7xx_mft_hold_reset;
  464. }
  465. static const TypeInfo npcm7xx_mft_info = {
  466. .name = TYPE_NPCM7XX_MFT,
  467. .parent = TYPE_SYS_BUS_DEVICE,
  468. .instance_size = sizeof(NPCM7xxMFTState),
  469. .class_init = npcm7xx_mft_class_init,
  470. .instance_init = npcm7xx_mft_init,
  471. };
  472. static void npcm7xx_mft_register_type(void)
  473. {
  474. type_register_static(&npcm7xx_mft_info);
  475. }
  476. type_init(npcm7xx_mft_register_type);