aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/video/backlight/atmel-pwm-bl.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/video/backlight/atmel-pwm-bl.c')
-rw-r--r--drivers/video/backlight/atmel-pwm-bl.c223
1 files changed, 0 insertions, 223 deletions
diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
deleted file mode 100644
index 261b1a4ec3d8..000000000000
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ /dev/null
@@ -1,223 +0,0 @@
1/*
2 * Copyright (C) 2008 Atmel Corporation
3 *
4 * Backlight driver using Atmel PWM peripheral.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
9 */
10#include <linux/init.h>
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/platform_device.h>
14#include <linux/fb.h>
15#include <linux/gpio.h>
16#include <linux/backlight.h>
17#include <linux/atmel_pwm.h>
18#include <linux/atmel-pwm-bl.h>
19#include <linux/slab.h>
20
21struct atmel_pwm_bl {
22 const struct atmel_pwm_bl_platform_data *pdata;
23 struct backlight_device *bldev;
24 struct platform_device *pdev;
25 struct pwm_channel pwmc;
26 int gpio_on;
27};
28
29static void atmel_pwm_bl_set_gpio_on(struct atmel_pwm_bl *pwmbl, int on)
30{
31 if (!gpio_is_valid(pwmbl->gpio_on))
32 return;
33
34 gpio_set_value(pwmbl->gpio_on, on ^ pwmbl->pdata->on_active_low);
35}
36
37static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
38{
39 struct atmel_pwm_bl *pwmbl = bl_get_data(bd);
40 int intensity = bd->props.brightness;
41 int pwm_duty;
42
43 if (bd->props.power != FB_BLANK_UNBLANK)
44 intensity = 0;
45 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
46 intensity = 0;
47
48 if (pwmbl->pdata->pwm_active_low)
49 pwm_duty = pwmbl->pdata->pwm_duty_min + intensity;
50 else
51 pwm_duty = pwmbl->pdata->pwm_duty_max - intensity;
52
53 if (pwm_duty > pwmbl->pdata->pwm_duty_max)
54 pwm_duty = pwmbl->pdata->pwm_duty_max;
55 if (pwm_duty < pwmbl->pdata->pwm_duty_min)
56 pwm_duty = pwmbl->pdata->pwm_duty_min;
57
58 if (!intensity) {
59 atmel_pwm_bl_set_gpio_on(pwmbl, 0);
60 pwm_channel_writel(&pwmbl->pwmc, PWM_CUPD, pwm_duty);
61 pwm_channel_disable(&pwmbl->pwmc);
62 } else {
63 pwm_channel_enable(&pwmbl->pwmc);
64 pwm_channel_writel(&pwmbl->pwmc, PWM_CUPD, pwm_duty);
65 atmel_pwm_bl_set_gpio_on(pwmbl, 1);
66 }
67
68 return 0;
69}
70
71static int atmel_pwm_bl_get_intensity(struct backlight_device *bd)
72{
73 struct atmel_pwm_bl *pwmbl = bl_get_data(bd);
74 u32 cdty;
75 u32 intensity;
76
77 cdty = pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY);
78 if (pwmbl->pdata->pwm_active_low)
79 intensity = cdty - pwmbl->pdata->pwm_duty_min;
80 else
81 intensity = pwmbl->pdata->pwm_duty_max - cdty;
82
83 return intensity & 0xffff;
84}
85
86static int atmel_pwm_bl_init_pwm(struct atmel_pwm_bl *pwmbl)
87{
88 unsigned long pwm_rate = pwmbl->pwmc.mck;
89 unsigned long prescale = DIV_ROUND_UP(pwm_rate,
90 (pwmbl->pdata->pwm_frequency *
91 pwmbl->pdata->pwm_compare_max)) - 1;
92
93 /*
94 * Prescale must be power of two and maximum 0xf in size because of
95 * hardware limit. PWM speed will be:
96 * PWM module clock speed / (2 ^ prescale).
97 */
98 prescale = fls(prescale);
99 if (prescale > 0xf)
100 prescale = 0xf;
101
102 pwm_channel_writel(&pwmbl->pwmc, PWM_CMR, prescale);
103 pwm_channel_writel(&pwmbl->pwmc, PWM_CDTY,
104 pwmbl->pdata->pwm_duty_min +
105 pwmbl->bldev->props.brightness);
106 pwm_channel_writel(&pwmbl->pwmc, PWM_CPRD,
107 pwmbl->pdata->pwm_compare_max);
108
109 dev_info(&pwmbl->pdev->dev, "Atmel PWM backlight driver (%lu Hz)\n",
110 pwmbl->pwmc.mck / pwmbl->pdata->pwm_compare_max /
111 (1 << prescale));
112
113 return pwm_channel_enable(&pwmbl->pwmc);
114}
115
116static const struct backlight_ops atmel_pwm_bl_ops = {
117 .get_brightness = atmel_pwm_bl_get_intensity,
118 .update_status = atmel_pwm_bl_set_intensity,
119};
120
121static int atmel_pwm_bl_probe(struct platform_device *pdev)
122{
123 struct backlight_properties props;
124 const struct atmel_pwm_bl_platform_data *pdata;
125 struct backlight_device *bldev;
126 struct atmel_pwm_bl *pwmbl;
127 unsigned long flags;
128 int retval;
129
130 pdata = dev_get_platdata(&pdev->dev);
131 if (!pdata)
132 return -ENODEV;
133
134 if (pdata->pwm_compare_max < pdata->pwm_duty_max ||
135 pdata->pwm_duty_min > pdata->pwm_duty_max ||
136 pdata->pwm_frequency == 0)
137 return -EINVAL;
138
139 pwmbl = devm_kzalloc(&pdev->dev, sizeof(struct atmel_pwm_bl),
140 GFP_KERNEL);
141 if (!pwmbl)
142 return -ENOMEM;
143
144 pwmbl->pdev = pdev;
145 pwmbl->pdata = pdata;
146 pwmbl->gpio_on = pdata->gpio_on;
147
148 retval = pwm_channel_alloc(pdata->pwm_channel, &pwmbl->pwmc);
149 if (retval)
150 return retval;
151
152 if (gpio_is_valid(pwmbl->gpio_on)) {
153 /* Turn display off by default. */
154 if (pdata->on_active_low)
155 flags = GPIOF_OUT_INIT_HIGH;
156 else
157 flags = GPIOF_OUT_INIT_LOW;
158
159 retval = devm_gpio_request_one(&pdev->dev, pwmbl->gpio_on,
160 flags, "gpio_atmel_pwm_bl");
161 if (retval)
162 goto err_free_pwm;
163 }
164
165 memset(&props, 0, sizeof(struct backlight_properties));
166 props.type = BACKLIGHT_RAW;
167 props.max_brightness = pdata->pwm_duty_max - pdata->pwm_duty_min;
168 bldev = devm_backlight_device_register(&pdev->dev, "atmel-pwm-bl",
169 &pdev->dev, pwmbl, &atmel_pwm_bl_ops,
170 &props);
171 if (IS_ERR(bldev)) {
172 retval = PTR_ERR(bldev);
173 goto err_free_pwm;
174 }
175
176 pwmbl->bldev = bldev;
177
178 platform_set_drvdata(pdev, pwmbl);
179
180 /* Power up the backlight by default at middle intesity. */
181 bldev->props.power = FB_BLANK_UNBLANK;
182 bldev->props.brightness = bldev->props.max_brightness / 2;
183
184 retval = atmel_pwm_bl_init_pwm(pwmbl);
185 if (retval)
186 goto err_free_pwm;
187
188 atmel_pwm_bl_set_intensity(bldev);
189
190 return 0;
191
192err_free_pwm:
193 pwm_channel_free(&pwmbl->pwmc);
194
195 return retval;
196}
197
198static int atmel_pwm_bl_remove(struct platform_device *pdev)
199{
200 struct atmel_pwm_bl *pwmbl = platform_get_drvdata(pdev);
201
202 atmel_pwm_bl_set_gpio_on(pwmbl, 0);
203 pwm_channel_disable(&pwmbl->pwmc);
204 pwm_channel_free(&pwmbl->pwmc);
205
206 return 0;
207}
208
209static struct platform_driver atmel_pwm_bl_driver = {
210 .driver = {
211 .name = "atmel-pwm-bl",
212 },
213 /* REVISIT add suspend() and resume() */
214 .probe = atmel_pwm_bl_probe,
215 .remove = atmel_pwm_bl_remove,
216};
217
218module_platform_driver(atmel_pwm_bl_driver);
219
220MODULE_AUTHOR("Hans-Christian egtvedt <hans-christian.egtvedt@atmel.com>");
221MODULE_DESCRIPTION("Atmel PWM backlight driver");
222MODULE_LICENSE("GPL");
223MODULE_ALIAS("platform:atmel-pwm-bl");