1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
/*
* Copyright 2007-2010 Freescale Semiconductor, Inc. All Rights Reserved.
*/
/*
* The code contained herein is licensed under the GNU General Public
* License. You may obtain a copy of the GNU General Public License
* Version 2 or later at the following locations:
*
* http://www.opensource.org/licenses/gpl-license.html
* http://www.gnu.org/copyleft/gpl.html
*/
/*!
* @defgroup IPU_BL MXC IPU Backlight Driver
*/
/*!
* @file mxc_ipu_bl.c
*
* @brief Backlight Driver for IPU PWM on Freescale MXC/i.MX platforms.
*
* This file contains API defined in include/linux/clk.h for setting up and
* retrieving clocks.
*
* Based on Sharp's Corgi Backlight Driver
*
* @ingroup IPU_BL
*/
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/spinlock.h>
#include <linux/fb.h>
#include <linux/backlight.h>
#include <linux/ipu.h>
#define MXC_MAX_INTENSITY 255
#define MXC_DEFAULT_INTENSITY 127
#define MXC_INTENSITY_OFF 0
struct mxcbl_dev_data {
int intensity;
};
static int fb_id;
static int mxcbl_send_intensity(struct backlight_device *bd)
{
int intensity = bd->props.brightness;
struct mxcbl_dev_data *devdata = dev_get_drvdata(&bd->dev);
if (bd->props.power != FB_BLANK_UNBLANK)
intensity = 0;
if (bd->props.fb_blank != FB_BLANK_UNBLANK)
intensity = 0;
ipu_sdc_set_brightness(intensity);
devdata->intensity = intensity;
return 0;
}
static int mxcbl_get_intensity(struct backlight_device *bd)
{
struct mxcbl_dev_data *devdata = dev_get_drvdata(&bd->dev);
return devdata->intensity;
}
static int mxcbl_check_fb(struct backlight_device *bldev, struct fb_info *info)
{
int id = info->fix.id[4] - '0';
if (id == fb_id) {
if ((id == 3) && !strcmp(info->fix.id, "DISP3 FG")) {
return 0;
}
return 1;
}
return 0;
}
static struct backlight_ops mxcbl_ops = {
.get_brightness = mxcbl_get_intensity,
.update_status = mxcbl_send_intensity,
.check_fb = mxcbl_check_fb,
};
static int __init mxcbl_probe(struct platform_device *pdev)
{
struct backlight_device *bd;
struct mxcbl_dev_data *devdata;
struct backlight_properties props;
int ret = 0;
devdata = kzalloc(sizeof(struct mxcbl_dev_data), GFP_KERNEL);
if (!devdata)
return -ENOMEM;
fb_id = (int)pdev->dev.platform_data;
memset(&props, 0, sizeof(struct backlight_properties));
props.max_brightness = MXC_MAX_INTENSITY;
bd = backlight_device_register(dev_name(&pdev->dev), &pdev->dev, devdata,
&mxcbl_ops, &props);
if (IS_ERR(bd)) {
ret = PTR_ERR(bd);
goto err0;
}
platform_set_drvdata(pdev, bd);
bd->props.brightness = MXC_DEFAULT_INTENSITY;
bd->props.power = FB_BLANK_UNBLANK;
bd->props.fb_blank = FB_BLANK_UNBLANK;
backlight_update_status(bd);
printk("MXC Backlight Device %s Initialized.\n", dev_name(&pdev->dev));
return 0;
err0:
kfree(devdata);
return ret;
}
static int mxcbl_remove(struct platform_device *pdev)
{
struct backlight_device *bd = platform_get_drvdata(pdev);
bd->props.brightness = MXC_INTENSITY_OFF;
backlight_update_status(bd);
backlight_device_unregister(bd);
return 0;
}
static struct platform_driver mxcbl_driver = {
.probe = mxcbl_probe,
.remove = mxcbl_remove,
.driver = {
.name = "mxc_ipu_bl",
},
};
static int __init mxcbl_init(void)
{
return platform_driver_register(&mxcbl_driver);
}
static void __exit mxcbl_exit(void)
{
platform_driver_unregister(&mxcbl_driver);
}
late_initcall(mxcbl_init);
module_exit(mxcbl_exit);
MODULE_DESCRIPTION("Freescale MXC/i.MX IPU PWM Backlight Driver");
MODULE_AUTHOR("Freescale Semiconductor, Inc.");
MODULE_LICENSE("GPL");
|