cregit-Linux how code gets into the kernel

Release 4.7 drivers/clk/ti/clk-dra7-atl.c

Directory: drivers/clk/ti
/*
 * DRA7 ATL (Audio Tracking Logic) clock driver
 *
 * Copyright (C) 2013 Texas Instruments, Inc.
 *
 * Peter Ujfalusi <peter.ujfalusi@ti.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
 * kind, whether express or implied; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <linux/module.h>
#include <linux/clk.h>
#include <linux/clk-provider.h>
#include <linux/slab.h>
#include <linux/io.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>


#define DRA7_ATL_INSTANCES	4


#define DRA7_ATL_PPMR_REG(id)		(0x200 + (id * 0x80))

#define DRA7_ATL_BBSR_REG(id)		(0x204 + (id * 0x80))

#define DRA7_ATL_ATLCR_REG(id)		(0x208 + (id * 0x80))

#define DRA7_ATL_SWEN_REG(id)		(0x210 + (id * 0x80))

#define DRA7_ATL_BWSMUX_REG(id)		(0x214 + (id * 0x80))

#define DRA7_ATL_AWSMUX_REG(id)		(0x218 + (id * 0x80))

#define DRA7_ATL_PCLKMUX_REG(id)	(0x21c + (id * 0x80))


#define DRA7_ATL_SWEN			BIT(0)

#define DRA7_ATL_DIVIDER_MASK		(0x1f)

#define DRA7_ATL_PCLKMUX		BIT(0)
struct dra7_atl_clock_info;


struct dra7_atl_desc {
	
struct clk *clk;
	
struct clk_hw hw;
	
struct dra7_atl_clock_info *cinfo;
	
int id;

	
bool probed;		/* the driver for the IP has been loaded */
	
bool valid;		/* configured */
	
bool enabled;
	
u32 bws;		/* Baseband Word Select Mux */
	
u32 aws;		/* Audio Word Select Mux */
	
u32 divider;		/* Cached divider value */
};


struct dra7_atl_clock_info {
	
struct device *dev;
	
void __iomem *iobase;

	
struct dra7_atl_desc *cdesc;
};


#define to_atl_desc(_hw)	container_of(_hw, struct dra7_atl_desc, hw)


static inline void atl_write(struct dra7_atl_clock_info *cinfo, u32 reg, u32 val) { __raw_writel(val, cinfo->iobase + reg); }

Contributors

PersonTokensPropCommitsCommitProp
peter ujfalusipeter ujfalusi29100.00%1100.00%
Total29100.00%1100.00%


static inline int atl_read(struct dra7_atl_clock_info *cinfo, u32 reg) { return __raw_readl(cinfo->iobase + reg); }

Contributors

PersonTokensPropCommitsCommitProp
peter ujfalusipeter ujfalusi25100.00%1100.00%
Total25100.00%1100.00%


static int atl_clk_enable(struct clk_hw *hw) { struct dra7_atl_desc *cdesc = to_atl_desc(hw); if (!cdesc->probed) goto out; if (unlikely(!cdesc->valid)) dev_warn(cdesc->cinfo->dev, "atl%d has not been configured\n", cdesc->id); pm_runtime_get_sync(cdesc->cinfo->dev); atl_write(cdesc->cinfo, DRA7_ATL_ATLCR_REG(cdesc->id), cdesc->divider - 1); atl_write(cdesc->cinfo, DRA7_ATL_SWEN_REG(cdesc->id), DRA7_ATL_SWEN); out: cdesc->enabled = true; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
peter ujfalusipeter ujfalusi112100.00%1100.00%
Total112100.00%1100.00%


static void atl_clk_disable(struct clk_hw *hw) { struct dra7_atl_desc *cdesc = to_atl_desc(hw); if (!cdesc->probed) goto out; atl_write(cdesc->cinfo, DRA7_ATL_SWEN_REG(cdesc->id), 0); pm_runtime_put_sync(cdesc->cinfo->dev); out: cdesc->enabled = false; }

Contributors

PersonTokensPropCommitsCommitProp
peter ujfalusipeter ujfalusi64100.00%1100.00%
Total64100.00%1100.00%


static int atl_clk_is_enabled(struct clk_hw *hw) { struct dra7_atl_desc *cdesc = to_atl_desc(hw); return cdesc->enabled; }

Contributors

PersonTokensPropCommitsCommitProp
peter ujfalusipeter ujfalusi26100.00%1100.00%
Total26100.00%1100.00%


static unsigned long atl_clk_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct dra7_atl_desc *cdesc = to_atl_desc(hw); return parent_rate / cdesc->divider; }

Contributors

PersonTokensPropCommitsCommitProp
peter ujfalusipeter ujfalusi33100.00%1100.00%
Total33100.00%1100.00%


static long atl_clk_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *parent_rate) { unsigned divider; divider = (*parent_rate + rate / 2) / rate; if (divider > DRA7_ATL_DIVIDER_MASK + 1) divider = DRA7_ATL_DIVIDER_MASK + 1; return *parent_rate / divider; }

Contributors

PersonTokensPropCommitsCommitProp
peter ujfalusipeter ujfalusi56100.00%1100.00%
Total56100.00%1100.00%


static int atl_clk_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct dra7_atl_desc *cdesc; u32 divider; if (!hw || !rate) return -EINVAL; cdesc = to_atl_desc(hw); divider = ((parent_rate + rate / 2) / rate) - 1; if (divider > DRA7_ATL_DIVIDER_MASK) divider = DRA7_ATL_DIVIDER_MASK; cdesc->divider = divider + 1; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
peter ujfalusipeter ujfalusi6477.11%150.00%
nishanth menonnishanth menon1922.89%150.00%
Total83100.00%2100.00%

static const struct clk_ops atl_clk_ops = { .enable = atl_clk_enable, .disable = atl_clk_disable, .is_enabled = atl_clk_is_enabled, .recalc_rate = atl_clk_recalc_rate, .round_rate = atl_clk_round_rate, .set_rate = atl_clk_set_rate, };
static void __init of_dra7_atl_clock_setup(struct device_node *node) { struct dra7_atl_desc *clk_hw = NULL; struct clk_init_data init = { NULL }; const char **parent_names = NULL; struct clk *clk; clk_hw = kzalloc(sizeof(*clk_hw), GFP_KERNEL); if (!clk_hw) { pr_err("%s: could not allocate dra7_atl_desc\n", __func__); return; } clk_hw->hw.init = &init; clk_hw->divider = 1; init.name = node->name; init.ops = &atl_clk_ops; init.flags = CLK_IGNORE_UNUSED; init.num_parents = of_clk_get_parent_count(node); if (init.num_parents != 1) { pr_err("%s: atl clock %s must have 1 parent\n", __func__, node->name); goto cleanup; } parent_names = kzalloc(sizeof(char *), GFP_KERNEL); if (!parent_names) goto cleanup; parent_names[0] = of_clk_get_parent_name(node, 0); init.parent_names = parent_names; clk = clk_register(NULL, &clk_hw->hw); if (!IS_ERR(clk)) { of_clk_add_provider(node, of_clk_src_simple_get, clk); kfree(parent_names); return; } cleanup: kfree(parent_names); kfree(clk_hw); }

Contributors

PersonTokensPropCommitsCommitProp
peter ujfalusipeter ujfalusi21997.33%133.33%
tero kristotero kristo52.22%133.33%
stephen boydstephen boyd10.44%133.33%
Total225100.00%3100.00%

