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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
/*
* Copyright 2008-2009 Freescale Semiconductor, Inc. All Rights Reserved
* Copyright 2010 Digi International, 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
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/console.h>
#include <linux/delay.h>
#include <linux/errno.h>
#include <linux/fb.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/mxcfb.h>
#include <mach/hardware.h>
#include <mach/mxc.h>
#define MAX_DISPLAYS 2
#define DISP0_ID "DISP3 BG"
#define DISP1_ID "DISP3 BG - DI1"
static void lcd_poweron(struct ccwmx51_lcd_pdata *plat);
static void lcd_poweroff(struct ccwmx51_lcd_pdata *plat);
static struct platform_device *plcd_dev[MAX_DISPLAYS] = {NULL, NULL};
static int lcd_get_index(struct fb_info *info)
{
if (!strcmp(info->fix.id, DISP0_ID))
return 0;
else if (!strcmp(info->fix.id, DISP1_ID))
return 1;
return -1;
}
static void lcd_init_fb(struct fb_info *info)
{
struct fb_var_screeninfo var;
struct ccwmx51_lcd_pdata *plat;
int i = lcd_get_index(info);
if (i < 0)
return;
plat = plcd_dev[i]->dev.platform_data;
memset(&var, 0, sizeof(var));
fb_videomode_to_var(&var, plat->fb_pdata.mode);
var.activate = FB_ACTIVATE_ALL;
acquire_console_sem();
info->flags |= FBINFO_MISC_USEREVENT;
fb_set_var(info, &var);
info->flags &= ~FBINFO_MISC_USEREVENT;
release_console_sem();
}
static int lcd_fb_event(struct notifier_block *nb, unsigned long val, void *v)
{
struct fb_event *event = v;
struct ccwmx51_lcd_pdata *plat = event->info->dev->platform_data;
switch (val) {
case FB_EVENT_FB_REGISTERED:
lcd_init_fb(event->info);
lcd_poweron(plat);
break;
case FB_EVENT_BLANK:
if (*((int *)event->data) == FB_BLANK_UNBLANK) {
lcd_poweron(plat);
} else {
lcd_poweroff(plat);
}
break;
}
return 0;
}
static struct notifier_block nb = {
.notifier_call = lcd_fb_event,
};
static int __devinit lcd_sync_probe(struct platform_device *pdev)
{
struct ccwmx51_lcd_pdata *plat = pdev->dev.platform_data;
int i;
if (!plat)
return -ENODEV;
if (plat->vif < 0 || plat->vif > (MAX_DISPLAYS - 1))
return -EINVAL;
if (plat->init)
plat->init(plat->vif);
plcd_dev[plat->vif] = pdev;
for (i = 0; i < num_registered_fb; i++) {
if ((!strcmp(registered_fb[i]->fix.id, DISP0_ID) && plat->vif == 0) ||
(!strcmp(registered_fb[i]->fix.id, DISP1_ID) && plat->vif == 1)) {
lcd_init_fb(registered_fb[i]);
/* Clear the screen */
memset((char *)registered_fb[i]->screen_base, 0,
registered_fb[i]->fix.smem_len);
fb_show_logo(registered_fb[i], 0);
}
}
/**
* Register the block notifier only once. The device being notified can be
* retrieved from the received event. There are some issues when the same
* notifier is registered multiple times.
*/
if (plcd_dev[0] == NULL && plcd_dev[1] == NULL)
fb_register_client(&nb);
lcd_poweron(plat);
return 0;
}
static int __devexit lcd_sync_remove(struct platform_device *pdev)
{
struct ccwmx51_lcd_pdata *plat = pdev->dev.platform_data;
lcd_poweroff(plat);
if (plat->deinit)
plat->deinit(plat->vif);
plcd_dev[plat->vif] = NULL;
if (plcd_dev[0] == NULL && plcd_dev[1] == NULL)
fb_unregister_client(&nb);
return 0;
}
#ifdef CONFIG_PM
static int lcd_sync_suspend(struct platform_device *pdev, pm_message_t state)
{
return 0;
}
static int lcd_sync_resume(struct platform_device *pdev)
{
return 0;
}
#else
#define lcd_sync_suspend NULL
#define lcd_sync_resume NULL
#endif
static struct platform_driver lcd_driver = {
.driver = {
.name = "ccwmx51_display"
},
.probe = lcd_sync_probe,
.remove = __devexit_p(lcd_sync_remove),
.suspend = lcd_sync_suspend,
.resume = lcd_sync_resume,
};
static void lcd_poweron(struct ccwmx51_lcd_pdata *plat)
{
if (plat && plat->bl_enable)
plat->bl_enable(1, plat->vif);
}
static void lcd_poweroff(struct ccwmx51_lcd_pdata *plat)
{
if (plat && plat->bl_enable)
plat->bl_enable(0, plat->vif);
}
static int __init lcd_sync_init(void)
{
return platform_driver_register(&lcd_driver);
}
static void __exit lcd_sync_exit(void)
{
platform_driver_unregister(&lcd_driver);
}
module_init(lcd_sync_init);
module_exit(lcd_sync_exit);
MODULE_AUTHOR("Digi International, Inc.");
MODULE_DESCRIPTION("ConnectCore Wi-i.MX51 LCD init driver");
MODULE_LICENSE("GPL");
|