aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc
diff options
context:
space:
mode:
authorArun Murthy <arun.murthy@stericsson.com>2010-09-06 02:54:52 -0400
committerSamuel Ortiz <sameo@linux.intel.com>2010-10-28 18:29:21 -0400
commitf0f05b1c751772d19c9c8f36d75e97b1d9687407 (patch)
tree31aa221575b1b05a6f3d63f7185ff01a29541490 /drivers/misc
parent47c1697508f2ec9f6b31ce6c825fe1017871dea6 (diff)
misc: Add ab8500 pwm driver
This patch adds a Pulse Width Modulation driver for Analog Baseband Chip AB8500. Signed-off-by: Arun Murthy <arun.murthy@stericsson.com> Acked-by: Linus Walleij <linus.walleij@stericsson.com> Acked-by: Mike Rapoport <mike@compulab.co.il> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers/misc')
-rw-r--r--drivers/misc/Kconfig9
-rw-r--r--drivers/misc/Makefile1
-rw-r--r--drivers/misc/ab8500-pwm.c168
3 files changed, 178 insertions, 0 deletions
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 39a2173b4e6c..4d073f1e4502 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -62,6 +62,15 @@ config ATMEL_PWM
62 purposes including software controlled power-efficient backlights 62 purposes including software controlled power-efficient backlights
63 on LCD displays, motor control, and waveform generation. 63 on LCD displays, motor control, and waveform generation.
64 64
65config AB8500_PWM
66 bool "AB8500 PWM support"
67 depends on AB8500_CORE
68 select HAVE_PWM
69 help
70 This driver exports functions to enable/disble/config/free Pulse
71 Width Modulation in the Analog Baseband Chip AB8500.
72 It is used by led and backlight driver to control the intensity.
73
65config ATMEL_TCLIB 74config ATMEL_TCLIB
66 bool "Atmel AT32/AT91 Timer/Counter Library" 75 bool "Atmel AT32/AT91 Timer/Counter Library"
67 depends on (AVR32 || ARCH_AT91) 76 depends on (AVR32 || ARCH_AT91)
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 47af4cd08f01..98009cc20cb9 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -41,3 +41,4 @@ obj-$(CONFIG_VMWARE_BALLOON) += vmw_balloon.o
41obj-$(CONFIG_ARM_CHARLCD) += arm-charlcd.o 41obj-$(CONFIG_ARM_CHARLCD) += arm-charlcd.o
42obj-$(CONFIG_PCH_PHUB) += pch_phub.o 42obj-$(CONFIG_PCH_PHUB) += pch_phub.o
43obj-y += ti-st/ 43obj-y += ti-st/
44obj-$(CONFIG_AB8500_PWM) += ab8500-pwm.o
diff --git a/drivers/misc/ab8500-pwm.c b/drivers/misc/ab8500-pwm.c
new file mode 100644
index 000000000000..54e3d05b63cc
--- /dev/null
+++ b/drivers/misc/ab8500-pwm.c
@@ -0,0 +1,168 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * Author: Arun R Murthy <arun.murthy@stericsson.com>
5 * License terms: GNU General Public License (GPL) version 2
6 */
7#include <linux/err.h>
8#include <linux/platform_device.h>
9#include <linux/slab.h>
10#include <linux/pwm.h>
11#include <linux/mfd/ab8500.h>
12#include <linux/mfd/abx500.h>
13
14/*
15 * PWM Out generators
16 * Bank: 0x10
17 */
18#define AB8500_PWM_OUT_CTRL1_REG 0x60
19#define AB8500_PWM_OUT_CTRL2_REG 0x61
20#define AB8500_PWM_OUT_CTRL7_REG 0x66
21
22/* backlight driver constants */
23#define ENABLE_PWM 1
24#define DISABLE_PWM 0
25
26struct pwm_device {
27 struct device *dev;
28 struct list_head node;
29 const char *label;
30 unsigned int pwm_id;
31};
32
33static LIST_HEAD(pwm_list);
34
35int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns)
36{
37 int ret = 0;
38 unsigned int higher_val, lower_val;
39 u8 reg;
40
41 /*
42 * get the first 8 bits that are be written to
43 * AB8500_PWM_OUT_CTRL1_REG[0:7]
44 */
45 lower_val = duty_ns & 0x00FF;
46 /*
47 * get bits [9:10] that are to be written to
48 * AB8500_PWM_OUT_CTRL2_REG[0:1]
49 */
50 higher_val = ((duty_ns & 0x0300) >> 8);
51
52 reg = AB8500_PWM_OUT_CTRL1_REG + ((pwm->pwm_id - 1) * 2);
53
54 ret = abx500_set_register_interruptible(pwm->dev, AB8500_MISC,
55 reg, (u8)lower_val);
56 if (ret < 0)
57 return ret;
58 ret = abx500_set_register_interruptible(pwm->dev, AB8500_MISC,
59 (reg + 1), (u8)higher_val);
60
61 return ret;
62}
63EXPORT_SYMBOL(pwm_config);
64
65int pwm_enable(struct pwm_device *pwm)
66{
67 int ret;
68
69 ret = abx500_mask_and_set_register_interruptible(pwm->dev,
70 AB8500_MISC, AB8500_PWM_OUT_CTRL7_REG,
71 1 << (pwm->pwm_id-1), ENABLE_PWM);
72 if (ret < 0)
73 dev_err(pwm->dev, "%s: Failed to disable PWM, Error %d\n",
74 pwm->label, ret);
75 return ret;
76}
77EXPORT_SYMBOL(pwm_enable);
78
79void pwm_disable(struct pwm_device *pwm)
80{
81 int ret;
82
83 ret = abx500_mask_and_set_register_interruptible(pwm->dev,
84 AB8500_MISC, AB8500_PWM_OUT_CTRL7_REG,
85 1 << (pwm->pwm_id-1), DISABLE_PWM);
86 if (ret < 0)
87 dev_err(pwm->dev, "%s: Failed to disable PWM, Error %d\n",
88 pwm->label, ret);
89 return;
90}
91EXPORT_SYMBOL(pwm_disable);
92
93struct pwm_device *pwm_request(int pwm_id, const char *label)
94{
95 struct pwm_device *pwm;
96
97 list_for_each_entry(pwm, &pwm_list, node) {
98 if (pwm->pwm_id == pwm_id) {
99 pwm->label = label;
100 pwm->pwm_id = pwm_id;
101 return pwm;
102 }
103 }
104
105 return ERR_PTR(-ENOENT);
106}
107EXPORT_SYMBOL(pwm_request);
108
109void pwm_free(struct pwm_device *pwm)
110{
111 pwm_disable(pwm);
112}
113EXPORT_SYMBOL(pwm_free);
114
115static int __devinit ab8500_pwm_probe(struct platform_device *pdev)
116{
117 struct pwm_device *pwm;
118 /*
119 * Nothing to be done in probe, this is required to get the
120 * device which is required for ab8500 read and write
121 */
122 pwm = kzalloc(sizeof(struct pwm_device), GFP_KERNEL);
123 if (pwm == NULL) {
124 dev_err(&pdev->dev, "failed to allocate memory\n");
125 return -ENOMEM;
126 }
127 pwm->dev = &pdev->dev;
128 pwm->pwm_id = pdev->id;
129 list_add_tail(&pwm->node, &pwm_list);
130 platform_set_drvdata(pdev, pwm);
131 dev_dbg(pwm->dev, "pwm probe successful\n");
132 return 0;
133}
134
135static int __devexit ab8500_pwm_remove(struct platform_device *pdev)
136{
137 struct pwm_device *pwm = platform_get_drvdata(pdev);
138 list_del(&pwm->node);
139 dev_dbg(&pdev->dev, "pwm driver removed\n");
140 kfree(pwm);
141 return 0;
142}
143
144static struct platform_driver ab8500_pwm_driver = {
145 .driver = {
146 .name = "ab8500-pwm",
147 .owner = THIS_MODULE,
148 },
149 .probe = ab8500_pwm_probe,
150 .remove = __devexit_p(ab8500_pwm_remove),
151};
152
153static int __init ab8500_pwm_init(void)
154{
155 return platform_driver_register(&ab8500_pwm_driver);
156}
157
158static void __exit ab8500_pwm_exit(void)
159{
160 platform_driver_unregister(&ab8500_pwm_driver);
161}
162
163subsys_initcall(ab8500_pwm_init);
164module_exit(ab8500_pwm_exit);
165MODULE_AUTHOR("Arun MURTHY <arun.murthy@stericsson.com>");
166MODULE_DESCRIPTION("AB8500 Pulse Width Modulation Driver");
167MODULE_ALIAS("AB8500 PWM driver");
168MODULE_LICENSE("GPL v2");