Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 062bfa43 authored by Vikram Mulukutla's avatar Vikram Mulukutla
Browse files

msm: clock: Introduce device tree lookups



Add a function of_msm_clock_register that registers a
clock provider with the clock DT framework. Provide a
new CLK_LOOKUP_OF macro to link up clock lookup entries
with DT clock indices.

Change-Id: I66ab29df116341583db5f812b2dc5db3a65e15b5
Signed-off-by: default avatarVikram Mulukutla <markivx@codeaurora.org>
parent 70275397
Loading
Loading
Loading
Loading
+52 −0
Original line number Original line Diff line number Diff line
@@ -24,6 +24,7 @@
#include <linux/list.h>
#include <linux/list.h>
#include <linux/regulator/consumer.h>
#include <linux/regulator/consumer.h>
#include <linux/mutex.h>
#include <linux/mutex.h>
#include <linux/of.h>
#include <trace/events/power.h>
#include <trace/events/power.h>
#include <mach/clk-provider.h>
#include <mach/clk-provider.h>
#include "clock.h"
#include "clock.h"
@@ -784,6 +785,57 @@ int msm_clock_register(struct clk_lookup *table, size_t size)
}
}
EXPORT_SYMBOL(msm_clock_register);
EXPORT_SYMBOL(msm_clock_register);


struct of_msm_provider_data {
	struct clk_lookup *table;
	size_t size;
};

static struct clk *of_clk_src_get(struct of_phandle_args *clkspec,
				  void *data)
{
	struct of_msm_provider_data *ofdata = data;
	int n;

	for (n = 0; n < ofdata->size; n++) {
		if (clkspec->args[0] == ofdata->table[n].of_idx)
			return ofdata->table[n].clk;
	}
	return ERR_PTR(-ENOENT);
}

/**
 * of_msm_clock_register() - Register clock tables with clkdev and with the
 *			     clock DT framework
 * @table: Table of clocks
 * @size: Size of @table
 * @np: Device pointer corresponding to the clock-provider device
 *
 * Upon return, clock APIs may be used to control clocks registered using this
 * function.
 */
int of_msm_clock_register(struct device_node *np, struct clk_lookup *table,
				size_t size)
{
	int ret = 0;
	struct of_msm_provider_data *data;

	data = kzalloc(sizeof(*data), GFP_KERNEL);
	if (!data)
		return -ENOMEM;

	data->table = table;
	data->size = size;

	ret = of_clk_add_provider(np, of_clk_src_get, data);
	if (ret) {
		kfree(data);
		return -ENOMEM;
	}

	return msm_clock_register(table, size);
}
EXPORT_SYMBOL(of_msm_clock_register);

/**
/**
 * msm_clock_init() - Register and initialize a clock driver
 * msm_clock_init() - Register and initialize a clock driver
 * @data: Driver-specific clock initialization data
 * @data: Driver-specific clock initialization data
+5 −0
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@
#include <linux/list.h>
#include <linux/list.h>
#include <linux/clkdev.h>
#include <linux/clkdev.h>
#include <linux/of.h>
#include <linux/of.h>
#include <linux/device.h>
#include <linux/spinlock.h>
#include <linux/spinlock.h>
#include <linux/mutex.h>
#include <linux/mutex.h>
#include <linux/regulator/consumer.h>
#include <linux/regulator/consumer.h>
@@ -196,6 +197,8 @@ void __clk_post_reparent(struct clk *c, struct clk *old, unsigned long *flags);


/* Register clocks with the MSM clock driver */
/* Register clocks with the MSM clock driver */
int msm_clock_register(struct clk_lookup *table, size_t size);
int msm_clock_register(struct clk_lookup *table, size_t size);
int of_msm_clock_register(struct device_node *np, struct clk_lookup *table,
				size_t size);


extern struct clk dummy_clk;
extern struct clk dummy_clk;
extern struct clk_ops clk_ops_dummy;
extern struct clk_ops clk_ops_dummy;
@@ -217,6 +220,8 @@ extern struct clk_ops clk_ops_dummy;
	};
	};


#define CLK_LOOKUP(con, c, dev) { .con_id = con, .clk = &c, .dev_id = dev }
#define CLK_LOOKUP(con, c, dev) { .con_id = con, .clk = &c, .dev_id = dev }
#define CLK_LOOKUP_OF(con, _c, dev) { .con_id = con, .clk = &(&_c)->c, \
				      .dev_id = dev, .of_idx = clk_##_c }


static inline bool is_better_rate(unsigned long req, unsigned long best,
static inline bool is_better_rate(unsigned long req, unsigned long best,
				  unsigned long new)
				  unsigned long new)