Commit 8cc7f533 authored by Stephen Boyd's avatar Stephen Boyd Committed by David Brown
Browse files

ARM: msm: Migrate to common clock framework



Move the existing clock code in mach-msm to the common clock
framework. We lose our capability to set the rate of and enable a
clock through debugfs. This is ok though because the debugfs
features are mainly used for testing and development of new clock
code.

To maintain compatibility with the original MSM clock code we
make a wrapper for clk_reset() that calls the struct msm_clk
specific reset function. This is necessary for the usb and sdcc
devices on MSM until a better suited API is made available.

Cc: Saravana Kannan <skannan@codeaurora.org>
Acked-by: default avatarMike Turquette <mturquette@linaro.org>
Signed-off-by: default avatarStephen Boyd <sboyd@codeaurora.org>
Signed-off-by: default avatarDavid Brown <davidb@codeaurora.org>
parent 421faca0
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -622,8 +622,8 @@ config ARCH_MSM
	bool "Qualcomm MSM"
	bool "Qualcomm MSM"
	select ARCH_REQUIRE_GPIOLIB
	select ARCH_REQUIRE_GPIOLIB
	select CLKDEV_LOOKUP
	select CLKDEV_LOOKUP
	select COMMON_CLK
	select GENERIC_CLOCKEVENTS
	select GENERIC_CLOCKEVENTS
	select HAVE_CLK
	help
	help
	  Support for Qualcomm MSM/QSD based systems.  This runs on the
	  Support for Qualcomm MSM/QSD based systems.  This runs on the
	  apps processor of the MSM/QSD and depends on a shared memory
	  apps processor of the MSM/QSD and depends on a shared memory
+0 −1
Original line number Original line Diff line number Diff line
obj-y += io.o timer.o
obj-y += io.o timer.o
obj-y += clock.o
obj-y += clock.o
obj-$(CONFIG_DEBUG_FS) += clock-debug.o


obj-$(CONFIG_MSM_VIC) += irq-vic.o
obj-$(CONFIG_MSM_VIC) += irq-vic.o
obj-$(CONFIG_MSM_IOMMU) += devices-iommu.o
obj-$(CONFIG_MSM_IOMMU) += devices-iommu.o

arch/arm/mach-msm/clock-debug.c

deleted100644 → 0
+0 −123
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2007 Google, Inc.
 * Copyright (c) 2007-2010, Code Aurora Forum. All rights reserved.
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
 * GNU General Public License for more details.
 *
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/ctype.h>
#include <linux/debugfs.h>
#include <linux/clk.h>
#include "clock.h"

static int clock_debug_rate_set(void *data, u64 val)
{
	struct clk *clock = data;
	int ret;

	ret = clk_set_rate(clock, val);
	if (ret != 0)
		printk(KERN_ERR "clk_set%s_rate failed (%d)\n",
			(clock->flags & CLK_MIN) ? "_min" : "", ret);
	return ret;
}

static int clock_debug_rate_get(void *data, u64 *val)
{
	struct clk *clock = data;
	*val = clk_get_rate(clock);
	return 0;
}

DEFINE_SIMPLE_ATTRIBUTE(clock_rate_fops, clock_debug_rate_get,
			clock_debug_rate_set, "%llu\n");

static int clock_debug_enable_set(void *data, u64 val)
{
	struct clk *clock = data;
	int rc = 0;

	if (val)
		rc = clock->ops->enable(clock->id);
	else
		clock->ops->disable(clock->id);

	return rc;
}

static int clock_debug_enable_get(void *data, u64 *val)
{
	struct clk *clock = data;

	*val = clock->ops->is_enabled(clock->id);

	return 0;
}

DEFINE_SIMPLE_ATTRIBUTE(clock_enable_fops, clock_debug_enable_get,
			clock_debug_enable_set, "%llu\n");

static int clock_debug_local_get(void *data, u64 *val)
{
	struct clk *clock = data;

	*val = clock->ops->is_local(clock->id);

	return 0;
}

