pwm: spear: Make use of devm_pwmchip_alloc() function
This prepares the pwm-spear driver to further changes of the pwm core outlined in the commit introducing devm_pwmchip_alloc(). There is no intended semantical change and the driver should behave as before. Link: https://lore.kernel.org/r/c67e3f26435a8fa047ad6887803dbcb9c1e032ee.1707900770.git.u.kleine-koenig@pengutronix.de Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
This commit is contained in:
+8
-10
@@ -48,17 +48,15 @@
|
|||||||
*
|
*
|
||||||
* @mmio_base: base address of pwm chip
|
* @mmio_base: base address of pwm chip
|
||||||
* @clk: pointer to clk structure of pwm chip
|
* @clk: pointer to clk structure of pwm chip
|
||||||
* @chip: linux pwm chip representation
|
|
||||||
*/
|
*/
|
||||||
struct spear_pwm_chip {
|
struct spear_pwm_chip {
|
||||||
void __iomem *mmio_base;
|
void __iomem *mmio_base;
|
||||||
struct clk *clk;
|
struct clk *clk;
|
||||||
struct pwm_chip chip;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline struct spear_pwm_chip *to_spear_pwm_chip(struct pwm_chip *chip)
|
static inline struct spear_pwm_chip *to_spear_pwm_chip(struct pwm_chip *chip)
|
||||||
{
|
{
|
||||||
return container_of(chip, struct spear_pwm_chip, chip);
|
return pwmchip_get_drvdata(chip);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline u32 spear_pwm_readl(struct spear_pwm_chip *chip, unsigned int num,
|
static inline u32 spear_pwm_readl(struct spear_pwm_chip *chip, unsigned int num,
|
||||||
@@ -194,13 +192,15 @@ static const struct pwm_ops spear_pwm_ops = {
|
|||||||
static int spear_pwm_probe(struct platform_device *pdev)
|
static int spear_pwm_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct device_node *np = pdev->dev.of_node;
|
struct device_node *np = pdev->dev.of_node;
|
||||||
|
struct pwm_chip *chip;
|
||||||
struct spear_pwm_chip *pc;
|
struct spear_pwm_chip *pc;
|
||||||
int ret;
|
int ret;
|
||||||
u32 val;
|
u32 val;
|
||||||
|
|
||||||
pc = devm_kzalloc(&pdev->dev, sizeof(*pc), GFP_KERNEL);
|
chip = devm_pwmchip_alloc(&pdev->dev, NUM_PWM, sizeof(*pc));
|
||||||
if (!pc)
|
if (IS_ERR(chip))
|
||||||
return -ENOMEM;
|
return PTR_ERR(chip);
|
||||||
|
pc = to_spear_pwm_chip(chip);
|
||||||
|
|
||||||
pc->mmio_base = devm_platform_ioremap_resource(pdev, 0);
|
pc->mmio_base = devm_platform_ioremap_resource(pdev, 0);
|
||||||
if (IS_ERR(pc->mmio_base))
|
if (IS_ERR(pc->mmio_base))
|
||||||
@@ -211,9 +211,7 @@ static int spear_pwm_probe(struct platform_device *pdev)
|
|||||||
return dev_err_probe(&pdev->dev, PTR_ERR(pc->clk),
|
return dev_err_probe(&pdev->dev, PTR_ERR(pc->clk),
|
||||||
"Failed to get clock\n");
|
"Failed to get clock\n");
|
||||||
|
|
||||||
pc->chip.dev = &pdev->dev;
|
chip->ops = &spear_pwm_ops;
|
||||||
pc->chip.ops = &spear_pwm_ops;
|
|
||||||
pc->chip.npwm = NUM_PWM;
|
|
||||||
|
|
||||||
if (of_device_is_compatible(np, "st,spear1340-pwm")) {
|
if (of_device_is_compatible(np, "st,spear1340-pwm")) {
|
||||||
ret = clk_enable(pc->clk);
|
ret = clk_enable(pc->clk);
|
||||||
@@ -232,7 +230,7 @@ static int spear_pwm_probe(struct platform_device *pdev)
|
|||||||
clk_disable(pc->clk);
|
clk_disable(pc->clk);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = devm_pwmchip_add(&pdev->dev, &pc->chip);
|
ret = devm_pwmchip_add(&pdev->dev, chip);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return dev_err_probe(&pdev->dev, ret, "pwmchip_add() failed\n");
|
return dev_err_probe(&pdev->dev, ret, "pwmchip_add() failed\n");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user