sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / drivers / video / fbdev / via / via_aux_edid.c
blob754d4509033fd6ec0b98ce199a0cebf3a4487a93
1 /*
2 * Copyright 2011 Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License as published by the Free Software Foundation;
7 * either version 2, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
11 * the implied warranty of MERCHANTABILITY or FITNESS FOR
12 * A PARTICULAR PURPOSE.See the GNU General Public License
13 * for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc.,
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * generic EDID driver
24 #include <linux/slab.h>
25 #include <linux/fb.h>
26 #include "via_aux.h"
27 #include "../edid.h"
30 static const char *name = "EDID";
33 static void query_edid(struct via_aux_drv *drv)
35 struct fb_monspecs *spec = drv->data;
36 unsigned char edid[EDID_LENGTH];
37 bool valid = false;
39 if (spec) {
40 fb_destroy_modedb(spec->modedb);
41 } else {
42 spec = kmalloc(sizeof(*spec), GFP_KERNEL);
43 if (!spec)
44 return;
47 spec->version = spec->revision = 0;
48 if (via_aux_read(drv, 0x00, edid, EDID_LENGTH)) {
49 fb_edid_to_monspecs(edid, spec);
50 valid = spec->version || spec->revision;
53 if (!valid) {
54 kfree(spec);
55 spec = NULL;
56 } else
57 printk(KERN_DEBUG "EDID: %s %s\n", spec->manufacturer, spec->monitor);
59 drv->data = spec;
62 static const struct fb_videomode *get_preferred_mode(struct via_aux_drv *drv)
64 struct fb_monspecs *spec = drv->data;
65 int i;
67 if (!spec || !spec->modedb || !(spec->misc & FB_MISC_1ST_DETAIL))
68 return NULL;
70 for (i = 0; i < spec->modedb_len; i++) {
71 if (spec->modedb[i].flag & FB_MODE_IS_FIRST &&
72 spec->modedb[i].flag & FB_MODE_IS_DETAILED)
73 return &spec->modedb[i];
76 return NULL;
79 static void cleanup(struct via_aux_drv *drv)
81 struct fb_monspecs *spec = drv->data;
83 if (spec)
84 fb_destroy_modedb(spec->modedb);
87 void via_aux_edid_probe(struct via_aux_bus *bus)
89 struct via_aux_drv drv = {
90 .bus = bus,
91 .addr = 0x50,
92 .name = name,
93 .cleanup = cleanup,
94 .get_preferred_mode = get_preferred_mode};
96 query_edid(&drv);
98 /* as EDID devices can be connected/disconnected just add the driver */
99 via_aux_add(&drv);