// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (C) 2013 Broadcom Corporation * Copyright 2013 Linaro Limited */ #include <linux/io.h> #include <linux/of_address.h> #include "clk-kona.h" /* These are used when a selector or trigger is found to be unneeded */ #define selector_clear_exists(sel) … #define trigger_clear_exists(trig) … /* Validity checking */ static bool ccu_data_offsets_valid(struct ccu_data *ccu) { … } static bool clk_requires_trigger(struct kona_clk *bcm_clk) { … } static bool peri_clk_data_offsets_valid(struct kona_clk *bcm_clk) { … } /* A bit position must be less than the number of bits in a 32-bit register. */ static bool bit_posn_valid(u32 bit_posn, const char *field_name, const char *clock_name) { … } /* * A bitfield must be at least 1 bit wide. Both the low-order and * high-order bits must lie within a 32-bit register. We require * fields to be less than 32 bits wide, mainly because we use * shifting to produce field masks, and shifting a full word width * is not well-defined by the C standard. */ static bool bitfield_valid(u32 shift, u32 width, const char *field_name, const char *clock_name) { … } static bool ccu_policy_valid(struct ccu_policy *ccu_policy, const char *ccu_name) { … } static bool policy_valid(struct bcm_clk_policy *policy, const char *clock_name) { … } /* * All gates, if defined, have a status bit, and for hardware-only * gates, that's it. Gates that can be software controlled also * have an enable bit. And a gate that can be hardware or software * controlled will have a hardware/software select bit. */ static bool gate_valid(struct bcm_clk_gate *gate, const char *field_name, const char *clock_name) { … } static bool hyst_valid(struct bcm_clk_hyst *hyst, const char *clock_name) { … } /* * A selector bitfield must be valid. Its parent_sel array must * also be reasonable for the field. */ static bool sel_valid(struct bcm_clk_sel *sel, const char *field_name, const char *clock_name) { … } /* * A fixed divider just needs to be non-zero. A variable divider * has to have a valid divider bitfield, and if it has a fraction, * the width of the fraction must not be no more than the width of * the divider as a whole. */ static bool div_valid(struct bcm_clk_div *div, const char *field_name, const char *clock_name) { … } /* * If a clock has two dividers, the combined number of fractional * bits must be representable in a 32-bit unsigned value. This * is because we scale up a dividend using both dividers before * dividing to improve accuracy, and we need to avoid overflow. */ static bool kona_dividers_valid(struct kona_clk *bcm_clk) { … } /* A trigger just needs to represent a valid bit position */ static bool trig_valid(struct bcm_clk_trig *trig, const char *field_name, const char *clock_name) { … } /* Determine whether the set of peripheral clock registers are valid. */ static bool peri_clk_data_valid(struct kona_clk *bcm_clk) { … } static bool kona_clk_valid(struct kona_clk *bcm_clk) { … } /* * Scan an array of parent clock names to determine whether there * are any entries containing BAD_CLK_NAME. Such entries are * placeholders for non-supported clocks. Keep track of the * position of each clock name in the original array. * * Allocates an array of pointers to hold the names of all * non-null entries in the original array, and returns a pointer to * that array in *names. This will be used for registering the * clock with the common clock code. On successful return, * *count indicates how many entries are in that names array. * * If there is more than one entry in the resulting names array, * another array is allocated to record the parent selector value * for each (defined) parent clock. This is the value that * represents this parent clock in the clock's source selector * register. The position of the clock in the original parent array * defines that selector value. The number of entries in this array * is the same as the number of entries in the parent names array. * * The array of selector values is returned. If the clock has no * parents, no selector is required and a null pointer is returned. * * Returns a null pointer if the clock names array supplied was * null. (This is not an error.) * * Returns a pointer-coded error if an error occurs. */ static u32 *parent_process(const char *clocks[], u32 *count, const char ***names) { … } static int clk_sel_setup(const char **clocks, struct bcm_clk_sel *sel, struct clk_init_data *init_data) { … } static void clk_sel_teardown(struct bcm_clk_sel *sel, struct clk_init_data *init_data) { … } static void peri_clk_teardown(struct peri_clk_data *data, struct clk_init_data *init_data) { … } /* * Caller is responsible for freeing the parent_names[] and * parent_sel[] arrays in the peripheral clock's "data" structure * that can be assigned if the clock has one or more parent clocks * associated with it. */ static int peri_clk_setup(struct peri_clk_data *data, struct clk_init_data *init_data) { … } static void bcm_clk_teardown(struct kona_clk *bcm_clk) { … } static void kona_clk_teardown(struct clk_hw *hw) { … } static int kona_clk_setup(struct kona_clk *bcm_clk) { … } static void ccu_clks_teardown(struct ccu_data *ccu) { … } static void kona_ccu_teardown(struct ccu_data *ccu) { … } static bool ccu_data_valid(struct ccu_data *ccu) { … } static struct clk_hw * of_clk_kona_onecell_get(struct of_phandle_args *clkspec, void *data) { … } /* * Set up a CCU. Call the provided ccu_clks_setup callback to * initialize the array of clocks provided by the CCU. */ void __init kona_dt_ccu_setup(struct ccu_data *ccu, struct device_node *node) { … }