Commit | Line | Data |
---|---|---|
af0ba001 PA |
1 | /* |
2 | * TI PWM Subsystem driver | |
3 | * | |
4 | * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/ | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | */ | |
17 | ||
18 | #include <linux/module.h> | |
19 | #include <linux/platform_device.h> | |
20 | #include <linux/io.h> | |
21 | #include <linux/err.h> | |
22 | #include <linux/pm_runtime.h> | |
23 | #include <linux/of_device.h> | |
24 | ||
25 | #include "pwm-tipwmss.h" | |
26 | ||
27 | #define PWMSS_CLKCONFIG 0x8 /* Clock gating reg */ | |
28 | #define PWMSS_CLKSTATUS 0xc /* Clock gating status reg */ | |
29 | ||
30 | struct pwmss_info { | |
31 | void __iomem *mmio_base; | |
32 | struct mutex pwmss_lock; | |
33 | u16 pwmss_clkconfig; | |
34 | }; | |
35 | ||
36 | u16 pwmss_submodule_state_change(struct device *dev, int set) | |
37 | { | |
38 | struct pwmss_info *info = dev_get_drvdata(dev); | |
39 | u16 val; | |
40 | ||
41 | mutex_lock(&info->pwmss_lock); | |
42 | val = readw(info->mmio_base + PWMSS_CLKCONFIG); | |
43 | val |= set; | |
44 | writew(val , info->mmio_base + PWMSS_CLKCONFIG); | |
45 | mutex_unlock(&info->pwmss_lock); | |
46 | ||
47 | return readw(info->mmio_base + PWMSS_CLKSTATUS); | |
48 | } | |
49 | EXPORT_SYMBOL(pwmss_submodule_state_change); | |
50 | ||
51 | static const struct of_device_id pwmss_of_match[] = { | |
52 | { .compatible = "ti,am33xx-pwmss" }, | |
53 | {}, | |
54 | }; | |
55 | MODULE_DEVICE_TABLE(of, pwmss_of_match); | |
56 | ||
57 | static int pwmss_probe(struct platform_device *pdev) | |
58 | { | |
59 | int ret; | |
60 | struct resource *r; | |
61 | struct pwmss_info *info; | |
62 | struct device_node *node = pdev->dev.of_node; | |
63 | ||
64 | info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); | |
65 | if (!info) { | |
66 | dev_err(&pdev->dev, "failed to allocate memory\n"); | |
67 | return -ENOMEM; | |
68 | } | |
69 | ||
70 | mutex_init(&info->pwmss_lock); | |
71 | ||
72 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); | |
6d4294d1 TR |
73 | info->mmio_base = devm_ioremap_resource(&pdev->dev, r); |
74 | if (IS_ERR(info->mmio_base)) | |
75 | return PTR_ERR(info->mmio_base); | |
af0ba001 PA |
76 | |
77 | pm_runtime_enable(&pdev->dev); | |
78 | pm_runtime_get_sync(&pdev->dev); | |
79 | platform_set_drvdata(pdev, info); | |
80 | ||
81 | /* Populate all the child nodes here... */ | |
82 | ret = of_platform_populate(node, NULL, NULL, &pdev->dev); | |
83 | if (ret) | |
84 | dev_err(&pdev->dev, "no child node found\n"); | |
85 | ||
86 | return ret; | |
87 | } | |
88 | ||
89 | static int pwmss_remove(struct platform_device *pdev) | |
90 | { | |
91 | struct pwmss_info *info = platform_get_drvdata(pdev); | |
92 | ||
93 | pm_runtime_put_sync(&pdev->dev); | |
94 | pm_runtime_disable(&pdev->dev); | |
95 | mutex_destroy(&info->pwmss_lock); | |
96 | return 0; | |
97 | } | |
98 | ||
c26e9bb4 | 99 | #ifdef CONFIG_PM_SLEEP |
af0ba001 PA |
100 | static int pwmss_suspend(struct device *dev) |
101 | { | |
102 | struct pwmss_info *info = dev_get_drvdata(dev); | |
103 | ||
104 | info->pwmss_clkconfig = readw(info->mmio_base + PWMSS_CLKCONFIG); | |
105 | pm_runtime_put_sync(dev); | |
106 | return 0; | |
107 | } | |
108 | ||
109 | static int pwmss_resume(struct device *dev) | |
110 | { | |
111 | struct pwmss_info *info = dev_get_drvdata(dev); | |
112 | ||
113 | pm_runtime_get_sync(dev); | |
114 | writew(info->pwmss_clkconfig, info->mmio_base + PWMSS_CLKCONFIG); | |
115 | return 0; | |
116 | } | |
c26e9bb4 | 117 | #endif |
af0ba001 PA |
118 | |
119 | static SIMPLE_DEV_PM_OPS(pwmss_pm_ops, pwmss_suspend, pwmss_resume); | |
120 | ||
121 | static struct platform_driver pwmss_driver = { | |
122 | .driver = { | |
123 | .name = "pwmss", | |
124 | .owner = THIS_MODULE, | |
125 | .pm = &pwmss_pm_ops, | |
126 | .of_match_table = pwmss_of_match, | |
127 | }, | |
128 | .probe = pwmss_probe, | |
129 | .remove = pwmss_remove, | |
130 | }; | |
131 | ||
132 | module_platform_driver(pwmss_driver); | |
133 | ||
134 | MODULE_DESCRIPTION("PWM Subsystem driver"); | |
135 | MODULE_AUTHOR("Texas Instruments"); | |
136 | MODULE_LICENSE("GPL"); |