Merge tag 'dma-mapping-4.17-5' of git://git.infradead.org/users/hch/dma-mapping
[linux-2.6-block.git] / drivers / mfd / stm32-timers.c
CommitLineData
fa93f5b7 1// SPDX-License-Identifier: GPL-2.0
d0f949e2
BG
2/*
3 * Copyright (C) STMicroelectronics 2016
d0f949e2 4 * Author: Benjamin Gaignard <benjamin.gaignard@st.com>
d0f949e2
BG
5 */
6
7#include <linux/mfd/stm32-timers.h>
8#include <linux/module.h>
9#include <linux/of_platform.h>
10#include <linux/reset.h>
11
12static const struct regmap_config stm32_timers_regmap_cfg = {
13 .reg_bits = 32,
14 .val_bits = 32,
15 .reg_stride = sizeof(u32),
ae6816ba 16 .max_register = 0x3fc,
d0f949e2
BG
17};
18
19static void stm32_timers_get_arr_size(struct stm32_timers *ddata)
20{
21 /*
22 * Only the available bits will be written so when readback
23 * we get the maximum value of auto reload register
24 */
25 regmap_write(ddata->regmap, TIM_ARR, ~0L);
26 regmap_read(ddata->regmap, TIM_ARR, &ddata->max_arr);
27 regmap_write(ddata->regmap, TIM_ARR, 0x0);
28}
29
30static int stm32_timers_probe(struct platform_device *pdev)
31{
32 struct device *dev = &pdev->dev;
33 struct stm32_timers *ddata;
34 struct resource *res;
35 void __iomem *mmio;
36
37 ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL);
38 if (!ddata)
39 return -ENOMEM;
40
41 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
42 mmio = devm_ioremap_resource(dev, res);
43 if (IS_ERR(mmio))
44 return PTR_ERR(mmio);
45
46 ddata->regmap = devm_regmap_init_mmio_clk(dev, "int", mmio,
47 &stm32_timers_regmap_cfg);
48 if (IS_ERR(ddata->regmap))
49 return PTR_ERR(ddata->regmap);
50
51 ddata->clk = devm_clk_get(dev, NULL);
52 if (IS_ERR(ddata->clk))
53 return PTR_ERR(ddata->clk);
54
55 stm32_timers_get_arr_size(ddata);
56
57 platform_set_drvdata(pdev, ddata);
58
c42a8edb 59 return devm_of_platform_populate(&pdev->dev);
f8b7ce67
FG
60}
61
d0f949e2
BG
62static const struct of_device_id stm32_timers_of_match[] = {
63 { .compatible = "st,stm32-timers", },
64 { /* end node */ },
65};
66MODULE_DEVICE_TABLE(of, stm32_timers_of_match);
67
68static struct platform_driver stm32_timers_driver = {
69 .probe = stm32_timers_probe,
70 .driver = {
71 .name = "stm32-timers",
72 .of_match_table = stm32_timers_of_match,
73 },
74};
75module_platform_driver(stm32_timers_driver);
76
77MODULE_DESCRIPTION("STMicroelectronics STM32 Timers");
78MODULE_LICENSE("GPL v2");