-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In some platforms (like am33xx), PWM sub modules (ECAP, EHRPWM, EQEP) are integrated to PWM subsystem. These PWM submodules has resources shared and only one register bit-field is provided to control module/clock enable/disable, makes it difficult to handle common resources from independent PWMSS submodule drivers. So the solution here implemented in this patch is, to create driver for PWMSS and take the role of parent driver for PWM submodules. PWMSS parent driver enumerates all the child nodes under PWMSS module. Also symbol "pwmss_submodule_state_change" exported to enable clock gating for individual PWMSS submodules, and submodule drivers has to enable clock gating from their drivers. As this is only supported during DT boot, the parent/child relationship is created and populated in DT execution flow. The only required change is inside DTS file, making EHRPWM & ECAP as a child to PWMSS node. Signed-off-by: Philip, Avinash <avinashphilip@ti.com> Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
- Loading branch information
Philip, Avinash
authored and
Thierry Reding
committed
Nov 28, 2012
1 parent
83af240
commit af0ba00
Showing
5 changed files
with
221 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
TI SOC based PWM Subsystem | ||
|
||
Required properties: | ||
- compatible: Must be "ti,am33xx-pwmss"; | ||
- reg: physical base address and size of the registers map. | ||
- address-cells: Specify the number of u32 entries needed in child nodes. | ||
Should set to 1. | ||
- size-cells: specify number of u32 entries needed to specify child nodes size | ||
in reg property. Should set to 1. | ||
- ranges: describes the address mapping of a memory-mapped bus. Should set to | ||
physical address map of child's base address, physical address within | ||
parent's address space and length of the address map. For am33xx, | ||
3 set of child register maps present, ECAP register space, EQEP | ||
register space, EHRPWM register space. | ||
|
||
Also child nodes should also populated under PWMSS DT node. | ||
|
||
Example: | ||
pwmss0: pwmss@48300000 { | ||
compatible = "ti,am33xx-pwmss"; | ||
reg = <0x48300000 0x10>; | ||
ti,hwmods = "epwmss0"; | ||
#address-cells = <1>; | ||
#size-cells = <1>; | ||
status = "disabled"; | ||
ranges = <0x48300100 0x48300100 0x80 /* ECAP */ | ||
0x48300180 0x48300180 0x80 /* EQEP */ | ||
0x48300200 0x48300200 0x80>; /* EHRPWM */ | ||
|
||
/* child nodes go here */ | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* | ||
* TI PWM Subsystem driver | ||
* | ||
* Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/ | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* 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/module.h> | ||
#include <linux/platform_device.h> | ||
#include <linux/io.h> | ||
#include <linux/err.h> | ||
#include <linux/pm_runtime.h> | ||
#include <linux/of_device.h> | ||
|
||
#include "pwm-tipwmss.h" | ||
|
||
#define PWMSS_CLKCONFIG 0x8 /* Clock gating reg */ | ||
#define PWMSS_CLKSTATUS 0xc /* Clock gating status reg */ | ||
|
||
struct pwmss_info { | ||
void __iomem *mmio_base; | ||
struct mutex pwmss_lock; | ||
u16 pwmss_clkconfig; | ||
}; | ||
|
||
u16 pwmss_submodule_state_change(struct device *dev, int set) | ||
{ | ||
struct pwmss_info *info = dev_get_drvdata(dev); | ||
u16 val; | ||
|
||
mutex_lock(&info->pwmss_lock); | ||
val = readw(info->mmio_base + PWMSS_CLKCONFIG); | ||
val |= set; | ||
writew(val , info->mmio_base + PWMSS_CLKCONFIG); | ||
mutex_unlock(&info->pwmss_lock); | ||
|
||
return readw(info->mmio_base + PWMSS_CLKSTATUS); | ||
} | ||
EXPORT_SYMBOL(pwmss_submodule_state_change); | ||
|
||
static const struct of_device_id pwmss_of_match[] = { | ||
{ .compatible = "ti,am33xx-pwmss" }, | ||
{}, | ||
}; | ||
MODULE_DEVICE_TABLE(of, pwmss_of_match); | ||
|
||
static int pwmss_probe(struct platform_device *pdev) | ||
{ | ||
int ret; | ||
struct resource *r; | ||
struct pwmss_info *info; | ||
struct device_node *node = pdev->dev.of_node; | ||
|
||
info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); | ||
if (!info) { | ||
dev_err(&pdev->dev, "failed to allocate memory\n"); | ||
return -ENOMEM; | ||
} | ||
|
||
mutex_init(&info->pwmss_lock); | ||
|
||
r = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
if (!r) { | ||
dev_err(&pdev->dev, "no memory resource defined\n"); | ||
return -ENODEV; | ||
} | ||
|
||
info->mmio_base = devm_request_and_ioremap(&pdev->dev, r); | ||
if (!info->mmio_base) | ||
return -EADDRNOTAVAIL; | ||
|
||
pm_runtime_enable(&pdev->dev); | ||
pm_runtime_get_sync(&pdev->dev); | ||
platform_set_drvdata(pdev, info); | ||
|
||
/* Populate all the child nodes here... */ | ||
ret = of_platform_populate(node, NULL, NULL, &pdev->dev); | ||
if (ret) | ||
dev_err(&pdev->dev, "no child node found\n"); | ||
|
||
return ret; | ||
} | ||
|
||
static int pwmss_remove(struct platform_device *pdev) | ||
{ | ||
struct pwmss_info *info = platform_get_drvdata(pdev); | ||
|
||
pm_runtime_put_sync(&pdev->dev); | ||
pm_runtime_disable(&pdev->dev); | ||
mutex_destroy(&info->pwmss_lock); | ||
return 0; | ||
} | ||
|
||
static int pwmss_suspend(struct device *dev) | ||
{ | ||
struct pwmss_info *info = dev_get_drvdata(dev); | ||
|
||
info->pwmss_clkconfig = readw(info->mmio_base + PWMSS_CLKCONFIG); | ||
pm_runtime_put_sync(dev); | ||
return 0; | ||
} | ||
|
||
static int pwmss_resume(struct device *dev) | ||
{ | ||
struct pwmss_info *info = dev_get_drvdata(dev); | ||
|
||
pm_runtime_get_sync(dev); | ||
writew(info->pwmss_clkconfig, info->mmio_base + PWMSS_CLKCONFIG); | ||
return 0; | ||
} | ||
|
||
static SIMPLE_DEV_PM_OPS(pwmss_pm_ops, pwmss_suspend, pwmss_resume); | ||
|
||
static struct platform_driver pwmss_driver = { | ||
.driver = { | ||
.name = "pwmss", | ||
.owner = THIS_MODULE, | ||
.pm = &pwmss_pm_ops, | ||
.of_match_table = pwmss_of_match, | ||
}, | ||
.probe = pwmss_probe, | ||
.remove = pwmss_remove, | ||
}; | ||
|
||
module_platform_driver(pwmss_driver); | ||
|
||
MODULE_DESCRIPTION("PWM Subsystem driver"); | ||
MODULE_AUTHOR("Texas Instruments"); | ||
MODULE_LICENSE("GPL"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* TI PWM Subsystem driver | ||
* | ||
* Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/ | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* 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. | ||
* | ||
*/ | ||
|
||
#ifndef __TIPWMSS_H | ||
#define __TIPWMSS_H | ||
|
||
#ifdef CONFIG_PWM_TIPWMSS | ||
/* PWM substem clock gating */ | ||
#define PWMSS_ECAPCLK_EN BIT(0) | ||
#define PWMSS_ECAPCLK_STOP_REQ BIT(1) | ||
#define PWMSS_EPWMCLK_EN BIT(8) | ||
#define PWMSS_EPWMCLK_STOP_REQ BIT(9) | ||
|
||
#define PWMSS_ECAPCLK_EN_ACK BIT(0) | ||
#define PWMSS_EPWMCLK_EN_ACK BIT(8) | ||
|
||
extern u16 pwmss_submodule_state_change(struct device *dev, int set); | ||
#else | ||
static inline u16 pwmss_submodule_state_change(struct device *dev, int set) | ||
{ | ||
/* return success status value */ | ||
return 0xFFFF; | ||
} | ||
#endif | ||
#endif /* __TIPWMSS_H */ |