4 * Driver for rockchip rk1000 tv control
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
14 #include <linux/module.h>
15 #include <linux/device.h>
16 #include <linux/i2c.h>
17 #include <linux/delay.h>
18 #include <linux/fcntl.h>
21 #include <linux/rk_fb.h>
24 #include <linux/of_gpio.h>
25 #include <dt-bindings/rkfb/rk_fb.h>
27 #include "rk1000_tve.h"
29 struct rk1000_tve rk1000_tve;
32 int rk1000_tv_write_block(u8 reg, u8 *buf, u8 len)
36 for (i = 0; i < len; i++) {
37 ret = rk1000_i2c_send(I2C_ADDR_TVE, reg + i, buf[i]);
44 int rk1000_control_write_block(u8 reg, u8 *buf, u8 len)
49 for (i = 0; i < len; i++) {
50 ret = rk1000_i2c_send(I2C_ADDR_CTRL, reg + i, buf[i]);
57 static int __init bootloader_rk1000_setup(char *str)
60 pr_info("cvbs init tve.format is %s\n", str);
61 if (kstrtoint(str, 0, &cvbsformat) < 0)
67 early_param("tve.format", bootloader_rk1000_setup);
69 int rk1000_switch_fb(const struct fb_videomode *modedb, int tv_mode)
71 struct rk_screen *screen;
75 screen = kzalloc(sizeof(*screen), GFP_KERNEL);
78 memset(screen, 0, sizeof(*screen));
79 /* screen type & face */
80 screen->type = SCREEN_RGB;
81 screen->face = OUT_P888;
82 screen->mode = *modedb;
83 screen->mode.vmode = 0;
85 if (FB_SYNC_HOR_HIGH_ACT & modedb->sync)
86 screen->pin_hsync = 1;
88 screen->pin_hsync = 0;
89 if (FB_SYNC_VERT_HIGH_ACT & modedb->sync)
90 screen->pin_vsync = 1;
92 screen->pin_vsync = 0;
99 screen->swap_delta = 0;
100 screen->swap_dumy = 0;
101 screen->overscan.left = 95;
102 screen->overscan.top = 95;
103 screen->overscan.right = 95;
104 screen->overscan.bottom = 95;
105 /* Operation function*/
107 screen->standby = NULL;
109 #ifdef CONFIG_RK1000_TVOUT_CVBS
110 case TVOUT_CVBS_NTSC:
111 screen->init = rk1000_tv_ntsc_init;
114 screen->init = rk1000_tv_pal_init;
117 #ifdef CONFIG_RK1000_TVOUT_YPBPR
118 case TVOUT_YPBPR_720X480P_60:
119 screen->init = rk1000_tv_ypbpr480_init;
121 case TVOUT_YPBPR_720X576P_50:
122 screen->init = rk1000_tv_ypbpr576_init;
124 case TVOUT_YPBPR_1280X720P_50:
125 screen->init = rk1000_tv_ypbpr720_50_init;
127 case TVOUT_YPBPR_1280X720P_60:
128 screen->init = rk1000_tv_ypbpr720_60_init;
135 rk_fb_switch_screen(screen, 1 , rk1000_tve.video_source);
136 rk1000_tve.mode = tv_mode;
138 if (gpio_is_valid(rk1000_tve.io_switch.gpio)) {
139 if (tv_mode < TVOUT_YPBPR_720X480P_60)
140 gpio_direction_output(rk1000_tve.io_switch.gpio,
141 !(rk1000_tve.io_switch.active));
143 gpio_direction_output(rk1000_tve.io_switch.gpio,
144 rk1000_tve.io_switch.active);
149 int rk1000_tv_standby(int type)
155 struct rk_screen screen;
159 if (rk1000_tve.ypbpr)
160 ypbpr = rk1000_tve.ypbpr->enable;
162 cvbs = rk1000_tve.cvbs->enable;
166 ret = rk1000_control_write_block(0x03, &val, 1);
168 pr_err("rk1000_control_write_block err!\n");
172 ret = rk1000_tv_write_block(0x03, &val, 1);
174 pr_err("rk1000_tv_write_block err!\n");
177 screen.type = SCREEN_RGB;
178 rk_fb_switch_screen(&screen, 0 , rk1000_tve.video_source);
179 pr_err("rk1000 tve standby\n");
183 static int rk1000_tve_initial(void)
185 struct rk_screen screen;
187 /* RK1000 tvencoder i2c reg need dclk, so we open lcdc.*/
188 memset(&screen, 0, sizeof(struct rk_screen));
189 /* screen type & face */
190 screen.type = SCREEN_RGB;
191 screen.face = OUT_P888;
193 screen.mode.xres = 720;
194 screen.mode.yres = 480;
196 screen.mode.pixclock = 27000000;
197 screen.mode.refresh = 60;
198 screen.mode.left_margin = 116;
199 screen.mode.right_margin = 16;
200 screen.mode.hsync_len = 6;
201 screen.mode.upper_margin = 25;
202 screen.mode.lower_margin = 14;
203 screen.mode.vsync_len = 6;
204 rk_fb_switch_screen(&screen, 2 , rk1000_tve.video_source);
205 /* Power down RK1000 output DAC. */
207 return rk1000_i2c_send(I2C_ADDR_TVE, 0x03, 0x07);
213 static void rk1000_early_suspend(void *h)
215 pr_info("rk1000_early_suspend\n");
216 if (rk1000_tve.ypbpr) {
217 if (rk1000_tve.ypbpr->enable)
218 rk1000_tve.ypbpr->ddev->ops->setenable(
219 rk1000_tve.ypbpr->ddev, 0);
220 if (!rk1000_tve.ypbpr->suspend)
221 rk1000_tve.ypbpr->suspend = 1;
223 if (rk1000_tve.cvbs) {
224 if (rk1000_tve.cvbs->enable)
225 rk1000_tve.cvbs->ddev->ops->setenable(
226 rk1000_tve.cvbs->ddev, 0);
227 if (!rk1000_tve.cvbs->suspend)
228 rk1000_tve.cvbs->suspend = 1;
233 static void rk1000_early_resume(void *h)
235 pr_info("rk1000 tve exit early resume\n");
236 if (rk1000_tve.cvbs) {
237 if (rk1000_tve.cvbs->suspend)
238 rk1000_tve.cvbs->suspend = 0;
239 if (rk1000_tve.mode < TVOUT_YPBPR_720X480P_60) {
240 rk_display_device_enable(
241 (rk1000_tve.cvbs)->ddev);
244 if (rk1000_tve.ypbpr) {
245 if (rk1000_tve.ypbpr->suspend)
246 rk1000_tve.ypbpr->suspend = 0;
247 if (rk1000_tve.mode > TVOUT_CVBS_PAL) {
248 rk_display_device_enable(
249 (rk1000_tve.ypbpr)->ddev);
255 static int rk1000_fb_event_notify(struct notifier_block *self,
256 unsigned long action, void *data)
258 struct fb_event *event;
261 if (action == FB_EARLY_EVENT_BLANK) {
262 switch (*((int *)event->data)) {
263 case FB_BLANK_UNBLANK:
266 rk1000_early_suspend(NULL);
269 } else if (action == FB_EVENT_BLANK) {
270 switch (*((int *)event->data)) {
271 case FB_BLANK_UNBLANK:
272 rk1000_early_resume(NULL);
281 static struct notifier_block rk1000_fb_notifier = {
282 .notifier_call = rk1000_fb_event_notify,
285 static int rk1000_tve_probe(struct i2c_client *client,
286 const struct i2c_device_id *id)
288 struct device_node *tve_np;
289 enum of_gpio_flags flags;
292 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
295 memset(&rk1000_tve, 0, sizeof(struct rk1000_tve));
296 rk1000_tve.client = client;
298 tve_np = client->dev.of_node;
299 rk1000_tve.io_switch.gpio = of_get_named_gpio_flags(tve_np,
302 if (gpio_is_valid(rk1000_tve.io_switch.gpio)) {
303 rc = gpio_request(rk1000_tve.io_switch.gpio,
304 "rk1000-tve-swicth-io");
306 rk1000_tve.io_switch.active = !(flags &
308 gpio_direction_output(rk1000_tve.io_switch.gpio,
309 !(rk1000_tve.io_switch.active));
311 pr_err("gpio request rk1000-tve-swicth-io err: %d\n",
312 rk1000_tve.io_switch.gpio);
314 of_property_read_u32(tve_np, "rockchip,source", &(rc));
315 rk1000_tve.video_source = rc;
316 of_property_read_u32(tve_np, "rockchip,prop", &(rc));
317 rk1000_tve.property = rc - 1;
318 pr_err("video src is lcdc%d, prop is %d\n", rk1000_tve.video_source,
319 rk1000_tve.property);
321 if (cvbsformat >= 0) {
322 rk1000_tve.mode = cvbsformat + 1;
324 rk1000_tve.mode = RK1000_TVOUT_DEAULT;
325 rc = rk1000_tve_initial();
327 dev_err(&client->dev,
328 "rk1000 tvencoder probe error %d\n", rc);
333 #ifdef CONFIG_RK1000_TVOUT_YPBPR
334 rk1000_register_display_ypbpr(&client->dev);
337 #ifdef CONFIG_RK1000_TVOUT_CVBS
338 rk1000_register_display_cvbs(&client->dev);
340 #ifdef CONFIG_HAS_EARLYSUSPEND
341 rk1000_tve.early_suspend.suspend = rk1000_early_suspend;
342 rk1000_tve.early_suspend.resume = rk1000_early_resume;
343 rk1000_tve.early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB - 11;
344 register_early_suspend(&(rk1000_tve.early_suspend));
346 fb_register_client(&rk1000_fb_notifier);
347 pr_info("rk1000 tvencoder ver 2.0 probe ok\n");
351 static int rk1000_tve_remove(struct i2c_client *client)
356 static void rk1000_tve_shutdown(struct i2c_client *client)
358 rk1000_i2c_send(I2C_ADDR_TVE, 0x03, 0x07);
361 static const struct i2c_device_id rk1000_tve_id[] = {
365 MODULE_DEVICE_TABLE(i2c, rk1000_tve_id);
367 static struct i2c_driver rk1000_tve_driver = {
369 .name = "rk1000_tve",
371 .id_table = rk1000_tve_id,
372 .probe = rk1000_tve_probe,
373 .remove = rk1000_tve_remove,
374 .shutdown = rk1000_tve_shutdown,
377 static int __init rk1000_tve_init(void)
381 ret = i2c_add_driver(&rk1000_tve_driver);
383 pr_err("i2c_add_driver err, ret = %d\n", ret);
387 static void __exit rk1000_tve_exit(void)
389 i2c_del_driver(&rk1000_tve_driver);
392 late_initcall(rk1000_tve_init);
393 module_exit(rk1000_tve_exit);
395 /* Module information */
396 MODULE_DESCRIPTION("ROCKCHIP rk1000 TV Encoder ");
397 MODULE_LICENSE("GPL");