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/abx500.h>
12 #include <linux/mfd/abx500/ab8500.h>
13 #include <linux/module.h>
19 #define AB8500_PWM_OUT_CTRL1_REG 0x60
20 #define AB8500_PWM_OUT_CTRL2_REG 0x61
21 #define AB8500_PWM_OUT_CTRL7_REG 0x66
23 /* backlight driver constants */
27 struct ab8500_pwm_chip {
31 static int ab8500_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
32 int duty_ns, int period_ns)
35 unsigned int higher_val, lower_val;
39 * get the first 8 bits that are be written to
40 * AB8500_PWM_OUT_CTRL1_REG[0:7]
42 lower_val = duty_ns & 0x00FF;
44 * get bits [9:10] that are to be written to
45 * AB8500_PWM_OUT_CTRL2_REG[0:1]
47 higher_val = ((duty_ns & 0x0300) >> 8);
49 reg = AB8500_PWM_OUT_CTRL1_REG + ((chip->base - 1) * 2);
51 ret = abx500_set_register_interruptible(chip->dev, AB8500_MISC,
55 ret = abx500_set_register_interruptible(chip->dev, AB8500_MISC,
56 (reg + 1), (u8)higher_val);
61 static int ab8500_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
65 ret = abx500_mask_and_set_register_interruptible(chip->dev,
66 AB8500_MISC, AB8500_PWM_OUT_CTRL7_REG,
67 1 << (chip->base - 1), ENABLE_PWM);
69 dev_err(chip->dev, "%s: Failed to disable PWM, Error %d\n",
74 static void ab8500_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
78 ret = abx500_mask_and_set_register_interruptible(chip->dev,
79 AB8500_MISC, AB8500_PWM_OUT_CTRL7_REG,
80 1 << (chip->base - 1), DISABLE_PWM);
82 dev_err(chip->dev, "%s: Failed to disable PWM, Error %d\n",
87 static const struct pwm_ops ab8500_pwm_ops = {
88 .config = ab8500_pwm_config,
89 .enable = ab8500_pwm_enable,
90 .disable = ab8500_pwm_disable,
93 static int ab8500_pwm_probe(struct platform_device *pdev)
95 struct ab8500_pwm_chip *ab8500;
99 * Nothing to be done in probe, this is required to get the
100 * device which is required for ab8500 read and write
102 ab8500 = kzalloc(sizeof(*ab8500), GFP_KERNEL);
103 if (ab8500 == NULL) {
104 dev_err(&pdev->dev, "failed to allocate memory\n");
108 ab8500->chip.dev = &pdev->dev;
109 ab8500->chip.ops = &ab8500_pwm_ops;
110 ab8500->chip.base = pdev->id;
111 ab8500->chip.npwm = 1;
113 err = pwmchip_add(&ab8500->chip);
119 dev_dbg(&pdev->dev, "pwm probe successful\n");
120 platform_set_drvdata(pdev, ab8500);
125 static int ab8500_pwm_remove(struct platform_device *pdev)
127 struct ab8500_pwm_chip *ab8500 = platform_get_drvdata(pdev);
130 err = pwmchip_remove(&ab8500->chip);
134 dev_dbg(&pdev->dev, "pwm driver removed\n");
140 static struct platform_driver ab8500_pwm_driver = {
142 .name = "ab8500-pwm",
143 .owner = THIS_MODULE,
145 .probe = ab8500_pwm_probe,
146 .remove = ab8500_pwm_remove,
148 module_platform_driver(ab8500_pwm_driver);
150 MODULE_AUTHOR("Arun MURTHY <arun.murthy@stericsson.com>");
151 MODULE_DESCRIPTION("AB8500 Pulse Width Modulation Driver");
152 MODULE_ALIAS("platform:ab8500-pwm");
153 MODULE_LICENSE("GPL v2");