CLK_OF_DECLARE(dra7_atl_clock, "ti,dra7-atl-clock", of_dra7_atl_clock_setup);
static int of_dra7_atl_clk_probe(struct platform_device *pdev) { struct device_node *node = pdev->dev.of_node; struct dra7_atl_clock_info *cinfo; int i; int ret = 0; if (!node) return -ENODEV; cinfo = devm_kzalloc(&pdev->dev, sizeof(*cinfo), GFP_KERNEL); if (!cinfo) return -ENOMEM; cinfo->iobase = of_iomap(node, 0); cinfo->dev = &pdev->dev; pm_runtime_enable(cinfo->dev); pm_runtime_irq_safe(cinfo->dev); pm_runtime_get_sync(cinfo->dev); atl_write(cinfo, DRA7_ATL_PCLKMUX_REG(0), DRA7_ATL_PCLKMUX); for (i = 0; i < DRA7_ATL_INSTANCES; i++) { struct device_node *cfg_node; char prop[5]; struct dra7_atl_desc *cdesc; struct of_phandle_args clkspec; struct clk *clk; int rc; rc = of_parse_phandle_with_args(node, "ti,provided-clocks", NULL, i, &clkspec); if (rc) { pr_err("%s: failed to lookup atl clock %d\n", __func__, i); return -EINVAL; } clk = of_clk_get_from_provider(&clkspec); if (IS_ERR(clk)) { pr_err("%s: failed to get atl clock %d from provider\n", __func__, i); return PTR_ERR(clk); } cdesc = to_atl_desc(__clk_get_hw(clk)); cdesc->cinfo = cinfo; cdesc->id = i; /* Get configuration for the ATL instances */ snprintf(prop, sizeof(prop), "atl%u", i); of_node_get(node); cfg_node = of_find_node_by_name(node, prop); if (cfg_node) { ret = of_property_read_u32(cfg_node, "bws", &cdesc->bws); ret |= of_property_read_u32(cfg_node, "aws", &cdesc->aws); if (!ret) { cdesc->valid = true; atl_write(cinfo, DRA7_ATL_BWSMUX_REG(i), cdesc->bws); atl_write(cinfo, DRA7_ATL_AWSMUX_REG(i), cdesc->aws); } of_node_put(cfg_node); } cdesc->probed = true; /* * Enable the clock if it has been asked prior to loading the * hw driver */ if (cdesc->enabled) atl_clk_enable(__clk_get_hw(clk)); } pm_runtime_put_sync(cinfo->dev); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
peter ujfalusipeter ujfalusi37293.94%375.00%
krzysztof kozlowskikrzysztof kozlowski246.06%125.00%
Total396100.00%4100.00%


static int of_dra7_atl_clk_remove(struct platform_device *pdev) { pm_runtime_disable(&pdev->dev); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
peter ujfalusipeter ujfalusi22100.00%1100.00%
Total22100.00%1100.00%

static const struct of_device_id of_dra7_atl_clk_match_tbl[] = { { .compatible = "ti,dra7-atl", }, {}, }; MODULE_DEVICE_TABLE(of, of_dra7_atl_clk_match_tbl); static struct platform_driver dra7_atl_clk_driver = { .driver = { .name = "dra7-atl", .of_match_table = of_dra7_atl_clk_match_tbl, }, .probe = of_dra7_atl_clk_probe, .remove = of_dra7_atl_clk_remove, }; module_platform_driver(dra7_atl_clk_driver); MODULE_DESCRIPTION("Clock driver for DRA7 Audio Tracking Logic"); MODULE_ALIAS("platform:dra7-atl-clock"); MODULE_AUTHOR("Peter Ujfalusi <peter.ujfalusi@ti.com>"); MODULE_LICENSE("GPL v2");

Overall Contributors

PersonTokensPropCommitsCommitProp
peter ujfalusipeter ujfalusi131496.05%333.33%
krzysztof kozlowskikrzysztof kozlowski241.75%111.11%
nishanth menonnishanth menon191.39%111.11%
tero kristotero kristo50.37%111.11%
stephen boydstephen boyd50.37%222.22%
fabian frederickfabian frederick10.07%111.11%
Total1368100.00%9100.00%
Directory: drivers/clk/ti
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
{% endraw %}