DEFINE_SIMPLE_ATTRIBUTE(clock_local_fops, clock_debug_local_get,
			NULL, "%llu\n");

static struct dentry *debugfs_base;

int __init clock_debug_init(void)
{
	debugfs_base = debugfs_create_dir("clk", NULL);
	if (!debugfs_base)
		return -ENOMEM;
	return 0;
}

int __init clock_debug_add(struct clk *clock)
{
	char temp[50], *ptr;
	struct dentry *clk_dir;

	if (!debugfs_base)
		return -ENOMEM;

	strncpy(temp, clock->dbg_name, ARRAY_SIZE(temp)-1);
	for (ptr = temp; *ptr; ptr++)
		*ptr = tolower(*ptr);

	clk_dir = debugfs_create_dir(temp, debugfs_base);
	if (!clk_dir)
		return -ENOMEM;

	if (!debugfs_create_file("rate", S_IRUGO | S_IWUSR, clk_dir,
				clock, &clock_rate_fops))
		goto error;

	if (!debugfs_create_file("enable", S_IRUGO | S_IWUSR, clk_dir,
				clock, &clock_enable_fops))
		goto error;

	if (!debugfs_create_file("is_local", S_IRUGO, clk_dir, clock,
				&clock_local_fops))
		goto error;
	return 0;
error:
	debugfs_remove_recursive(clk_dir);
	return -ENOMEM;
}
+74 −44
Original line number Original line Diff line number Diff line
/*
/*
 * Copyright (C) 2007 Google, Inc.
 * Copyright (C) 2007 Google, Inc.
 * Copyright (c) 2007-2010, Code Aurora Forum. All rights reserved.
 * Copyright (c) 2007-2012, The Linux Foundation. All rights reserved.
 *
 *
 * This software is licensed under the terms of the GNU General Public
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * License version 2, as published by the Free Software Foundation, and
@@ -13,9 +13,12 @@
 *
 *
 */
 */


#include <linux/kernel.h>
#include <linux/err.h>
#include <linux/err.h>
#include <linux/platform_device.h>
#include <linux/platform_device.h>
#include <linux/module.h>
#include <linux/module.h>
#include <linux/clk-provider.h>
#include <linux/clkdev.h>


#include <mach/clk.h>
#include <mach/clk.h>


@@ -23,11 +26,20 @@
#include "clock.h"
#include "clock.h"
#include "clock-pcom.h"
#include "clock-pcom.h"


/*
struct clk_pcom {
 * glue for the proc_comm interface
	unsigned id;
 */
	unsigned long flags;
static int pc_clk_enable(unsigned id)
	struct msm_clk msm_clk;
};

static inline struct clk_pcom *to_clk_pcom(struct clk_hw *hw)
{
{
	return container_of(to_msm_clk(hw), struct clk_pcom, msm_clk);
}

static int pc_clk_enable(struct clk_hw *hw)
{
	unsigned id = to_clk_pcom(hw)->id;
	int rc = msm_proc_comm(PCOM_CLKCTL_RPC_ENABLE, &id, NULL);
	int rc = msm_proc_comm(PCOM_CLKCTL_RPC_ENABLE, &id, NULL);
	if (rc < 0)
	if (rc < 0)
		return rc;
		return rc;
@@ -35,14 +47,16 @@ static int pc_clk_enable(unsigned id)
		return (int)id < 0 ? -EINVAL : 0;
		return (int)id < 0 ? -EINVAL : 0;
}
}


static void pc_clk_disable(unsigned id)
static void pc_clk_disable(struct clk_hw *hw)
{
{
	unsigned id = to_clk_pcom(hw)->id;
	msm_proc_comm(PCOM_CLKCTL_RPC_DISABLE, &id, NULL);
	msm_proc_comm(PCOM_CLKCTL_RPC_DISABLE, &id, NULL);
}
}


