IB/mlx5: Verify DEVX general object type correctly
[sfrench/cifs-2.6.git] / drivers / clk / clk.c
index 8244ef2ba977e82d2dcd9f6875406aa95fc90895..96053a96fe2fc4878250aabf92601de729838cd3 100644 (file)
@@ -396,16 +396,19 @@ bool clk_hw_is_prepared(const struct clk_hw *hw)
 {
        return clk_core_is_prepared(hw->core);
 }
+EXPORT_SYMBOL_GPL(clk_hw_is_prepared);
 
 bool clk_hw_rate_is_protected(const struct clk_hw *hw)
 {
        return clk_core_rate_is_protected(hw->core);
 }
+EXPORT_SYMBOL_GPL(clk_hw_rate_is_protected);
 
 bool clk_hw_is_enabled(const struct clk_hw *hw)
 {
        return clk_core_is_enabled(hw->core);
 }
+EXPORT_SYMBOL_GPL(clk_hw_is_enabled);
 
 bool __clk_is_enabled(struct clk *clk)
 {
@@ -4068,8 +4071,15 @@ void devm_of_clk_del_provider(struct device *dev)
 }
 EXPORT_SYMBOL(devm_of_clk_del_provider);
 
-int of_parse_clkspec(const struct device_node *np, int index, const char *name,
-                    struct of_phandle_args *out_args)
+/*
+ * Beware the return values when np is valid, but no clock provider is found.
+ * If name == NULL, the function returns -ENOENT.
+ * If name != NULL, the function returns -EINVAL. This is because
+ * of_parse_phandle_with_args() is called even if of_property_match_string()
+ * returns an error.
+ */
+static int of_parse_clkspec(const struct device_node *np, int index,
+                           const char *name, struct of_phandle_args *out_args)
 {
        int ret = -ENOENT;
 
@@ -4119,7 +4129,8 @@ __of_clk_get_hw_from_provider(struct of_clk_provider *provider,
        return __clk_get_hw(clk);
 }
 
-struct clk_hw *of_clk_get_hw_from_clkspec(struct of_phandle_args *clkspec)
+static struct clk_hw *
+of_clk_get_hw_from_clkspec(struct of_phandle_args *clkspec)
 {
        struct of_clk_provider *provider;
        struct clk_hw *hw = ERR_PTR(-EPROBE_DEFER);
@@ -4156,6 +4167,56 @@ struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec)
 }
 EXPORT_SYMBOL_GPL(of_clk_get_from_provider);
 
+struct clk_hw *of_clk_get_hw(struct device_node *np, int index,
+                            const char *con_id)
+{
+       int ret;
+       struct clk_hw *hw;
+       struct of_phandle_args clkspec;
+
+       ret = of_parse_clkspec(np, index, con_id, &clkspec);
+       if (ret)
+               return ERR_PTR(ret);
+
+       hw = of_clk_get_hw_from_clkspec(&clkspec);
+       of_node_put(clkspec.np);
+
+       return hw;
+}
+
+static struct clk *__of_clk_get(struct device_node *np,
+                               int index, const char *dev_id,
+                               const char *con_id)
+{
+       struct clk_hw *hw = of_clk_get_hw(np, index, con_id);
+
+       return clk_hw_create_clk(NULL, hw, dev_id, con_id);
+}
+
+struct clk *of_clk_get(struct device_node *np, int index)
+{
+       return __of_clk_get(np, index, np->full_name, NULL);
+}
+EXPORT_SYMBOL(of_clk_get);
+
+/**
+ * of_clk_get_by_name() - Parse and lookup a clock referenced by a device node
+ * @np: pointer to clock consumer node
+ * @name: name of consumer's clock input, or NULL for the first clock reference
+ *
+ * This function parses the clocks and clock-names properties,
+ * and uses them to look up the struct clk from the registered list of clock
+ * providers.
+ */
+struct clk *of_clk_get_by_name(struct device_node *np, const char *name)
+{
+       if (!np)
+               return ERR_PTR(-ENOENT);
+
+       return __of_clk_get(np, 0, np->full_name, name);
+}
+EXPORT_SYMBOL(of_clk_get_by_name);
+
 /**
  * of_clk_get_parent_count() - Count the number of clocks a device node has
  * @np: device node to count