/* CLKIN within range of PLL input, feed directly to PLL. */ if (parent_rate <= 50000000) {
ret = regmap_set_bits(vc5->regmap, VC5_VCO_CTRL_AND_PREDIV,
VC5_VCO_CTRL_AND_PREDIV_BYPASS_PREDIV); if (ret) return ret;
/* Avoid division by zero if the output is not configured. */ if (div_int == 0 && div_frc == 0) return 0;
/* The PLL divider has 12 integer bits and 30 fractional bits */ return div64_u64((u64)f_in << 24ULL, ((u64)div_int << 24ULL) + div_frc);
}
staticlong vc5_fod_round_rate(struct clk_hw *hw, unsignedlong rate, unsignedlong *parent_rate)
{ struct vc5_hw_data *hwdata = container_of(hw, struct vc5_hw_data, hw); /* VCO frequency is divided by two before entering FOD */
u32 f_in = *parent_rate / 2;
u32 div_int;
u64 div_frc;
/* Determine integer part, which is 12 bit wide */
div_int = f_in / rate; /* * WARNING: The clock chip does not output signal if the integer part * of the divider is 0xfff and fractional part is non-zero. * Clamp the divider at 0xffe to keep the code simple.
*/ if (div_int > 0xffe) {
div_int = 0xffe;
rate = f_in / div_int;
}
/* Determine best fractional part, which is 30 bit wide */
div_frc = f_in % rate;
div_frc <<= 24;
do_div(div_frc, rate);
ret = regmap_bulk_write(vc5->regmap, VC5_OUT_DIV_FRAC(hwdata->num, 0),
data, 14); if (ret) return ret;
/* * Toggle magic bit in undocumented register for unknown reason. * This is what the IDT timing commander tool does and the chip * datasheet somewhat implies this is needed, but the register * and the bit is not documented.
*/
ret = regmap_clear_bits(vc5->regmap, VC5_GLOBAL_REGISTER,
VC5_GLOBAL_REGISTER_GLOBAL_RESET); if (ret) return ret;
/* * When enabling a FOD, all currently enabled FODs are briefly * stopped in order to synchronize all of them. This causes a clock * disruption to any unrelated chips that might be already using * other clock outputs. Bypass the sync feature to avoid the issue, * which is possible on the VersaClock 6E family via reserved * registers.
*/ if (vc5->chip_info->flags & VC5_HAS_BYPASS_SYNC_BIT) {
ret = regmap_set_bits(vc5->regmap,
VC5_RESERVED_X0(hwdata->num),
VC5_RESERVED_X0_BYPASS_SYNC); if (ret) return ret;
}
/* * If the input mux is disabled, enable it first and * select source from matching FOD.
*/
ret = regmap_read(vc5->regmap, VC5_OUT_DIV_CONTROL(hwdata->num), &src); if (ret) return ret;
if ((src & mask) == 0) {
src = VC5_OUT_DIV_CONTROL_RESET | VC5_OUT_DIV_CONTROL_EN_FOD;
ret = regmap_update_bits(vc5->regmap,
VC5_OUT_DIV_CONTROL(hwdata->num),
mask | VC5_OUT_DIV_CONTROL_RESET, src); if (ret) return ret;
}
/* Enable the clock buffer */
ret = regmap_set_bits(vc5->regmap, VC5_CLK_OUTPUT_CFG(hwdata->num, 1),
VC5_CLK_OUTPUT_CFG1_EN_CLKBUF); if (ret) return ret;
if (hwdata->clk_output_cfg0_mask) {
dev_dbg(&vc5->client->dev, "Update output %d mask 0x%0X val 0x%0X\n",
hwdata->num, hwdata->clk_output_cfg0_mask,
hwdata->clk_output_cfg0);
ret = regmap_update_bits(vc5->regmap,
VC5_CLK_OUTPUT_CFG(hwdata->num, 0),
hwdata->clk_output_cfg0_mask,
hwdata->clk_output_cfg0); if (ret) return ret;
}
if (!of_property_read_u32(np_output, "idt,mode", &value)) {
clk_out->clk_output_cfg0_mask |= VC5_CLK_OUTPUT_CFG0_CFG_MASK; switch (value) { case VC5_CLK_OUTPUT_CFG0_CFG_LVPECL: case VC5_CLK_OUTPUT_CFG0_CFG_CMOS: case VC5_CLK_OUTPUT_CFG0_CFG_HCSL33: case VC5_CLK_OUTPUT_CFG0_CFG_LVDS: case VC5_CLK_OUTPUT_CFG0_CFG_CMOS2: case VC5_CLK_OUTPUT_CFG0_CFG_CMOSD: case VC5_CLK_OUTPUT_CFG0_CFG_HCSL25:
clk_out->clk_output_cfg0 |=
value << VC5_CLK_OUTPUT_CFG0_CFG_SHIFT; break; default: return -EINVAL;
}
} return 0;
}
if (!of_property_read_u32(np_output, "idt,voltage-microvolt",
&value)) {
clk_out->clk_output_cfg0_mask |= VC5_CLK_OUTPUT_CFG0_PWR_MASK; switch (value) { case 1800000:
clk_out->clk_output_cfg0 |= VC5_CLK_OUTPUT_CFG0_PWR_18; break; case 2500000:
clk_out->clk_output_cfg0 |= VC5_CLK_OUTPUT_CFG0_PWR_25; break; case 3300000:
clk_out->clk_output_cfg0 |= VC5_CLK_OUTPUT_CFG0_PWR_33; break; default: return -EINVAL;
}
} return 0;
}
staticint vc5_map_cap_value(u32 femtofarads)
{ int mapped_value;
/* * The datasheet explicitly states 9000 - 25000 with 0.5pF * steps, but the Programmer's guide shows the steps are 0.430pF. * After getting feedback from Renesas, the .5pF steps were the * goal, but 430nF was the actual values. * Because of this, the actual range goes to 22760 instead of 25000
*/ if (femtofarads < 9000 || femtofarads > 22760) return -EINVAL;
/* * The Programmer's guide shows XTAL[5:0] but in reality, * XTAL[0] and XTAL[1] are both LSB which makes the math * strange. With clarfication from Renesas, setting the * values should be simpler by ignoring XTAL[0]
*/
mapped_value = DIV_ROUND_CLOSEST(femtofarads - 9000, 430);
/* * Since the calculation ignores XTAL[0], there is one * special case where mapped_value = 32. In reality, this means * the real mapped value should be 111111b. In other cases, * the mapped_value needs to be shifted 1 to the left.
*/ if (mapped_value > 31)
mapped_value = 0x3f; else
mapped_value <<= 1;
return mapped_value;
} staticint vc5_update_cap_load(struct device_node *node, struct vc5_driver_data *vc5)
{
u32 value; int mapped_value; int ret;
if (of_property_read_u32(node, "idt,xtal-load-femtofarads", &value)) return 0;
mapped_value = vc5_map_cap_value(value); if (mapped_value < 0) return mapped_value;
/* * The mapped_value is really the high 6 bits of * VC5_XTAL_X1_LOAD_CAP and VC5_XTAL_X2_LOAD_CAP, so * shift the value 2 places.
*/
ret = regmap_update_bits(vc5->regmap, VC5_XTAL_X1_LOAD_CAP, ~0x03,
mapped_value << 2); if (ret) return ret;
if (!IS_ERR(vc5->pin_clkin)) {
vc5->clk_mux_ins |= VC5_MUX_IN_CLKIN;
parent_names[init.num_parents++] =
__clk_get_name(vc5->pin_clkin);
}
if (!init.num_parents) return dev_err_probe(&client->dev, -EINVAL, "no input clock specified!\n");
/* Configure Optional Loading Capacitance for external XTAL */ if (!(vc5->chip_info->flags & VC5_HAS_INTERNAL_XTAL)) {
ret = vc5_update_cap_load(client->dev.of_node, vc5); if (ret) goto err_clk_register;
}
init.name = kasprintf(GFP_KERNEL, "%pOFn.mux", client->dev.of_node); if (!init.name) {
ret = -ENOMEM; goto err_clk;
}
init.ops = &vc5_mux_ops;
init.flags = 0;
init.parent_names = parent_names;
vc5->clk_mux.init = &init;
ret = devm_clk_hw_register(&client->dev, &vc5->clk_mux); if (ret) goto err_clk_register;
kfree(init.name); /* clock framework made a copy of the name */
if (vc5->chip_info->flags & VC5_HAS_PFD_FREQ_DBL) { /* Register frequency doubler */
memset(&init, 0, sizeof(init));
init.name = kasprintf(GFP_KERNEL, "%pOFn.dbl",
client->dev.of_node); if (!init.name) {
ret = -ENOMEM; goto err_clk;
}
init.ops = &vc5_dbl_ops;
init.flags = CLK_SET_RATE_PARENT;
init.parent_names = parent_names;
parent_names[0] = clk_hw_get_name(&vc5->clk_mux);
init.num_parents = 1;
vc5->clk_mul.init = &init;
ret = devm_clk_hw_register(&client->dev, &vc5->clk_mul); if (ret) goto err_clk_register;
kfree(init.name); /* clock framework made a copy of the name */
}
/* Register PFD */
memset(&init, 0, sizeof(init));
init.name = kasprintf(GFP_KERNEL, "%pOFn.pfd", client->dev.of_node); if (!init.name) {
ret = -ENOMEM; goto err_clk;
}
init.ops = &vc5_pfd_ops;
init.flags = CLK_SET_RATE_PARENT;
init.parent_names = parent_names; if (vc5->chip_info->flags & VC5_HAS_PFD_FREQ_DBL)
parent_names[0] = clk_hw_get_name(&vc5->clk_mul); else
parent_names[0] = clk_hw_get_name(&vc5->clk_mux);
init.num_parents = 1;
vc5->clk_pfd.init = &init;
ret = devm_clk_hw_register(&client->dev, &vc5->clk_pfd); if (ret) goto err_clk_register;
kfree(init.name); /* clock framework made a copy of the name */
/* Register PLL */
memset(&init, 0, sizeof(init));
init.name = kasprintf(GFP_KERNEL, "%pOFn.pll", client->dev.of_node); if (!init.name) {
ret = -ENOMEM; goto err_clk;
}
init.ops = &vc5_pll_ops;
init.flags = CLK_SET_RATE_PARENT;
init.parent_names = parent_names;
parent_names[0] = clk_hw_get_name(&vc5->clk_pfd);
init.num_parents = 1;
vc5->clk_pll.num = 0;
vc5->clk_pll.vc5 = vc5;
vc5->clk_pll.hw.init = &init;
ret = devm_clk_hw_register(&client->dev, &vc5->clk_pll.hw); if (ret) goto err_clk_register;
kfree(init.name); /* clock framework made a copy of the name */
/* Register FODs */ for (n = 0; n < vc5->chip_info->clk_fod_cnt; n++) {
idx = vc5_map_index_to_output(vc5->chip_info->model, n);
memset(&init, 0, sizeof(init));
init.name = kasprintf(GFP_KERNEL, "%pOFn.fod%d",
client->dev.of_node, idx); if (!init.name) {
ret = -ENOMEM; goto err_clk;
}
init.ops = &vc5_fod_ops;
init.flags = CLK_SET_RATE_PARENT;
init.parent_names = parent_names;
parent_names[0] = clk_hw_get_name(&vc5->clk_pll.hw);
init.num_parents = 1;
vc5->clk_fod[n].num = idx;
vc5->clk_fod[n].vc5 = vc5;
vc5->clk_fod[n].hw.init = &init;
ret = devm_clk_hw_register(&client->dev, &vc5->clk_fod[n].hw); if (ret) goto err_clk_register;
kfree(init.name); /* clock framework made a copy of the name */
}
/* Register MUX-connected OUT0_I2C_SELB output */
memset(&init, 0, sizeof(init));
init.name = kasprintf(GFP_KERNEL, "%pOFn.out0_sel_i2cb",
client->dev.of_node); if (!init.name) {
ret = -ENOMEM; goto err_clk;
}
init.ops = &vc5_clk_out_ops;
init.flags = CLK_SET_RATE_PARENT;
init.parent_names = parent_names;
parent_names[0] = clk_hw_get_name(&vc5->clk_mux);
init.num_parents = 1;
vc5->clk_out[0].num = idx;
vc5->clk_out[0].vc5 = vc5;
vc5->clk_out[0].hw.init = &init;
ret = devm_clk_hw_register(&client->dev, &vc5->clk_out[0].hw); if (ret) goto err_clk_register;
kfree(init.name); /* clock framework made a copy of the name */
/* Register FOD-connected OUTx outputs */ for (n = 1; n < vc5->chip_info->clk_out_cnt; n++) {
idx = vc5_map_index_to_output(vc5->chip_info->model, n - 1);
parent_names[0] = clk_hw_get_name(&vc5->clk_fod[idx].hw); if (n == 1)
parent_names[1] = clk_hw_get_name(&vc5->clk_mux); else
parent_names[1] =
clk_hw_get_name(&vc5->clk_out[n - 1].hw);
memset(&init, 0, sizeof(init));
init.name = kasprintf(GFP_KERNEL, "%pOFn.out%d",
client->dev.of_node, idx + 1); if (!init.name) {
ret = -ENOMEM; goto err_clk;
}
init.ops = &vc5_clk_out_ops;
init.flags = CLK_SET_RATE_PARENT;
init.parent_names = parent_names;
init.num_parents = 2;
vc5->clk_out[n].num = idx;
vc5->clk_out[n].vc5 = vc5;
vc5->clk_out[n].hw.init = &init;
ret = devm_clk_hw_register(&client->dev, &vc5->clk_out[n].hw); if (ret) goto err_clk_register;
kfree(init.name); /* clock framework made a copy of the name */
/* Fetch Clock Output configuration from DT (if specified) */
ret = vc5_get_output_config(client, &vc5->clk_out[n]); if (ret) goto err_clk;
}
ret = of_clk_add_hw_provider(client->dev.of_node, vc5_of_clk_get, vc5); if (ret) {
dev_err_probe(&client->dev, ret, "unable to add clk provider\n"); goto err_clk;
}
return 0;
err_clk_register:
dev_err_probe(&client->dev, ret, "unable to register %s\n", init.name);
kfree(init.name); /* clock framework made a copy of the name */
err_clk: if (vc5->chip_info->flags & VC5_HAS_INTERNAL_XTAL)
clk_unregister_fixed_rate(vc5->pin_xin); return ret;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.