2 * Copyright (C) ST-Ericsson SA 2010
4 * Author: Arun R Murthy <arun.murthy@stericsson.com>
5 * License terms: GNU General Public License (GPL) version 2
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>
18 #define AB8500_PWM_OUT_CTRL1_REG 0x60
19 #define AB8500_PWM_OUT_CTRL2_REG 0x61
20 #define AB8500_PWM_OUT_CTRL7_REG 0x66
22 /* backlight driver constants */
28 struct list_head node
;
33 static LIST_HEAD(pwm_list
);
35 int pwm_config(struct pwm_device
*pwm
, int duty_ns
, int period_ns
)
38 unsigned int higher_val
, lower_val
;
42 * get the first 8 bits that are be written to
43 * AB8500_PWM_OUT_CTRL1_REG[0:7]
45 lower_val
= duty_ns
& 0x00FF;
47 * get bits [9:10] that are to be written to
48 * AB8500_PWM_OUT_CTRL2_REG[0:1]
50 higher_val
= ((duty_ns
& 0x0300) >> 8);
52 reg
= AB8500_PWM_OUT_CTRL1_REG
+ ((pwm
->pwm_id
- 1) * 2);
54 ret
= abx500_set_register_interruptible(pwm
->dev
, AB8500_MISC
,
58 ret
= abx500_set_register_interruptible(pwm
->dev
, AB8500_MISC
,
59 (reg
+ 1), (u8
)higher_val
);
63 EXPORT_SYMBOL(pwm_config
);
65 int pwm_enable(struct pwm_device
*pwm
)
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
);
73 dev_err(pwm
->dev
, "%s: Failed to disable PWM, Error %d\n",
77 EXPORT_SYMBOL(pwm_enable
);
79 void pwm_disable(struct pwm_device
*pwm
)
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
);
87 dev_err(pwm
->dev
, "%s: Failed to disable PWM, Error %d\n",
91 EXPORT_SYMBOL(pwm_disable
);
93 struct pwm_device
*pwm_request(int pwm_id
, const char *label
)
95 struct pwm_device
*pwm
;
97 list_for_each_entry(pwm
, &pwm_list
, node
) {
98 if (pwm
->pwm_id
== pwm_id
) {
100 pwm
->pwm_id
= pwm_id
;
105 return ERR_PTR(-ENOENT
);
107 EXPORT_SYMBOL(pwm_request
);
109 void pwm_free(struct pwm_device
*pwm
)
113 EXPORT_SYMBOL(pwm_free
);
115 static int __devinit
ab8500_pwm_probe(struct platform_device
*pdev
)
117 struct pwm_device
*pwm
;
119 * Nothing to be done in probe, this is required to get the
120 * device which is required for ab8500 read and write
122 pwm
= kzalloc(sizeof(struct pwm_device
), GFP_KERNEL
);
124 dev_err(&pdev
->dev
, "failed to allocate memory\n");
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");
135 static int __devexit
ab8500_pwm_remove(struct platform_device
*pdev
)
137 struct pwm_device
*pwm
= platform_get_drvdata(pdev
);
138 list_del(&pwm
->node
);
139 dev_dbg(&pdev
->dev
, "pwm driver removed\n");
144 static struct platform_driver ab8500_pwm_driver
= {
146 .name
= "ab8500-pwm",
147 .owner
= THIS_MODULE
,
149 .probe
= ab8500_pwm_probe
,
150 .remove
= __devexit_p(ab8500_pwm_remove
),
153 static int __init
ab8500_pwm_init(void)
155 return platform_driver_register(&ab8500_pwm_driver
);
158 static void __exit
ab8500_pwm_exit(void)
160 platform_driver_unregister(&ab8500_pwm_driver
);
163 subsys_initcall(ab8500_pwm_init
);
164 module_exit(ab8500_pwm_exit
);
165 MODULE_AUTHOR("Arun MURTHY <arun.murthy@stericsson.com>");
166 MODULE_DESCRIPTION("AB8500 Pulse Width Modulation Driver");
167 MODULE_ALIAS("platform:ab8500-pwm");
168 MODULE_LICENSE("GPL v2");