int pc_clk_reset(unsigned id, enum clk_reset_action action)
static int pc_clk_reset(struct clk_hw *hw, enum clk_reset_action action)
{
{
	int rc;
	int rc;
	unsigned id = to_clk_pcom(hw)->id;


	if (action == CLK_RESET_ASSERT)
	if (action == CLK_RESET_ASSERT)
		rc = msm_proc_comm(PCOM_CLKCTL_RPC_RESET_ASSERT, &id, NULL);
		rc = msm_proc_comm(PCOM_CLKCTL_RPC_RESET_ASSERT, &id, NULL);
@@ -55,83 +69,99 @@ int pc_clk_reset(unsigned id, enum clk_reset_action action)
		return (int)id < 0 ? -EINVAL : 0;
		return (int)id < 0 ? -EINVAL : 0;
}
}


static int pc_clk_set_rate(unsigned id, unsigned rate)
static int pc_clk_set_rate(struct clk_hw *hw, unsigned long new_rate,
			   unsigned long p_rate)
{
{
	/* The rate _might_ be rounded off to the nearest KHz value by the
	struct clk_pcom *p = to_clk_pcom(hw);
	unsigned id = p->id, rate = new_rate;
	int rc;

	/*
	 * The rate _might_ be rounded off to the nearest KHz value by the
	 * remote function. So a return value of 0 doesn't necessarily mean
	 * remote function. So a return value of 0 doesn't necessarily mean
	 * that the exact rate was set successfully.
	 * that the exact rate was set successfully.
	 */
	 */
	int rc = msm_proc_comm(PCOM_CLKCTL_RPC_SET_RATE, &id, &rate);
	if (p->flags & CLKFLAG_MIN)
	if (rc < 0)
		rc = msm_proc_comm(PCOM_CLKCTL_RPC_MIN_RATE, &id, &rate);
		return rc;
	else
	else
		return (int)id < 0 ? -EINVAL : 0;
		rc = msm_proc_comm(PCOM_CLKCTL_RPC_SET_RATE, &id, &rate);
}

static int pc_clk_set_min_rate(unsigned id, unsigned rate)
{
	int rc = msm_proc_comm(PCOM_CLKCTL_RPC_MIN_RATE, &id, &rate);
	if (rc < 0)
		return rc;
	else
		return (int)id < 0 ? -EINVAL : 0;
}

static int pc_clk_set_max_rate(unsigned id, unsigned rate)
{
	int rc = msm_proc_comm(PCOM_CLKCTL_RPC_MAX_RATE, &id, &rate);
	if (rc < 0)
	if (rc < 0)
		return rc;
		return rc;
	else
	else
		return (int)id < 0 ? -EINVAL : 0;
		return (int)id < 0 ? -EINVAL : 0;
}
}


static unsigned pc_clk_get_rate(unsigned id)
static unsigned long pc_clk_recalc_rate(struct clk_hw *hw, unsigned long p_rate)
{
{
	unsigned id = to_clk_pcom(hw)->id;
	if (msm_proc_comm(PCOM_CLKCTL_RPC_RATE, &id, NULL))
	if (msm_proc_comm(PCOM_CLKCTL_RPC_RATE, &id, NULL))
		return 0;
		return 0;
	else
	else
		return id;
		return id;
}
}


static unsigned pc_clk_is_enabled(unsigned id)
static int pc_clk_is_enabled(struct clk_hw *hw)
{
{
	unsigned id = to_clk_pcom(hw)->id;
	if (msm_proc_comm(PCOM_CLKCTL_RPC_ENABLED, &id, NULL))
	if (msm_proc_comm(PCOM_CLKCTL_RPC_ENABLED, &id, NULL))
		return 0;
		return 0;
	else
	else
		return id;
		return id;
}
}


static long pc_clk_round_rate(unsigned id, unsigned rate)
static long pc_clk_round_rate(struct clk_hw *hw, unsigned long rate,
			      unsigned long *p_rate)
{
{

	/* Not really supported; pc_clk_set_rate() does rounding on it's own. */
	/* Not really supported; pc_clk_set_rate() does rounding on it's own. */
	return rate;
	return rate;
}
}


