Lines Matching refs:gate
350 __is_clk_gate_enabled(struct ccu_data *ccu, struct bcm_clk_gate *gate)
355 /* If there is no gate we can assume it's enabled. */
356 if (!gate_exists(gate))
359 bit_mask = 1 << gate->status_bit;
360 reg_val = __ccu_read(ccu, gate->offset);
367 is_clk_gate_enabled(struct ccu_data *ccu, struct bcm_clk_gate *gate)
373 if (!gate_exists(gate))
377 ret = __is_clk_gate_enabled(ccu, gate);
384 * Commit our desired gate state to the hardware.
388 __gate_commit(struct ccu_data *ccu, struct bcm_clk_gate *gate)
394 BUG_ON(!gate_exists(gate));
395 if (!gate_is_sw_controllable(gate))
398 reg_val = __ccu_read(ccu, gate->offset);
400 /* For a hardware/software gate, set which is in control */
401 if (gate_is_hw_controllable(gate)) {
402 mask = (u32)1 << gate->hw_sw_sel_bit;
403 if (gate_is_sw_managed(gate))
410 * If software is in control, enable or disable the gate.
412 * If a software controlled gate can't be disabled, we're
413 * required to write a 0 into the enable bit (but the gate
416 mask = (u32)1 << gate->en_bit;
417 if (gate_is_sw_managed(gate) && (enabled = gate_is_enabled(gate)) &&
418 !gate_is_no_disable(gate))
423 __ccu_write(ccu, gate->offset, reg_val);
425 /* For a hardware controlled gate, we're done */
426 if (!gate_is_sw_managed(gate))
429 /* Otherwise wait for the gate to be in desired state */
430 return __ccu_wait_bit(ccu, gate->offset, gate->status_bit, enabled);
434 * Initialize a gate. Our desired state (hardware/software select,
439 static bool gate_init(struct ccu_data *ccu, struct bcm_clk_gate *gate)
441 if (!gate_exists(gate))
443 return __gate_commit(ccu, gate);
447 * Set a gate to enabled or disabled state. Does nothing if the
448 * gate is not currently under software control, or if it is already
453 __clk_gate(struct ccu_data *ccu, struct bcm_clk_gate *gate, bool enable)
457 if (!gate_exists(gate) || !gate_is_sw_managed(gate))
460 if (!enable && gate_is_no_disable(gate)) {
461 pr_warn("%s: invalid gate disable request (ignoring)\n",
466 if (enable == gate_is_enabled(gate))
469 gate_flip_enabled(gate);
470 ret = __gate_commit(ccu, gate);
472 gate_flip_enabled(gate); /* Revert the change */
477 /* Enable or disable a gate. Returns 0 if successful, -EIO otherwise */
479 struct bcm_clk_gate *gate, bool enable)
488 if (!gate_exists(gate) || !gate_is_sw_managed(gate))
490 if (!enable && gate_is_no_disable(gate))
496 success = __clk_gate(ccu, gate, enable);
504 pr_err("%s: failed to %s gate for %s\n", __func__,
513 * If a clock gate requires a turn-off delay it will have
583 static int __div_commit(struct ccu_data *ccu, struct bcm_clk_gate *gate,
611 enabled = __is_clk_gate_enabled(ccu, gate);
612 if (!enabled && !__clk_gate(ccu, gate, true)) {
623 /* If the trigger fails we still want to disable the gate */
628 if (!enabled && !__clk_gate(ccu, gate, false))
639 static bool div_init(struct ccu_data *ccu, struct bcm_clk_gate *gate,
644 return !__div_commit(ccu, gate, div, trig);
647 static int divider_write(struct ccu_data *ccu, struct bcm_clk_gate *gate,
666 ret = __div_commit(ccu, gate, div, trig);
866 __sel_commit(struct ccu_data *ccu, struct bcm_clk_gate *gate,
898 enabled = __is_clk_gate_enabled(ccu, gate);
899 if (!enabled && !__clk_gate(ccu, gate, true))
907 /* If the trigger fails we still want to disable the gate */
912 if (!enabled && !__clk_gate(ccu, gate, false))
923 static bool sel_init(struct ccu_data *ccu, struct bcm_clk_gate *gate,
928 return !__sel_commit(ccu, gate, sel, trig);
936 static int selector_write(struct ccu_data *ccu, struct bcm_clk_gate *gate,
953 ret = __sel_commit(ccu, gate, sel, trig);
969 struct bcm_clk_gate *gate = &bcm_clk->u.peri->gate;
971 return clk_gate(bcm_clk->ccu, bcm_clk->init_data.name, gate, true);
977 struct bcm_clk_gate *gate = &bcm_clk->u.peri->gate;
979 (void)clk_gate(bcm_clk->ccu, bcm_clk->init_data.name, gate, false);
985 struct bcm_clk_gate *gate = &bcm_clk->u.peri->gate;
987 return is_clk_gate_enabled(bcm_clk->ccu, gate) ? 1 : 0;
1096 ret = selector_write(bcm_clk->ccu, &data->gate, sel, trig, index);
1160 ret = divider_write(bcm_clk->ccu, &data->gate, &data->div,
1200 if (!gate_init(ccu, &peri->gate)) {
1201 pr_err("%s: error initializing gate for %s\n", __func__, name);
1208 if (!div_init(ccu, &peri->gate, &peri->div, &peri->trig)) {
1221 if (!div_init(ccu, &peri->gate, &peri->pre_div, trig)) {
1227 if (!sel_init(ccu, &peri->gate, &peri->sel, trig)) {