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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
|
/*
* Copyright 2009 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 Framebuffer Framebuffer Driver for SDC and ADC.
*/
/*!
* @file mxcfb_epson_vga.c
*
* @brief MXC Frame buffer driver for SDC
*
* @ingroup Framebuffer
*/
/*!
* Include files
*/
#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/regulator/consumer.h>
#include <linux/i2c.h>
#include <linux/mxcfb.h>
#include <linux/ipu.h>
static struct i2c_client *ch7026_client;
static int lcd_init(void);
static void lcd_poweron(struct fb_info *info);
static void lcd_poweroff(void);
static void (*lcd_reset) (void);
static struct regulator *io_reg;
static struct regulator *core_reg;
static struct regulator *analog_reg;
/* 8 800x600-60 VESA */
static struct fb_videomode mode = {
NULL, 60, 800, 600, 25000, 88, 40, 23, 1, 128, 4,
FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA
};
static void lcd_init_fb(struct fb_info *info)
{
struct fb_var_screeninfo var;
memset(&var, 0, sizeof(var));
fb_videomode_to_var(&var, &mode);
var.activate = FB_ACTIVATE_ALL;
acquire_console_sem();
info->flags |= FBINFO_MISC_USEREVENT;
fb_set_var(info, &var);
fb_blank(info, FB_BLANK_UNBLANK);
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;
if (strcmp(event->info->fix.id, "DISP3 BG - DI1"))
return 0;
switch (val) {
case FB_EVENT_FB_REGISTERED:
lcd_init_fb(event->info);
lcd_poweron(event->info);
break;
case FB_EVENT_BLANK:
if (*((int *)event->data) == FB_BLANK_UNBLANK)
lcd_poweron(event->info);
else
lcd_poweroff();
break;
}
return 0;
}
static struct notifier_block nb = {
.notifier_call = lcd_fb_event,
};
/*!
* This function is called whenever the SPI slave device is detected.
*
* @param spi the SPI slave device
*
* @return Returns 0 on SUCCESS and error on FAILURE.
*/
static int __devinit lcd_probe(struct device *dev)
{
int ret = 0;
int i;
struct mxc_lcd_platform_data *plat = dev->platform_data;
if (plat) {
io_reg = regulator_get(dev, plat->io_reg);
if (!IS_ERR(io_reg)) {
regulator_set_voltage(io_reg, 1800000, 1800000);
regulator_enable(io_reg);
} else {
io_reg = NULL;
}
core_reg = regulator_get(dev, plat->core_reg);
if (!IS_ERR(core_reg)) {
regulator_set_voltage(core_reg, 2500000, 2500000);
regulator_enable(core_reg);
} else {
core_reg = NULL;
}
analog_reg = regulator_get(dev, plat->analog_reg);
if (!IS_ERR(analog_reg)) {
regulator_set_voltage(analog_reg, 2775000, 2775000);
regulator_enable(analog_reg);
} else {
analog_reg = NULL;
}
msleep(100);
lcd_reset = plat->reset;
if (lcd_reset)
lcd_reset();
}
for (i = 0; i < num_registered_fb; i++) {
if (strcmp(registered_fb[i]->fix.id, "DISP3 BG - DI1") == 0) {
ret = lcd_init();
if (ret < 0)
goto err;
lcd_init_fb(registered_fb[i]);
fb_show_logo(registered_fb[i], 0);
lcd_poweron(registered_fb[i]);
}
}
fb_register_client(&nb);
return 0;
err:
if (io_reg)
regulator_disable(io_reg);
if (core_reg)
regulator_disable(core_reg);
if (analog_reg)
regulator_disable(analog_reg);
return ret;
}
static int __devinit ch7026_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
int id_reg;
ch7026_client = client;
return lcd_probe(&client->dev);
}
static int __devexit ch7026_remove(struct i2c_client *client)
{
fb_unregister_client(&nb);
lcd_poweroff();
regulator_put(io_reg);
regulator_put(core_reg);
regulator_put(analog_reg);
return 0;
}
static int ch7026_suspend(struct i2c_client *client, pm_message_t message)
{
return 0;
}
static int ch7026_resume(struct i2c_client *client)
{
return 0;
}
u8 reg_init[][2] = {
{ 0x02, 0x01 },
{ 0x02, 0x03 },
{ 0x03, 0x00 },
{ 0x06, 0x6B },
{ 0x08, 0x08 },
{ 0x09, 0x80 },
{ 0x0C, 0x0A },
{ 0x0D, 0x89 },
{ 0x0F, 0x23 },
{ 0x10, 0x20 },
{ 0x11, 0x20 },
{ 0x12, 0x40 },
{ 0x13, 0x28 },
{ 0x14, 0x80 },
{ 0x15, 0x52 },
{ 0x16, 0x58 },
{ 0x17, 0x74 },
{ 0x19, 0x01 },
{ 0x1A, 0x04 },
{ 0x1B, 0x23 },
{ 0x1C, 0x20 },
{ 0x1D, 0x20 },
{ 0x1F, 0x28 },
{ 0x20, 0x80 },
{ 0x21, 0x12 },
{ 0x22, 0x58 },
{ 0x23, 0x74 },
{ 0x25, 0x01 },
{ 0x26, 0x04 },
{ 0x37, 0x20 },
{ 0x39, 0x20 },
{ 0x3B, 0x20 },
{ 0x41, 0xA2 },
{ 0x4D, 0x03 },
{ 0x4E, 0x13 },
{ 0x4F, 0xB1 },
{ 0x50, 0x3B },
{ 0x51, 0x54 },
{ 0x52, 0x12 },
{ 0x53, 0x13 },
{ 0x55, 0xE5 },
{ 0x5E, 0x80 },
{ 0x69, 0x64 },
{ 0x7D, 0x62 },
{ 0x04, 0x00 },
{ 0x06, 0x69 },
/*
NOTE: The following five repeated sentences are used here to wait memory initial complete, please don't remove...(you could refer to Appendix A of programming guide document (CH7025(26)B Programming Guide Rev2.03.pdf) for detailed information about memory initialization!
*/
{ 0x03, 0x00 },
{ 0x03, 0x00 },
{ 0x03, 0x00 },
{ 0x03, 0x00 },
{ 0x03, 0x00 },
{ 0x06, 0x68 },
{ 0x02, 0x02 },
{ 0x02, 0x03 },
};
#define REGMAP_LENGTH (sizeof(reg_init) / (2*sizeof(u8)))
/*
* Send init commands to L4F00242T03
*
*/
static int lcd_init(void)
{
int i;
int dat;
dev_dbg(&ch7026_client->dev, "initializing CH7026\n");
/* read device ID */
msleep(100);
dat = i2c_smbus_read_byte_data(ch7026_client, 0x00);
dev_dbg(&ch7026_client->dev, "read id = 0x%02X\n", dat);
if (dat != 0x54)
return -ENODEV;
for (i = 0; i < REGMAP_LENGTH; ++i) {
if (i2c_smbus_write_byte_data
(ch7026_client, reg_init[i][0], reg_init[i][1]) < 0)
return -EIO;
}
return 0;
}
static int lcd_on;
/*
* Send Power On commands to L4F00242T03
*
*/
static void lcd_poweron(struct fb_info *info)
{
u16 data[4];
u32 refresh;
if (lcd_on)
return;
dev_dbg(&ch7026_client->dev, "turning on LCD\n");
data[0] = PICOS2KHZ(info->var.pixclock) / 10;
data[2] = info->var.hsync_len + info->var.left_margin +
info->var.xres + info->var.right_margin;
data[3] = info->var.vsync_len + info->var.upper_margin +
info->var.yres + info->var.lower_margin;
refresh = data[2] * data[3];
refresh = (PICOS2KHZ(info->var.pixclock) * 1000) / refresh;
data[1] = refresh * 100;
lcd_on = 1;
}
/*
* Send Power Off commands to L4F00242T03
*
*/
static void lcd_poweroff(void)
{
if (!lcd_on)
return;
dev_dbg(&ch7026_client->dev, "turning off LCD\n");
lcd_on = 0;
}
static const struct i2c_device_id ch7026_id[] = {
{"ch7026", 0},
{},
};
MODULE_DEVICE_TABLE(i2c, ch7026_id);
static struct i2c_driver ch7026_driver = {
.driver = {
.name = "ch7026",
},
.probe = ch7026_probe,
.remove = ch7026_remove,
.suspend = ch7026_suspend,
.resume = ch7026_resume,
.id_table = ch7026_id,
};
static int __init ch7026_init(void)
{
return i2c_add_driver(&ch7026_driver);
}
static void __exit ch7026_exit(void)
{
i2c_del_driver(&ch7026_driver);
}
module_init(ch7026_init);
module_exit(ch7026_exit);
MODULE_AUTHOR("Freescale Semiconductor, Inc.");
MODULE_DESCRIPTION("CH7026 VGA driver");
MODULE_LICENSE("GPL");
|