static bool pc_clk_is_local(unsigned id)
static struct clk_ops clk_ops_pcom = {
{
	return false;
}

struct clk_ops clk_ops_pcom = {
	.enable = pc_clk_enable,
	.enable = pc_clk_enable,
	.disable = pc_clk_disable,
	.disable = pc_clk_disable,
	.auto_off = pc_clk_disable,
	.reset = pc_clk_reset,
	.set_rate = pc_clk_set_rate,
	.set_rate = pc_clk_set_rate,
	.set_min_rate = pc_clk_set_min_rate,
	.recalc_rate = pc_clk_recalc_rate,
	.set_max_rate = pc_clk_set_max_rate,
	.get_rate = pc_clk_get_rate,
	.is_enabled = pc_clk_is_enabled,
	.is_enabled = pc_clk_is_enabled,
	.round_rate = pc_clk_round_rate,
	.round_rate = pc_clk_round_rate,
	.is_local = pc_clk_is_local,
};
};


static int msm_clock_pcom_probe(struct platform_device *pdev)
static int msm_clock_pcom_probe(struct platform_device *pdev)
{
{
	const struct pcom_clk_pdata *pdata = pdev->dev.platform_data;
	const struct pcom_clk_pdata *pdata = pdev->dev.platform_data;
	msm_clock_init(pdata->lookup, pdata->num_lookups);
	int i, ret;

	for (i = 0; i < pdata->num_lookups; i++) {
		const struct clk_pcom_desc *desc = &pdata->lookup[i];
		struct clk *c;
		struct clk_pcom *p;
		struct clk_hw *hw;
		struct clk_init_data init;

		p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL);
		if (!p)
			return -ENOMEM;

		p->id = desc->id;
		p->flags = desc->flags;
		p->msm_clk.reset = pc_clk_reset;

		hw = &p->msm_clk.hw;
		hw->init = &init;

		init.name = desc->name;
		init.ops = &clk_ops_pcom;
		init.num_parents = 0;
		init.flags = CLK_IS_ROOT;

		if (!(p->flags & CLKFLAG_AUTO_OFF))
			init.flags |= CLK_IGNORE_UNUSED;

		c = devm_clk_register(&pdev->dev, hw);
		ret = clk_register_clkdev(c, desc->con, desc->dev);
		if (ret)
			return ret;
	}

	return 0;
	return 0;
}
}


+15 −15
Original line number Original line Diff line number Diff line
/* Copyright (c) 2009, Code Aurora Forum. All rights reserved.
/*
 * Copyright (c) 2009-2012, The Linux Foundation. All rights reserved.
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * it under the terms of the GNU General Public License version 2 and
@@ -120,26 +121,25 @@


#define P_NR_CLKS		102
#define P_NR_CLKS		102


struct clk_ops;
struct clk_pcom_desc {
extern struct clk_ops clk_ops_pcom;
	unsigned id;
	const char *name;
	const char *con;
	const char *dev;
	unsigned long flags;
};


struct pcom_clk_pdata {
struct pcom_clk_pdata {
	struct clk_lookup *lookup;
	struct clk_pcom_desc *lookup;
	u32 num_lookups;
	u32 num_lookups;
};
};


int pc_clk_reset(unsigned id, enum clk_reset_action action);

#define CLK_PCOM(clk_name, clk_id, clk_dev, clk_flags) {	\
#define CLK_PCOM(clk_name, clk_id, clk_dev, clk_flags) {	\
	.con_id = clk_name, \
	.dev_id = clk_dev, \
	.clk = &(struct clk){ \
	.id = P_##clk_id,					\
	.id = P_##clk_id,					\
		.remote_id = P_##clk_id, \
	.name = #clk_id,					\
		.ops = &clk_ops_pcom, \
	.con = clk_name,					\
	.dev = clk_dev,						\
	.flags = clk_flags,					\
	.flags = clk_flags,					\
		.dbg_name = #clk_id, \
	}, \
	}
	}


#endif
#endif
Loading