Lines Matching refs:gate
358 __is_clk_gate_enabled(struct ccu_data *ccu, struct bcm_clk_gate *gate)
363 /* If there is no gate we can assume it's enabled. */
364 if (!gate_exists(gate))
367 bit_mask = 1 << gate->status_bit;
368 reg_val = __ccu_read(ccu, gate->offset);
375 is_clk_gate_enabled(struct ccu_data *ccu, struct bcm_clk_gate *gate)
381 if (!gate_exists(gate))
385 ret = __is_clk_gate_enabled(ccu, gate);
392 * Commit our desired gate state to the hardware.
396 __gate_commit(struct ccu_data *ccu, struct bcm_clk_gate *gate)
402 BUG_ON(!gate_exists(gate));
403 if (!gate_is_sw_controllable(gate))
406 reg_val = __ccu_read(ccu, gate->offset);
408 /* For a hardware/software gate, set which is in control */
409 if (gate_is_hw_controllable(gate)) {
410 mask = (u32)1 << gate->hw_sw_sel_bit;
411 if (gate_is_sw_managed(gate))
418 * If software is in control, enable or disable the gate.
420 * If a software controlled gate can't be disabled, we're
421 * required to write a 0 into the enable bit (but the gate
424 mask = (u32)1 << gate->en_bit;
425 if (gate_is_sw_managed(gate) && (enabled = gate_is_enabled(gate)) &&
426 !gate_is_no_disable(gate))
431 __ccu_write(ccu, gate->offset, reg_val);
433 /* For a hardware controlled gate, we're done */
434 if (!gate_is_sw_managed(gate))
437 /* Otherwise wait for the gate to be in desired state */
438 return __ccu_wait_bit(ccu, gate->offset, gate->status_bit, enabled);
442 * Initialize a gate. Our desired state (hardware/software select,
447 static bool gate_init(struct ccu_data *ccu, struct bcm_clk_gate *gate)
449 if (!gate_exists(gate))
451 return __gate_commit(ccu, gate);
455 * Set a gate to enabled or disabled state. Does nothing if the
456 * gate is not currently under software control, or if it is already
461 __clk_gate(struct ccu_data *ccu, struct bcm_clk_gate *gate, bool enable)
465 if (!gate_exists(gate) || !gate_is_sw_managed(gate))
468 if (!enable && gate_is_no_disable(gate)) {
469 pr_warn("%s: invalid gate disable request (ignoring)\n",
474 if (enable == gate_is_enabled(gate))
477 gate_flip_enabled(gate);
478 ret = __gate_commit(ccu, gate);
480 gate_flip_enabled(gate); /* Revert the change */
485 /* Enable or disable a gate. Returns 0 if successful, -EIO otherwise */
487 struct bcm_clk_gate *gate, bool enable)
496 if (!gate_exists(gate) || !gate_is_sw_managed(gate))
498 if (!enable && gate_is_no_disable(gate))
504 success = __clk_gate(ccu, gate, enable);
512 pr_err("%s: failed to %s gate for %s\n", __func__,
521 * If a clock gate requires a turn-off delay it will have
591 static int __div_commit(struct ccu_data *ccu, struct bcm_clk_gate *gate,
619 enabled = __is_clk_gate_enabled(ccu, gate);
620 if (!enabled && !__clk_gate(ccu, gate, true)) {
631 /* If the trigger fails we still want to disable the gate */
636 if (!enabled && !__clk_gate(ccu, gate, false))
647 static bool div_init(struct ccu_data *ccu, struct bcm_clk_gate *gate,
652 return !__div_commit(ccu, gate, div, trig);
655 static int divider_write(struct ccu_data *ccu, struct bcm_clk_gate *gate,
674 ret = __div_commit(ccu, gate, div, trig);
874 __sel_commit(struct ccu_data *ccu, struct bcm_clk_gate *gate,
906 enabled = __is_clk_gate_enabled(ccu, gate);
907 if (!enabled && !__clk_gate(ccu, gate, true))
915 /* If the trigger fails we still want to disable the gate */
920 if (!enabled && !__clk_gate(ccu, gate, false))
931 static bool sel_init(struct ccu_data *ccu, struct bcm_clk_gate *gate,
936 return !__sel_commit(ccu, gate, sel, trig);
944 static int selector_write(struct ccu_data *ccu, struct bcm_clk_gate *gate,
961 ret = __sel_commit(ccu, gate, sel, trig);
977 struct bcm_clk_gate *gate = &bcm_clk->u.peri->gate;
979 return clk_gate(bcm_clk->ccu, bcm_clk->init_data.name, gate, true);
985 struct bcm_clk_gate *gate = &bcm_clk->u.peri->gate;
987 (void)clk_gate(bcm_clk->ccu, bcm_clk->init_data.name, gate, false);
993 struct bcm_clk_gate *gate = &bcm_clk->u.peri->gate;
995 return is_clk_gate_enabled(bcm_clk->ccu, gate) ? 1 : 0;
1104 ret = selector_write(bcm_clk->ccu, &data->gate, sel, trig, index);
1168 ret = divider_write(bcm_clk->ccu, &data->gate, &data->div,
1208 if (!gate_init(ccu, &peri->gate)) {
1209 pr_err("%s: error initializing gate for %s\n", __func__, name);
1216 if (!div_init(ccu, &peri->gate, &peri->div, &peri->trig)) {
1229 if (!div_init(ccu, &peri->gate, &peri->pre_div, trig)) {
1235 if (!sel_init(ccu, &peri->gate, &peri->sel, trig)) {