blob: a6675a44940958cc47533c866a27681dc6a9bdcd [file] [log] [blame]
Benjamin Gaignardd0f949e2017-01-20 10:15:03 +01001/*
2 * Copyright (C) STMicroelectronics 2016
3 *
4 * Author: Benjamin Gaignard <benjamin.gaignard@st.com>
5 *
6 * License terms: GNU General Public License (GPL), version 2
7 */
8
9#include <linux/mfd/stm32-timers.h>
10#include <linux/module.h>
11#include <linux/of_platform.h>
12#include <linux/reset.h>
13
14static const struct regmap_config stm32_timers_regmap_cfg = {
15 .reg_bits = 32,
16 .val_bits = 32,
17 .reg_stride = sizeof(u32),
Fabrice Gasnierae6816b2017-02-15 09:04:32 +010018 .max_register = 0x3fc,
Benjamin Gaignardd0f949e2017-01-20 10:15:03 +010019};
20
21static void stm32_timers_get_arr_size(struct stm32_timers *ddata)
22{
23 /*
24 * Only the available bits will be written so when readback
25 * we get the maximum value of auto reload register
26 */
27 regmap_write(ddata->regmap, TIM_ARR, ~0L);
28 regmap_read(ddata->regmap, TIM_ARR, &ddata->max_arr);
29 regmap_write(ddata->regmap, TIM_ARR, 0x0);
30}
31
32static int stm32_timers_probe(struct platform_device *pdev)
33{
34 struct device *dev = &pdev->dev;
35 struct stm32_timers *ddata;
36 struct resource *res;
37 void __iomem *mmio;
38
39 ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL);
40 if (!ddata)
41 return -ENOMEM;
42
43 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
44 mmio = devm_ioremap_resource(dev, res);
45 if (IS_ERR(mmio))
46 return PTR_ERR(mmio);
47
48 ddata->regmap = devm_regmap_init_mmio_clk(dev, "int", mmio,
49 &stm32_timers_regmap_cfg);
50 if (IS_ERR(ddata->regmap))
51 return PTR_ERR(ddata->regmap);
52
53 ddata->clk = devm_clk_get(dev, NULL);
54 if (IS_ERR(ddata->clk))
55 return PTR_ERR(ddata->clk);
56
57 stm32_timers_get_arr_size(ddata);
58
59 platform_set_drvdata(pdev, ddata);
60
Benjamin Gaignardc42a8edb2017-05-29 17:45:53 +020061 return devm_of_platform_populate(&pdev->dev);
Fabrice Gasnierf8b7ce62017-02-01 17:41:46 +010062}
63
Benjamin Gaignardd0f949e2017-01-20 10:15:03 +010064static const struct of_device_id stm32_timers_of_match[] = {
65 { .compatible = "st,stm32-timers", },
66 { /* end node */ },
67};
68MODULE_DEVICE_TABLE(of, stm32_timers_of_match);
69
70static struct platform_driver stm32_timers_driver = {
71 .probe = stm32_timers_probe,
Benjamin Gaignardd0f949e2017-01-20 10:15:03 +010072 .driver = {
73 .name = "stm32-timers",
74 .of_match_table = stm32_timers_of_match,
75 },
76};
77module_platform_driver(stm32_timers_driver);
78
79MODULE_DESCRIPTION("STMicroelectronics STM32 Timers");
80MODULE_LICENSE("GPL v2");