Skip to content
Snippets Groups Projects
Commit 6f835381 authored by Johannes Feldmann's avatar Johannes Feldmann
Browse files

Device tree overlay for fclk[0..3] created. Driver for fclk created to be able...

Device tree overlay for fclk[0..3] created. Driver for fclk created to be able to change the frequency.
parent 27ae1d3d
No related branches found
No related tags found
No related merge requests found
# Ignore unnecessary file in driver folders
*.tmp_versions
*.cmd
*.mod.c
*.o
*.symvers
*.order
obj-m += fclk.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
#include <linux/module.h> // included for all kernel modules
#include <linux/init.h> // included for __init and __exit macros
#include <linux/platform_device.h>
#include <linux/of_platform.h>
#include <linux/clk.h>
MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("Johannes Feldmann");
MODULE_DESCRIPTION("This module configures an fclk with settings from a device tree");
///////////////////////////////////////////////////////////////////////////////////////////////////
// Devicetree structures
/*
fclk_0: fclk@0 {
compatible = "jf,fclk-1.0.0";
reg = <0>;
clocks = <&clkc 15>;
freq-in-hz = <200000000>;
};
*/
///////////////////////////////////////////////////////////////////////////////////////////////////
// Driver structures
struct fclk_state {
struct device *pDev;
struct clk *pClk;
u32 nFreq;
};
///////////////////////////////////////////////////////////////////////////////////////////////////
// Function definitions
static int fclk_probe(struct platform_device *pdev)
{
struct fclk_state *pState;
int ret;
// Allocate memory for driver structure
pState = devm_kzalloc(&pdev->dev, sizeof(*pState), GFP_KERNEL);
if(!pState)
return -ENOMEM;
// Save device
pState->pDev = &pdev->dev;
// Set driver data
platform_set_drvdata(pdev, pState);
// Get clock
pState->pClk = devm_clk_get(&pdev->dev, NULL);
if(IS_ERR(pState->pClk))
{
dev_err(&pdev->dev, "fclk: failed to get clock");
return PTR_ERR(pState->pClk);
}
// Get Clock frequency
of_property_read_u32(pdev->dev.of_node, "freq-in-hz", &pState->nFreq);
ret = clk_set_rate(pState->pClk, pState->nFreq);
if(ret != 0)
{
dev_err(&pdev->dev, "fclk: Frequency set to %d failed", pState->nFreq);
return ret;
}
dev_info(&pdev->dev, "fclk: Frequency set to %d", pState->nFreq);
// Enable clock
//ret = clk_prepare_enable(pState->pClk);
if(ret != 0)
{
dev_err(&pdev->dev, "fclk: Failed to enalbe Clock");
return ret;
}
dev_info(&pdev->dev, "fclk: Probe successful for (%s)\n", pdev->name);
return 0;
}
static int fclk_remove(struct platform_device *pdev)
{
struct fclk_state *pState = platform_get_drvdata(pdev);
//clk_disable_unprepare(pState->pClk);
dev_info(&pdev->dev, "fclk: Removal successful\n");
return 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// Driver definition
static const struct of_device_id fclk_of_ids[] = {
{ .compatible = "jf,fclk-1.0.0",},
{}
};
static struct platform_driver fclk_driver = {
.driver = {
.name = "fclk",
.owner = THIS_MODULE,
.of_match_table = fclk_of_ids,
},
.probe = fclk_probe,
.remove = fclk_remove,
};
module_platform_driver(fclk_driver);
File added
File added
/dts-v1/;
/plugin/;
/ {
compatible = "xlnx,zynq-7000";
fragment@0 {
target-path = "/";
__overlay__ {
fclk_0: fclk@0 {
compatible = "jf,fclk-1.0.0";
clocks = <&clkc 15>;
freq-in-hz = <160000000>;
};
fclk_1: fclk@1 {
compatible = "jf,fclk-1.0.0";
clocks = <&clkc 16>;
freq-in-hz = <100000000>;
};
fclk_2: fclk@2 {
compatible = "jf,fclk-1.0.0";
clocks = <&clkc 17>;
freq-in-hz = <200000000>;
};
fclk_3: fclk@3 {
compatible = "jf,fclk-1.0.0";
clocks = <&clkc 18>;
freq-in-hz = <000000000>;
};
};
};
};
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment