1fc14176bSLuc Michel /* 2fc14176bSLuc Michel * BCM2835 CPRMAN clock manager 3fc14176bSLuc Michel * 4fc14176bSLuc Michel * Copyright (c) 2020 Luc Michel <luc@lmichel.fr> 5fc14176bSLuc Michel * 6fc14176bSLuc Michel * SPDX-License-Identifier: GPL-2.0-or-later 7fc14176bSLuc Michel */ 8fc14176bSLuc Michel 9fc14176bSLuc Michel /* 10fc14176bSLuc Michel * This peripheral is roughly divided into 3 main parts: 11fc14176bSLuc Michel * - the PLLs 12fc14176bSLuc Michel * - the PLL channels 13fc14176bSLuc Michel * - the clock muxes 14fc14176bSLuc Michel * 15fc14176bSLuc Michel * A main oscillator (xosc) feeds all the PLLs. Each PLLs has one or more 16fc14176bSLuc Michel * channels. Those channel are then connected to the clock muxes. Each mux has 17fc14176bSLuc Michel * multiples sources (usually the xosc, some of the PLL channels and some "test 18fc14176bSLuc Michel * debug" clocks). A mux is configured to select a given source through its 19fc14176bSLuc Michel * control register. Each mux has one output clock that also goes out of the 20fc14176bSLuc Michel * CPRMAN. This output clock usually connects to another peripheral in the SoC 21fc14176bSLuc Michel * (so a given mux is dedicated to a peripheral). 22fc14176bSLuc Michel * 23fc14176bSLuc Michel * At each level (PLL, channel and mux), the clock can be altered through 24fc14176bSLuc Michel * dividers (and multipliers in case of the PLLs), and can be disabled (in this 25fc14176bSLuc Michel * case, the next levels see no clock). 26fc14176bSLuc Michel * 27fc14176bSLuc Michel * This can be sum-up as follows (this is an example and not the actual BCM2835 28fc14176bSLuc Michel * clock tree): 29fc14176bSLuc Michel * 30fc14176bSLuc Michel * /-->[PLL]-|->[PLL channel]--... [mux]--> to peripherals 31fc14176bSLuc Michel * | |->[PLL channel] muxes takes [mux] 32fc14176bSLuc Michel * | \->[PLL channel] inputs from [mux] 33fc14176bSLuc Michel * | some channels [mux] 34fc14176bSLuc Michel * [xosc]---|-->[PLL]-|->[PLL channel] and other srcs [mux] 35fc14176bSLuc Michel * | \->[PLL channel] ...-->[mux] 36fc14176bSLuc Michel * | [mux] 37fc14176bSLuc Michel * \-->[PLL]--->[PLL channel] [mux] 38fc14176bSLuc Michel * 39fc14176bSLuc Michel * The page at https://elinux.org/The_Undocumented_Pi gives the actual clock 40fc14176bSLuc Michel * tree configuration. 4172813624SLuc Michel * 4272813624SLuc Michel * The CPRMAN exposes clock outputs with the name of the clock mux suffixed 4372813624SLuc Michel * with "-out" (e.g. "uart-out", "h264-out", ...). 44fc14176bSLuc Michel */ 45fc14176bSLuc Michel 46fc14176bSLuc Michel #include "qemu/osdep.h" 47fc14176bSLuc Michel #include "qemu/log.h" 48fc14176bSLuc Michel #include "migration/vmstate.h" 49fc14176bSLuc Michel #include "hw/qdev-properties.h" 50fc14176bSLuc Michel #include "hw/misc/bcm2835_cprman.h" 51fc14176bSLuc Michel #include "hw/misc/bcm2835_cprman_internals.h" 52fc14176bSLuc Michel #include "trace.h" 53fc14176bSLuc Michel 541e986e25SLuc Michel /* PLL */ 551e986e25SLuc Michel 56*83ad4695SLuc Michel static void pll_reset(DeviceState *dev) 57*83ad4695SLuc Michel { 58*83ad4695SLuc Michel CprmanPllState *s = CPRMAN_PLL(dev); 59*83ad4695SLuc Michel const PLLResetInfo *info = &PLL_RESET_INFO[s->id]; 60*83ad4695SLuc Michel 61*83ad4695SLuc Michel *s->reg_cm = info->cm; 62*83ad4695SLuc Michel *s->reg_a2w_ctrl = info->a2w_ctrl; 63*83ad4695SLuc Michel memcpy(s->reg_a2w_ana, info->a2w_ana, sizeof(info->a2w_ana)); 64*83ad4695SLuc Michel *s->reg_a2w_frac = info->a2w_frac; 65*83ad4695SLuc Michel } 66*83ad4695SLuc Michel 676d2b874cSLuc Michel static bool pll_is_locked(const CprmanPllState *pll) 686d2b874cSLuc Michel { 696d2b874cSLuc Michel return !FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, PWRDN) 706d2b874cSLuc Michel && !FIELD_EX32(*pll->reg_cm, CM_PLLx, ANARST); 716d2b874cSLuc Michel } 726d2b874cSLuc Michel 731e986e25SLuc Michel static void pll_update(CprmanPllState *pll) 741e986e25SLuc Michel { 756d2b874cSLuc Michel uint64_t freq, ndiv, fdiv, pdiv; 766d2b874cSLuc Michel 776d2b874cSLuc Michel if (!pll_is_locked(pll)) { 781e986e25SLuc Michel clock_update(pll->out, 0); 796d2b874cSLuc Michel return; 806d2b874cSLuc Michel } 816d2b874cSLuc Michel 826d2b874cSLuc Michel pdiv = FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, PDIV); 836d2b874cSLuc Michel 846d2b874cSLuc Michel if (!pdiv) { 856d2b874cSLuc Michel clock_update(pll->out, 0); 866d2b874cSLuc Michel return; 876d2b874cSLuc Michel } 886d2b874cSLuc Michel 896d2b874cSLuc Michel ndiv = FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, NDIV); 906d2b874cSLuc Michel fdiv = FIELD_EX32(*pll->reg_a2w_frac, A2W_PLLx_FRAC, FRAC); 916d2b874cSLuc Michel 926d2b874cSLuc Michel if (pll->reg_a2w_ana[1] & pll->prediv_mask) { 936d2b874cSLuc Michel /* The prescaler doubles the parent frequency */ 946d2b874cSLuc Michel ndiv *= 2; 956d2b874cSLuc Michel fdiv *= 2; 966d2b874cSLuc Michel } 976d2b874cSLuc Michel 986d2b874cSLuc Michel /* 996d2b874cSLuc Michel * We have a multiplier with an integer part (ndiv) and a fractional part 1006d2b874cSLuc Michel * (fdiv), and a divider (pdiv). 1016d2b874cSLuc Michel */ 1026d2b874cSLuc Michel freq = clock_get_hz(pll->xosc_in) * 1036d2b874cSLuc Michel ((ndiv << R_A2W_PLLx_FRAC_FRAC_LENGTH) + fdiv); 1046d2b874cSLuc Michel freq /= pdiv; 1056d2b874cSLuc Michel freq >>= R_A2W_PLLx_FRAC_FRAC_LENGTH; 1066d2b874cSLuc Michel 1076d2b874cSLuc Michel clock_update_hz(pll->out, freq); 1081e986e25SLuc Michel } 1091e986e25SLuc Michel 1101e986e25SLuc Michel static void pll_xosc_update(void *opaque) 1111e986e25SLuc Michel { 1121e986e25SLuc Michel pll_update(CPRMAN_PLL(opaque)); 1131e986e25SLuc Michel } 1141e986e25SLuc Michel 1151e986e25SLuc Michel static void pll_init(Object *obj) 1161e986e25SLuc Michel { 1171e986e25SLuc Michel CprmanPllState *s = CPRMAN_PLL(obj); 1181e986e25SLuc Michel 1191e986e25SLuc Michel s->xosc_in = qdev_init_clock_in(DEVICE(s), "xosc-in", pll_xosc_update, s); 1201e986e25SLuc Michel s->out = qdev_init_clock_out(DEVICE(s), "out"); 1211e986e25SLuc Michel } 1221e986e25SLuc Michel 1231e986e25SLuc Michel static const VMStateDescription pll_vmstate = { 1241e986e25SLuc Michel .name = TYPE_CPRMAN_PLL, 1251e986e25SLuc Michel .version_id = 1, 1261e986e25SLuc Michel .minimum_version_id = 1, 1271e986e25SLuc Michel .fields = (VMStateField[]) { 1281e986e25SLuc Michel VMSTATE_CLOCK(xosc_in, CprmanPllState), 1291e986e25SLuc Michel VMSTATE_END_OF_LIST() 1301e986e25SLuc Michel } 1311e986e25SLuc Michel }; 1321e986e25SLuc Michel 1331e986e25SLuc Michel static void pll_class_init(ObjectClass *klass, void *data) 1341e986e25SLuc Michel { 1351e986e25SLuc Michel DeviceClass *dc = DEVICE_CLASS(klass); 1361e986e25SLuc Michel 137*83ad4695SLuc Michel dc->reset = pll_reset; 1381e986e25SLuc Michel dc->vmsd = &pll_vmstate; 1391e986e25SLuc Michel } 1401e986e25SLuc Michel 1411e986e25SLuc Michel static const TypeInfo cprman_pll_info = { 1421e986e25SLuc Michel .name = TYPE_CPRMAN_PLL, 1431e986e25SLuc Michel .parent = TYPE_DEVICE, 1441e986e25SLuc Michel .instance_size = sizeof(CprmanPllState), 1451e986e25SLuc Michel .class_init = pll_class_init, 1461e986e25SLuc Michel .instance_init = pll_init, 1471e986e25SLuc Michel }; 1481e986e25SLuc Michel 1491e986e25SLuc Michel 15009d56bbcSLuc Michel /* PLL channel */ 15109d56bbcSLuc Michel 152*83ad4695SLuc Michel static void pll_channel_reset(DeviceState *dev) 153*83ad4695SLuc Michel { 154*83ad4695SLuc Michel CprmanPllChannelState *s = CPRMAN_PLL_CHANNEL(dev); 155*83ad4695SLuc Michel const PLLChannelResetInfo *info = &PLL_CHANNEL_RESET_INFO[s->id]; 156*83ad4695SLuc Michel 157*83ad4695SLuc Michel *s->reg_a2w_ctrl = info->a2w_ctrl; 158*83ad4695SLuc Michel } 159*83ad4695SLuc Michel 16095745811SLuc Michel static bool pll_channel_is_enabled(CprmanPllChannelState *channel) 16195745811SLuc Michel { 16295745811SLuc Michel /* 16395745811SLuc Michel * XXX I'm not sure of the purpose of the LOAD field. The Linux driver does 16495745811SLuc Michel * not set it when enabling the channel, but does clear it when disabling 16595745811SLuc Michel * it. 16695745811SLuc Michel */ 16795745811SLuc Michel return !FIELD_EX32(*channel->reg_a2w_ctrl, A2W_PLLx_CHANNELy, DISABLE) 16895745811SLuc Michel && !(*channel->reg_cm & channel->hold_mask); 16995745811SLuc Michel } 17095745811SLuc Michel 17109d56bbcSLuc Michel static void pll_channel_update(CprmanPllChannelState *channel) 17209d56bbcSLuc Michel { 17395745811SLuc Michel uint64_t freq, div; 17495745811SLuc Michel 17595745811SLuc Michel if (!pll_channel_is_enabled(channel)) { 17609d56bbcSLuc Michel clock_update(channel->out, 0); 17795745811SLuc Michel return; 17895745811SLuc Michel } 17995745811SLuc Michel 18095745811SLuc Michel div = FIELD_EX32(*channel->reg_a2w_ctrl, A2W_PLLx_CHANNELy, DIV); 18195745811SLuc Michel 18295745811SLuc Michel if (!div) { 18395745811SLuc Michel /* 18495745811SLuc Michel * It seems that when the divider value is 0, it is considered as 18595745811SLuc Michel * being maximum by the hardware (see the Linux driver). 18695745811SLuc Michel */ 18795745811SLuc Michel div = R_A2W_PLLx_CHANNELy_DIV_MASK; 18895745811SLuc Michel } 18995745811SLuc Michel 19095745811SLuc Michel /* Some channels have an additional fixed divider */ 19195745811SLuc Michel freq = clock_get_hz(channel->pll_in) / (div * channel->fixed_divider); 19295745811SLuc Michel 19395745811SLuc Michel clock_update_hz(channel->out, freq); 19409d56bbcSLuc Michel } 19509d56bbcSLuc Michel 19609d56bbcSLuc Michel /* Update a PLL and all its channels */ 19709d56bbcSLuc Michel static void pll_update_all_channels(BCM2835CprmanState *s, 19809d56bbcSLuc Michel CprmanPllState *pll) 19909d56bbcSLuc Michel { 20009d56bbcSLuc Michel size_t i; 20109d56bbcSLuc Michel 20209d56bbcSLuc Michel pll_update(pll); 20309d56bbcSLuc Michel 20409d56bbcSLuc Michel for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) { 20509d56bbcSLuc Michel CprmanPllChannelState *channel = &s->channels[i]; 20609d56bbcSLuc Michel if (channel->parent == pll->id) { 20709d56bbcSLuc Michel pll_channel_update(channel); 20809d56bbcSLuc Michel } 20909d56bbcSLuc Michel } 21009d56bbcSLuc Michel } 21109d56bbcSLuc Michel 21209d56bbcSLuc Michel static void pll_channel_pll_in_update(void *opaque) 21309d56bbcSLuc Michel { 21409d56bbcSLuc Michel pll_channel_update(CPRMAN_PLL_CHANNEL(opaque)); 21509d56bbcSLuc Michel } 21609d56bbcSLuc Michel 21709d56bbcSLuc Michel static void pll_channel_init(Object *obj) 21809d56bbcSLuc Michel { 21909d56bbcSLuc Michel CprmanPllChannelState *s = CPRMAN_PLL_CHANNEL(obj); 22009d56bbcSLuc Michel 22109d56bbcSLuc Michel s->pll_in = qdev_init_clock_in(DEVICE(s), "pll-in", 22209d56bbcSLuc Michel pll_channel_pll_in_update, s); 22309d56bbcSLuc Michel s->out = qdev_init_clock_out(DEVICE(s), "out"); 22409d56bbcSLuc Michel } 22509d56bbcSLuc Michel 22609d56bbcSLuc Michel static const VMStateDescription pll_channel_vmstate = { 22709d56bbcSLuc Michel .name = TYPE_CPRMAN_PLL_CHANNEL, 22809d56bbcSLuc Michel .version_id = 1, 22909d56bbcSLuc Michel .minimum_version_id = 1, 23009d56bbcSLuc Michel .fields = (VMStateField[]) { 23109d56bbcSLuc Michel VMSTATE_CLOCK(pll_in, CprmanPllChannelState), 23209d56bbcSLuc Michel VMSTATE_END_OF_LIST() 23309d56bbcSLuc Michel } 23409d56bbcSLuc Michel }; 23509d56bbcSLuc Michel 23609d56bbcSLuc Michel static void pll_channel_class_init(ObjectClass *klass, void *data) 23709d56bbcSLuc Michel { 23809d56bbcSLuc Michel DeviceClass *dc = DEVICE_CLASS(klass); 23909d56bbcSLuc Michel 240*83ad4695SLuc Michel dc->reset = pll_channel_reset; 24109d56bbcSLuc Michel dc->vmsd = &pll_channel_vmstate; 24209d56bbcSLuc Michel } 24309d56bbcSLuc Michel 24409d56bbcSLuc Michel static const TypeInfo cprman_pll_channel_info = { 24509d56bbcSLuc Michel .name = TYPE_CPRMAN_PLL_CHANNEL, 24609d56bbcSLuc Michel .parent = TYPE_DEVICE, 24709d56bbcSLuc Michel .instance_size = sizeof(CprmanPllChannelState), 24809d56bbcSLuc Michel .class_init = pll_channel_class_init, 24909d56bbcSLuc Michel .instance_init = pll_channel_init, 25009d56bbcSLuc Michel }; 25109d56bbcSLuc Michel 25209d56bbcSLuc Michel 25372813624SLuc Michel /* clock mux */ 25472813624SLuc Michel 255fc984085SLuc Michel static bool clock_mux_is_enabled(CprmanClockMuxState *mux) 256fc984085SLuc Michel { 257fc984085SLuc Michel return FIELD_EX32(*mux->reg_ctl, CM_CLOCKx_CTL, ENABLE); 258fc984085SLuc Michel } 259fc984085SLuc Michel 26072813624SLuc Michel static void clock_mux_update(CprmanClockMuxState *mux) 26172813624SLuc Michel { 262fc984085SLuc Michel uint64_t freq; 263fc984085SLuc Michel uint32_t div, src = FIELD_EX32(*mux->reg_ctl, CM_CLOCKx_CTL, SRC); 264fc984085SLuc Michel bool enabled = clock_mux_is_enabled(mux); 265fc984085SLuc Michel 266fc984085SLuc Michel *mux->reg_ctl = FIELD_DP32(*mux->reg_ctl, CM_CLOCKx_CTL, BUSY, enabled); 267fc984085SLuc Michel 268fc984085SLuc Michel if (!enabled) { 26972813624SLuc Michel clock_update(mux->out, 0); 270fc984085SLuc Michel return; 271fc984085SLuc Michel } 272fc984085SLuc Michel 273fc984085SLuc Michel freq = clock_get_hz(mux->srcs[src]); 274fc984085SLuc Michel 275fc984085SLuc Michel if (mux->int_bits == 0 && mux->frac_bits == 0) { 276fc984085SLuc Michel clock_update_hz(mux->out, freq); 277fc984085SLuc Michel return; 278fc984085SLuc Michel } 279fc984085SLuc Michel 280fc984085SLuc Michel /* 281fc984085SLuc Michel * The divider has an integer and a fractional part. The size of each part 282fc984085SLuc Michel * varies with the muxes (int_bits and frac_bits). Both parts are 283fc984085SLuc Michel * concatenated, with the integer part always starting at bit 12. 284fc984085SLuc Michel * 285fc984085SLuc Michel * 31 12 11 0 286fc984085SLuc Michel * ------------------------------ 287fc984085SLuc Michel * CM_DIV | | int | frac | | 288fc984085SLuc Michel * ------------------------------ 289fc984085SLuc Michel * <-----> <------> 290fc984085SLuc Michel * int_bits frac_bits 291fc984085SLuc Michel */ 292fc984085SLuc Michel div = extract32(*mux->reg_div, 293fc984085SLuc Michel R_CM_CLOCKx_DIV_FRAC_LENGTH - mux->frac_bits, 294fc984085SLuc Michel mux->int_bits + mux->frac_bits); 295fc984085SLuc Michel 296fc984085SLuc Michel if (!div) { 297fc984085SLuc Michel clock_update(mux->out, 0); 298fc984085SLuc Michel return; 299fc984085SLuc Michel } 300fc984085SLuc Michel 301fc984085SLuc Michel freq = muldiv64(freq, 1 << mux->frac_bits, div); 302fc984085SLuc Michel 303fc984085SLuc Michel clock_update_hz(mux->out, freq); 30472813624SLuc Michel } 30572813624SLuc Michel 30672813624SLuc Michel static void clock_mux_src_update(void *opaque) 30772813624SLuc Michel { 30872813624SLuc Michel CprmanClockMuxState **backref = opaque; 30972813624SLuc Michel CprmanClockMuxState *s = *backref; 310fc984085SLuc Michel CprmanClockMuxSource src = backref - s->backref; 311fc984085SLuc Michel 312fc984085SLuc Michel if (FIELD_EX32(*s->reg_ctl, CM_CLOCKx_CTL, SRC) != src) { 313fc984085SLuc Michel return; 314fc984085SLuc Michel } 31572813624SLuc Michel 31672813624SLuc Michel clock_mux_update(s); 31772813624SLuc Michel } 31872813624SLuc Michel 319*83ad4695SLuc Michel static void clock_mux_reset(DeviceState *dev) 320*83ad4695SLuc Michel { 321*83ad4695SLuc Michel CprmanClockMuxState *clock = CPRMAN_CLOCK_MUX(dev); 322*83ad4695SLuc Michel const ClockMuxResetInfo *info = &CLOCK_MUX_RESET_INFO[clock->id]; 323*83ad4695SLuc Michel 324*83ad4695SLuc Michel *clock->reg_ctl = info->cm_ctl; 325*83ad4695SLuc Michel *clock->reg_div = info->cm_div; 326*83ad4695SLuc Michel } 327*83ad4695SLuc Michel 32872813624SLuc Michel static void clock_mux_init(Object *obj) 32972813624SLuc Michel { 33072813624SLuc Michel CprmanClockMuxState *s = CPRMAN_CLOCK_MUX(obj); 33172813624SLuc Michel size_t i; 33272813624SLuc Michel 33372813624SLuc Michel for (i = 0; i < CPRMAN_NUM_CLOCK_MUX_SRC; i++) { 33472813624SLuc Michel char *name = g_strdup_printf("srcs[%zu]", i); 33572813624SLuc Michel s->backref[i] = s; 33672813624SLuc Michel s->srcs[i] = qdev_init_clock_in(DEVICE(s), name, 33772813624SLuc Michel clock_mux_src_update, 33872813624SLuc Michel &s->backref[i]); 33972813624SLuc Michel g_free(name); 34072813624SLuc Michel } 34172813624SLuc Michel 34272813624SLuc Michel s->out = qdev_init_clock_out(DEVICE(s), "out"); 34372813624SLuc Michel } 34472813624SLuc Michel 34572813624SLuc Michel static const VMStateDescription clock_mux_vmstate = { 34672813624SLuc Michel .name = TYPE_CPRMAN_CLOCK_MUX, 34772813624SLuc Michel .version_id = 1, 34872813624SLuc Michel .minimum_version_id = 1, 34972813624SLuc Michel .fields = (VMStateField[]) { 35072813624SLuc Michel VMSTATE_ARRAY_CLOCK(srcs, CprmanClockMuxState, 35172813624SLuc Michel CPRMAN_NUM_CLOCK_MUX_SRC), 35272813624SLuc Michel VMSTATE_END_OF_LIST() 35372813624SLuc Michel } 35472813624SLuc Michel }; 35572813624SLuc Michel 35672813624SLuc Michel static void clock_mux_class_init(ObjectClass *klass, void *data) 35772813624SLuc Michel { 35872813624SLuc Michel DeviceClass *dc = DEVICE_CLASS(klass); 35972813624SLuc Michel 360*83ad4695SLuc Michel dc->reset = clock_mux_reset; 36172813624SLuc Michel dc->vmsd = &clock_mux_vmstate; 36272813624SLuc Michel } 36372813624SLuc Michel 36472813624SLuc Michel static const TypeInfo cprman_clock_mux_info = { 36572813624SLuc Michel .name = TYPE_CPRMAN_CLOCK_MUX, 36672813624SLuc Michel .parent = TYPE_DEVICE, 36772813624SLuc Michel .instance_size = sizeof(CprmanClockMuxState), 36872813624SLuc Michel .class_init = clock_mux_class_init, 36972813624SLuc Michel .instance_init = clock_mux_init, 37072813624SLuc Michel }; 37172813624SLuc Michel 37272813624SLuc Michel 373502960caSLuc Michel /* DSI0HSCK mux */ 374502960caSLuc Michel 375502960caSLuc Michel static void dsi0hsck_mux_update(CprmanDsi0HsckMuxState *s) 376502960caSLuc Michel { 377502960caSLuc Michel bool src_is_plld = FIELD_EX32(*s->reg_cm, CM_DSI0HSCK, SELPLLD); 378502960caSLuc Michel Clock *src = src_is_plld ? s->plld_in : s->plla_in; 379502960caSLuc Michel 380502960caSLuc Michel clock_update(s->out, clock_get(src)); 381502960caSLuc Michel } 382502960caSLuc Michel 383502960caSLuc Michel static void dsi0hsck_mux_in_update(void *opaque) 384502960caSLuc Michel { 385502960caSLuc Michel dsi0hsck_mux_update(CPRMAN_DSI0HSCK_MUX(opaque)); 386502960caSLuc Michel } 387502960caSLuc Michel 388502960caSLuc Michel static void dsi0hsck_mux_init(Object *obj) 389502960caSLuc Michel { 390502960caSLuc Michel CprmanDsi0HsckMuxState *s = CPRMAN_DSI0HSCK_MUX(obj); 391502960caSLuc Michel DeviceState *dev = DEVICE(obj); 392502960caSLuc Michel 393502960caSLuc Michel s->plla_in = qdev_init_clock_in(dev, "plla-in", dsi0hsck_mux_in_update, s); 394502960caSLuc Michel s->plld_in = qdev_init_clock_in(dev, "plld-in", dsi0hsck_mux_in_update, s); 395502960caSLuc Michel s->out = qdev_init_clock_out(DEVICE(s), "out"); 396502960caSLuc Michel } 397502960caSLuc Michel 398502960caSLuc Michel static const VMStateDescription dsi0hsck_mux_vmstate = { 399502960caSLuc Michel .name = TYPE_CPRMAN_DSI0HSCK_MUX, 400502960caSLuc Michel .version_id = 1, 401502960caSLuc Michel .minimum_version_id = 1, 402502960caSLuc Michel .fields = (VMStateField[]) { 403502960caSLuc Michel VMSTATE_CLOCK(plla_in, CprmanDsi0HsckMuxState), 404502960caSLuc Michel VMSTATE_CLOCK(plld_in, CprmanDsi0HsckMuxState), 405502960caSLuc Michel VMSTATE_END_OF_LIST() 406502960caSLuc Michel } 407502960caSLuc Michel }; 408502960caSLuc Michel 409502960caSLuc Michel static void dsi0hsck_mux_class_init(ObjectClass *klass, void *data) 410502960caSLuc Michel { 411502960caSLuc Michel DeviceClass *dc = DEVICE_CLASS(klass); 412502960caSLuc Michel 413502960caSLuc Michel dc->vmsd = &dsi0hsck_mux_vmstate; 414502960caSLuc Michel } 415502960caSLuc Michel 416502960caSLuc Michel static const TypeInfo cprman_dsi0hsck_mux_info = { 417502960caSLuc Michel .name = TYPE_CPRMAN_DSI0HSCK_MUX, 418502960caSLuc Michel .parent = TYPE_DEVICE, 419502960caSLuc Michel .instance_size = sizeof(CprmanDsi0HsckMuxState), 420502960caSLuc Michel .class_init = dsi0hsck_mux_class_init, 421502960caSLuc Michel .instance_init = dsi0hsck_mux_init, 422502960caSLuc Michel }; 423502960caSLuc Michel 424502960caSLuc Michel 425fc14176bSLuc Michel /* CPRMAN "top level" model */ 426fc14176bSLuc Michel 4276d2b874cSLuc Michel static uint32_t get_cm_lock(const BCM2835CprmanState *s) 4286d2b874cSLuc Michel { 4296d2b874cSLuc Michel static const int CM_LOCK_MAPPING[CPRMAN_NUM_PLL] = { 4306d2b874cSLuc Michel [CPRMAN_PLLA] = R_CM_LOCK_FLOCKA_SHIFT, 4316d2b874cSLuc Michel [CPRMAN_PLLC] = R_CM_LOCK_FLOCKC_SHIFT, 4326d2b874cSLuc Michel [CPRMAN_PLLD] = R_CM_LOCK_FLOCKD_SHIFT, 4336d2b874cSLuc Michel [CPRMAN_PLLH] = R_CM_LOCK_FLOCKH_SHIFT, 4346d2b874cSLuc Michel [CPRMAN_PLLB] = R_CM_LOCK_FLOCKB_SHIFT, 4356d2b874cSLuc Michel }; 4366d2b874cSLuc Michel 4376d2b874cSLuc Michel uint32_t r = 0; 4386d2b874cSLuc Michel size_t i; 4396d2b874cSLuc Michel 4406d2b874cSLuc Michel for (i = 0; i < CPRMAN_NUM_PLL; i++) { 4416d2b874cSLuc Michel r |= pll_is_locked(&s->plls[i]) << CM_LOCK_MAPPING[i]; 4426d2b874cSLuc Michel } 4436d2b874cSLuc Michel 4446d2b874cSLuc Michel return r; 4456d2b874cSLuc Michel } 4466d2b874cSLuc Michel 447fc14176bSLuc Michel static uint64_t cprman_read(void *opaque, hwaddr offset, 448fc14176bSLuc Michel unsigned size) 449fc14176bSLuc Michel { 450fc14176bSLuc Michel BCM2835CprmanState *s = CPRMAN(opaque); 451fc14176bSLuc Michel uint64_t r = 0; 452fc14176bSLuc Michel size_t idx = offset / sizeof(uint32_t); 453fc14176bSLuc Michel 454fc14176bSLuc Michel switch (idx) { 4556d2b874cSLuc Michel case R_CM_LOCK: 4566d2b874cSLuc Michel r = get_cm_lock(s); 4576d2b874cSLuc Michel break; 4586d2b874cSLuc Michel 459fc14176bSLuc Michel default: 460fc14176bSLuc Michel r = s->regs[idx]; 461fc14176bSLuc Michel } 462fc14176bSLuc Michel 463fc14176bSLuc Michel trace_bcm2835_cprman_read(offset, r); 464fc14176bSLuc Michel return r; 465fc14176bSLuc Michel } 466fc14176bSLuc Michel 46709d56bbcSLuc Michel static inline void update_pll_and_channels_from_cm(BCM2835CprmanState *s, 46809d56bbcSLuc Michel size_t idx) 46909d56bbcSLuc Michel { 47009d56bbcSLuc Michel size_t i; 47109d56bbcSLuc Michel 47209d56bbcSLuc Michel for (i = 0; i < CPRMAN_NUM_PLL; i++) { 47309d56bbcSLuc Michel if (PLL_INIT_INFO[i].cm_offset == idx) { 47409d56bbcSLuc Michel pll_update_all_channels(s, &s->plls[i]); 47509d56bbcSLuc Michel return; 47609d56bbcSLuc Michel } 47709d56bbcSLuc Michel } 47809d56bbcSLuc Michel } 47909d56bbcSLuc Michel 48009d56bbcSLuc Michel static inline void update_channel_from_a2w(BCM2835CprmanState *s, size_t idx) 48109d56bbcSLuc Michel { 48209d56bbcSLuc Michel size_t i; 48309d56bbcSLuc Michel 48409d56bbcSLuc Michel for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) { 48509d56bbcSLuc Michel if (PLL_CHANNEL_INIT_INFO[i].a2w_ctrl_offset == idx) { 48609d56bbcSLuc Michel pll_channel_update(&s->channels[i]); 48709d56bbcSLuc Michel return; 48809d56bbcSLuc Michel } 48909d56bbcSLuc Michel } 49009d56bbcSLuc Michel } 49109d56bbcSLuc Michel 49272813624SLuc Michel static inline void update_mux_from_cm(BCM2835CprmanState *s, size_t idx) 49372813624SLuc Michel { 49472813624SLuc Michel size_t i; 49572813624SLuc Michel 49672813624SLuc Michel for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) { 49772813624SLuc Michel if ((CLOCK_MUX_INIT_INFO[i].cm_offset == idx) || 49872813624SLuc Michel (CLOCK_MUX_INIT_INFO[i].cm_offset + 4 == idx)) { 49972813624SLuc Michel /* matches CM_CTL or CM_DIV mux register */ 50072813624SLuc Michel clock_mux_update(&s->clock_muxes[i]); 50172813624SLuc Michel return; 50272813624SLuc Michel } 50372813624SLuc Michel } 50472813624SLuc Michel } 50572813624SLuc Michel 50609d56bbcSLuc Michel #define CASE_PLL_A2W_REGS(pll_) \ 5071e986e25SLuc Michel case R_A2W_ ## pll_ ## _CTRL: \ 5081e986e25SLuc Michel case R_A2W_ ## pll_ ## _ANA0: \ 5091e986e25SLuc Michel case R_A2W_ ## pll_ ## _ANA1: \ 5101e986e25SLuc Michel case R_A2W_ ## pll_ ## _ANA2: \ 5111e986e25SLuc Michel case R_A2W_ ## pll_ ## _ANA3: \ 5121e986e25SLuc Michel case R_A2W_ ## pll_ ## _FRAC 5131e986e25SLuc Michel 514fc14176bSLuc Michel static void cprman_write(void *opaque, hwaddr offset, 515fc14176bSLuc Michel uint64_t value, unsigned size) 516fc14176bSLuc Michel { 517fc14176bSLuc Michel BCM2835CprmanState *s = CPRMAN(opaque); 518fc14176bSLuc Michel size_t idx = offset / sizeof(uint32_t); 519fc14176bSLuc Michel 520fc14176bSLuc Michel if (FIELD_EX32(value, CPRMAN, PASSWORD) != CPRMAN_PASSWORD) { 521fc14176bSLuc Michel trace_bcm2835_cprman_write_invalid_magic(offset, value); 522fc14176bSLuc Michel return; 523fc14176bSLuc Michel } 524fc14176bSLuc Michel 525fc14176bSLuc Michel value &= ~R_CPRMAN_PASSWORD_MASK; 526fc14176bSLuc Michel 527fc14176bSLuc Michel trace_bcm2835_cprman_write(offset, value); 528fc14176bSLuc Michel s->regs[idx] = value; 529fc14176bSLuc Michel 5301e986e25SLuc Michel switch (idx) { 53109d56bbcSLuc Michel case R_CM_PLLA ... R_CM_PLLH: 53209d56bbcSLuc Michel case R_CM_PLLB: 53309d56bbcSLuc Michel /* 53409d56bbcSLuc Michel * A given CM_PLLx register is shared by both the PLL and the channels 53509d56bbcSLuc Michel * of this PLL. 53609d56bbcSLuc Michel */ 53709d56bbcSLuc Michel update_pll_and_channels_from_cm(s, idx); 53809d56bbcSLuc Michel break; 53909d56bbcSLuc Michel 54009d56bbcSLuc Michel CASE_PLL_A2W_REGS(PLLA) : 5411e986e25SLuc Michel pll_update(&s->plls[CPRMAN_PLLA]); 5421e986e25SLuc Michel break; 5431e986e25SLuc Michel 54409d56bbcSLuc Michel CASE_PLL_A2W_REGS(PLLC) : 5451e986e25SLuc Michel pll_update(&s->plls[CPRMAN_PLLC]); 5461e986e25SLuc Michel break; 5471e986e25SLuc Michel 54809d56bbcSLuc Michel CASE_PLL_A2W_REGS(PLLD) : 5491e986e25SLuc Michel pll_update(&s->plls[CPRMAN_PLLD]); 5501e986e25SLuc Michel break; 5511e986e25SLuc Michel 55209d56bbcSLuc Michel CASE_PLL_A2W_REGS(PLLH) : 5531e986e25SLuc Michel pll_update(&s->plls[CPRMAN_PLLH]); 5541e986e25SLuc Michel break; 5551e986e25SLuc Michel 55609d56bbcSLuc Michel CASE_PLL_A2W_REGS(PLLB) : 5571e986e25SLuc Michel pll_update(&s->plls[CPRMAN_PLLB]); 5581e986e25SLuc Michel break; 55909d56bbcSLuc Michel 56009d56bbcSLuc Michel case R_A2W_PLLA_DSI0: 56109d56bbcSLuc Michel case R_A2W_PLLA_CORE: 56209d56bbcSLuc Michel case R_A2W_PLLA_PER: 56309d56bbcSLuc Michel case R_A2W_PLLA_CCP2: 56409d56bbcSLuc Michel case R_A2W_PLLC_CORE2: 56509d56bbcSLuc Michel case R_A2W_PLLC_CORE1: 56609d56bbcSLuc Michel case R_A2W_PLLC_PER: 56709d56bbcSLuc Michel case R_A2W_PLLC_CORE0: 56809d56bbcSLuc Michel case R_A2W_PLLD_DSI0: 56909d56bbcSLuc Michel case R_A2W_PLLD_CORE: 57009d56bbcSLuc Michel case R_A2W_PLLD_PER: 57109d56bbcSLuc Michel case R_A2W_PLLD_DSI1: 57209d56bbcSLuc Michel case R_A2W_PLLH_AUX: 57309d56bbcSLuc Michel case R_A2W_PLLH_RCAL: 57409d56bbcSLuc Michel case R_A2W_PLLH_PIX: 57509d56bbcSLuc Michel case R_A2W_PLLB_ARM: 57609d56bbcSLuc Michel update_channel_from_a2w(s, idx); 57709d56bbcSLuc Michel break; 57872813624SLuc Michel 57972813624SLuc Michel case R_CM_GNRICCTL ... R_CM_SMIDIV: 58072813624SLuc Michel case R_CM_TCNTCNT ... R_CM_VECDIV: 58172813624SLuc Michel case R_CM_PULSECTL ... R_CM_PULSEDIV: 58272813624SLuc Michel case R_CM_SDCCTL ... R_CM_ARMCTL: 58372813624SLuc Michel case R_CM_AVEOCTL ... R_CM_EMMCDIV: 58472813624SLuc Michel case R_CM_EMMC2CTL ... R_CM_EMMC2DIV: 58572813624SLuc Michel update_mux_from_cm(s, idx); 58672813624SLuc Michel break; 587502960caSLuc Michel 588502960caSLuc Michel case R_CM_DSI0HSCK: 589502960caSLuc Michel dsi0hsck_mux_update(&s->dsi0hsck_mux); 590502960caSLuc Michel break; 591fc14176bSLuc Michel } 5921e986e25SLuc Michel } 5931e986e25SLuc Michel 59409d56bbcSLuc Michel #undef CASE_PLL_A2W_REGS 595fc14176bSLuc Michel 596fc14176bSLuc Michel static const MemoryRegionOps cprman_ops = { 597fc14176bSLuc Michel .read = cprman_read, 598fc14176bSLuc Michel .write = cprman_write, 599fc14176bSLuc Michel .endianness = DEVICE_LITTLE_ENDIAN, 600fc14176bSLuc Michel .valid = { 601fc14176bSLuc Michel /* 602fc14176bSLuc Michel * Although this hasn't been checked against real hardware, nor the 603fc14176bSLuc Michel * information can be found in a datasheet, it seems reasonable because 604fc14176bSLuc Michel * of the "PASSWORD" magic value found in every registers. 605fc14176bSLuc Michel */ 606fc14176bSLuc Michel .min_access_size = 4, 607fc14176bSLuc Michel .max_access_size = 4, 608fc14176bSLuc Michel .unaligned = false, 609fc14176bSLuc Michel }, 610fc14176bSLuc Michel .impl = { 611fc14176bSLuc Michel .max_access_size = 4, 612fc14176bSLuc Michel }, 613fc14176bSLuc Michel }; 614fc14176bSLuc Michel 615fc14176bSLuc Michel static void cprman_reset(DeviceState *dev) 616fc14176bSLuc Michel { 617fc14176bSLuc Michel BCM2835CprmanState *s = CPRMAN(dev); 6181e986e25SLuc Michel size_t i; 619fc14176bSLuc Michel 620fc14176bSLuc Michel memset(s->regs, 0, sizeof(s->regs)); 621fc14176bSLuc Michel 6221e986e25SLuc Michel for (i = 0; i < CPRMAN_NUM_PLL; i++) { 6231e986e25SLuc Michel device_cold_reset(DEVICE(&s->plls[i])); 6241e986e25SLuc Michel } 6251e986e25SLuc Michel 62609d56bbcSLuc Michel for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) { 62709d56bbcSLuc Michel device_cold_reset(DEVICE(&s->channels[i])); 62809d56bbcSLuc Michel } 62909d56bbcSLuc Michel 630502960caSLuc Michel device_cold_reset(DEVICE(&s->dsi0hsck_mux)); 631502960caSLuc Michel 63272813624SLuc Michel for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) { 63372813624SLuc Michel device_cold_reset(DEVICE(&s->clock_muxes[i])); 63472813624SLuc Michel } 63572813624SLuc Michel 636fc14176bSLuc Michel clock_update_hz(s->xosc, s->xosc_freq); 637fc14176bSLuc Michel } 638fc14176bSLuc Michel 639fc14176bSLuc Michel static void cprman_init(Object *obj) 640fc14176bSLuc Michel { 641fc14176bSLuc Michel BCM2835CprmanState *s = CPRMAN(obj); 6421e986e25SLuc Michel size_t i; 6431e986e25SLuc Michel 6441e986e25SLuc Michel for (i = 0; i < CPRMAN_NUM_PLL; i++) { 6451e986e25SLuc Michel object_initialize_child(obj, PLL_INIT_INFO[i].name, 6461e986e25SLuc Michel &s->plls[i], TYPE_CPRMAN_PLL); 6471e986e25SLuc Michel set_pll_init_info(s, &s->plls[i], i); 6481e986e25SLuc Michel } 649fc14176bSLuc Michel 65009d56bbcSLuc Michel for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) { 65109d56bbcSLuc Michel object_initialize_child(obj, PLL_CHANNEL_INIT_INFO[i].name, 65209d56bbcSLuc Michel &s->channels[i], 65309d56bbcSLuc Michel TYPE_CPRMAN_PLL_CHANNEL); 65409d56bbcSLuc Michel set_pll_channel_init_info(s, &s->channels[i], i); 65509d56bbcSLuc Michel } 65609d56bbcSLuc Michel 657502960caSLuc Michel object_initialize_child(obj, "dsi0hsck-mux", 658502960caSLuc Michel &s->dsi0hsck_mux, TYPE_CPRMAN_DSI0HSCK_MUX); 659502960caSLuc Michel s->dsi0hsck_mux.reg_cm = &s->regs[R_CM_DSI0HSCK]; 660502960caSLuc Michel 66172813624SLuc Michel for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) { 66272813624SLuc Michel char *alias; 66372813624SLuc Michel 66472813624SLuc Michel object_initialize_child(obj, CLOCK_MUX_INIT_INFO[i].name, 66572813624SLuc Michel &s->clock_muxes[i], 66672813624SLuc Michel TYPE_CPRMAN_CLOCK_MUX); 66772813624SLuc Michel set_clock_mux_init_info(s, &s->clock_muxes[i], i); 66872813624SLuc Michel 66972813624SLuc Michel /* Expose muxes output as CPRMAN outputs */ 67072813624SLuc Michel alias = g_strdup_printf("%s-out", CLOCK_MUX_INIT_INFO[i].name); 67172813624SLuc Michel qdev_alias_clock(DEVICE(&s->clock_muxes[i]), "out", DEVICE(obj), alias); 67272813624SLuc Michel g_free(alias); 67372813624SLuc Michel } 67472813624SLuc Michel 675fc14176bSLuc Michel s->xosc = clock_new(obj, "xosc"); 67672813624SLuc Michel s->gnd = clock_new(obj, "gnd"); 67772813624SLuc Michel 67872813624SLuc Michel clock_set(s->gnd, 0); 679fc14176bSLuc Michel 680fc14176bSLuc Michel memory_region_init_io(&s->iomem, obj, &cprman_ops, 681fc14176bSLuc Michel s, "bcm2835-cprman", 0x2000); 682fc14176bSLuc Michel sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem); 683fc14176bSLuc Michel } 684fc14176bSLuc Michel 68572813624SLuc Michel static void connect_mux_sources(BCM2835CprmanState *s, 68672813624SLuc Michel CprmanClockMuxState *mux, 68772813624SLuc Michel const CprmanPllChannel *clk_mapping) 68872813624SLuc Michel { 68972813624SLuc Michel size_t i; 69072813624SLuc Michel Clock *td0 = s->clock_muxes[CPRMAN_CLOCK_TD0].out; 69172813624SLuc Michel Clock *td1 = s->clock_muxes[CPRMAN_CLOCK_TD1].out; 69272813624SLuc Michel 69372813624SLuc Michel /* For sources from 0 to 3. Source 4 to 9 are mux specific */ 69472813624SLuc Michel Clock * const CLK_SRC_MAPPING[] = { 69572813624SLuc Michel [CPRMAN_CLOCK_SRC_GND] = s->gnd, 69672813624SLuc Michel [CPRMAN_CLOCK_SRC_XOSC] = s->xosc, 69772813624SLuc Michel [CPRMAN_CLOCK_SRC_TD0] = td0, 69872813624SLuc Michel [CPRMAN_CLOCK_SRC_TD1] = td1, 69972813624SLuc Michel }; 70072813624SLuc Michel 70172813624SLuc Michel for (i = 0; i < CPRMAN_NUM_CLOCK_MUX_SRC; i++) { 70272813624SLuc Michel CprmanPllChannel mapping = clk_mapping[i]; 70372813624SLuc Michel Clock *src; 70472813624SLuc Michel 70572813624SLuc Michel if (mapping == CPRMAN_CLOCK_SRC_FORCE_GROUND) { 70672813624SLuc Michel src = s->gnd; 70772813624SLuc Michel } else if (mapping == CPRMAN_CLOCK_SRC_DSI0HSCK) { 708502960caSLuc Michel src = s->dsi0hsck_mux.out; 70972813624SLuc Michel } else if (i < CPRMAN_CLOCK_SRC_PLLA) { 71072813624SLuc Michel src = CLK_SRC_MAPPING[i]; 71172813624SLuc Michel } else { 71272813624SLuc Michel src = s->channels[mapping].out; 71372813624SLuc Michel } 71472813624SLuc Michel 71572813624SLuc Michel clock_set_source(mux->srcs[i], src); 71672813624SLuc Michel } 71772813624SLuc Michel } 71872813624SLuc Michel 7191e986e25SLuc Michel static void cprman_realize(DeviceState *dev, Error **errp) 7201e986e25SLuc Michel { 7211e986e25SLuc Michel BCM2835CprmanState *s = CPRMAN(dev); 7221e986e25SLuc Michel size_t i; 7231e986e25SLuc Michel 7241e986e25SLuc Michel for (i = 0; i < CPRMAN_NUM_PLL; i++) { 7251e986e25SLuc Michel CprmanPllState *pll = &s->plls[i]; 7261e986e25SLuc Michel 7271e986e25SLuc Michel clock_set_source(pll->xosc_in, s->xosc); 7281e986e25SLuc Michel 7291e986e25SLuc Michel if (!qdev_realize(DEVICE(pll), NULL, errp)) { 7301e986e25SLuc Michel return; 7311e986e25SLuc Michel } 7321e986e25SLuc Michel } 73309d56bbcSLuc Michel 73409d56bbcSLuc Michel for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) { 73509d56bbcSLuc Michel CprmanPllChannelState *channel = &s->channels[i]; 73609d56bbcSLuc Michel CprmanPll parent = PLL_CHANNEL_INIT_INFO[i].parent; 73709d56bbcSLuc Michel Clock *parent_clk = s->plls[parent].out; 73809d56bbcSLuc Michel 73909d56bbcSLuc Michel clock_set_source(channel->pll_in, parent_clk); 74009d56bbcSLuc Michel 74109d56bbcSLuc Michel if (!qdev_realize(DEVICE(channel), NULL, errp)) { 74209d56bbcSLuc Michel return; 74309d56bbcSLuc Michel } 74409d56bbcSLuc Michel } 74572813624SLuc Michel 746502960caSLuc Michel clock_set_source(s->dsi0hsck_mux.plla_in, 747502960caSLuc Michel s->channels[CPRMAN_PLLA_CHANNEL_DSI0].out); 748502960caSLuc Michel clock_set_source(s->dsi0hsck_mux.plld_in, 749502960caSLuc Michel s->channels[CPRMAN_PLLD_CHANNEL_DSI0].out); 750502960caSLuc Michel 751502960caSLuc Michel if (!qdev_realize(DEVICE(&s->dsi0hsck_mux), NULL, errp)) { 752502960caSLuc Michel return; 753502960caSLuc Michel } 754502960caSLuc Michel 75572813624SLuc Michel for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) { 75672813624SLuc Michel CprmanClockMuxState *clock_mux = &s->clock_muxes[i]; 75772813624SLuc Michel 75872813624SLuc Michel connect_mux_sources(s, clock_mux, CLOCK_MUX_INIT_INFO[i].src_mapping); 75972813624SLuc Michel 76072813624SLuc Michel if (!qdev_realize(DEVICE(clock_mux), NULL, errp)) { 76172813624SLuc Michel return; 76272813624SLuc Michel } 76372813624SLuc Michel } 7641e986e25SLuc Michel } 7651e986e25SLuc Michel 766fc14176bSLuc Michel static const VMStateDescription cprman_vmstate = { 767fc14176bSLuc Michel .name = TYPE_BCM2835_CPRMAN, 768fc14176bSLuc Michel .version_id = 1, 769fc14176bSLuc Michel .minimum_version_id = 1, 770fc14176bSLuc Michel .fields = (VMStateField[]) { 771fc14176bSLuc Michel VMSTATE_UINT32_ARRAY(regs, BCM2835CprmanState, CPRMAN_NUM_REGS), 772fc14176bSLuc Michel VMSTATE_END_OF_LIST() 773fc14176bSLuc Michel } 774fc14176bSLuc Michel }; 775fc14176bSLuc Michel 776fc14176bSLuc Michel static Property cprman_properties[] = { 777fc14176bSLuc Michel DEFINE_PROP_UINT32("xosc-freq-hz", BCM2835CprmanState, xosc_freq, 19200000), 778fc14176bSLuc Michel DEFINE_PROP_END_OF_LIST() 779fc14176bSLuc Michel }; 780fc14176bSLuc Michel 781fc14176bSLuc Michel static void cprman_class_init(ObjectClass *klass, void *data) 782fc14176bSLuc Michel { 783fc14176bSLuc Michel DeviceClass *dc = DEVICE_CLASS(klass); 784fc14176bSLuc Michel 7851e986e25SLuc Michel dc->realize = cprman_realize; 786fc14176bSLuc Michel dc->reset = cprman_reset; 787fc14176bSLuc Michel dc->vmsd = &cprman_vmstate; 788fc14176bSLuc Michel device_class_set_props(dc, cprman_properties); 789fc14176bSLuc Michel } 790fc14176bSLuc Michel 791fc14176bSLuc Michel static const TypeInfo cprman_info = { 792fc14176bSLuc Michel .name = TYPE_BCM2835_CPRMAN, 793fc14176bSLuc Michel .parent = TYPE_SYS_BUS_DEVICE, 794fc14176bSLuc Michel .instance_size = sizeof(BCM2835CprmanState), 795fc14176bSLuc Michel .class_init = cprman_class_init, 796fc14176bSLuc Michel .instance_init = cprman_init, 797fc14176bSLuc Michel }; 798fc14176bSLuc Michel 799fc14176bSLuc Michel static void cprman_register_types(void) 800fc14176bSLuc Michel { 801fc14176bSLuc Michel type_register_static(&cprman_info); 8021e986e25SLuc Michel type_register_static(&cprman_pll_info); 80309d56bbcSLuc Michel type_register_static(&cprman_pll_channel_info); 80472813624SLuc Michel type_register_static(&cprman_clock_mux_info); 805502960caSLuc Michel type_register_static(&cprman_dsi0hsck_mux_info); 806fc14176bSLuc Michel } 807fc14176bSLuc Michel 808fc14176bSLuc Michel type_init(cprman_register_types); 809