blob: 754d4509033fd6ec0b98ce199a0cebf3a4487a93 [file] [log] [blame]
Florian Tobias Schandinate7589272011-07-30 01:25:29 +00001/*
2 * Copyright 2011 Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
3 *
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.
8 *
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.
14 *
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.
19 */
20/*
21 * generic EDID driver
22 */
23
24#include <linux/slab.h>
Florian Tobias Schandinat5dc5f612012-01-12 12:52:37 +000025#include <linux/fb.h>
Florian Tobias Schandinate7589272011-07-30 01:25:29 +000026#include "via_aux.h"
Florian Tobias Schandinat5dc5f612012-01-12 12:52:37 +000027#include "../edid.h"
Florian Tobias Schandinate7589272011-07-30 01:25:29 +000028
29
30static const char *name = "EDID";
31
32
Florian Tobias Schandinat5dc5f612012-01-12 12:52:37 +000033static void query_edid(struct via_aux_drv *drv)
34{
35 struct fb_monspecs *spec = drv->data;
36 unsigned char edid[EDID_LENGTH];
37 bool valid = false;
38
Dan Carpenterc572c8b2012-02-17 09:45:01 +030039 if (spec) {
Florian Tobias Schandinat5dc5f612012-01-12 12:52:37 +000040 fb_destroy_modedb(spec->modedb);
Dan Carpenterc572c8b2012-02-17 09:45:01 +030041 } else {
Florian Tobias Schandinat5dc5f612012-01-12 12:52:37 +000042 spec = kmalloc(sizeof(*spec), GFP_KERNEL);
Dan Carpenterc572c8b2012-02-17 09:45:01 +030043 if (!spec)
44 return;
45 }
Florian Tobias Schandinat5dc5f612012-01-12 12:52:37 +000046
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;
51 }
52
53 if (!valid) {
54 kfree(spec);
55 spec = NULL;
56 } else
57 printk(KERN_DEBUG "EDID: %s %s\n", spec->manufacturer, spec->monitor);
58
59 drv->data = spec;
60}
61
62static const struct fb_videomode *get_preferred_mode(struct via_aux_drv *drv)
63{
64 struct fb_monspecs *spec = drv->data;
65 int i;
66
67 if (!spec || !spec->modedb || !(spec->misc & FB_MISC_1ST_DETAIL))
68 return NULL;
69
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];
74 }
75
76 return NULL;
77}
78
79static void cleanup(struct via_aux_drv *drv)
80{
81 struct fb_monspecs *spec = drv->data;
82
83 if (spec)
84 fb_destroy_modedb(spec->modedb);
85}
86
Florian Tobias Schandinate7589272011-07-30 01:25:29 +000087void via_aux_edid_probe(struct via_aux_bus *bus)
88{
89 struct via_aux_drv drv = {
90 .bus = bus,
91 .addr = 0x50,
Florian Tobias Schandinat5dc5f612012-01-12 12:52:37 +000092 .name = name,
93 .cleanup = cleanup,
94 .get_preferred_mode = get_preferred_mode};
95
96 query_edid(&drv);
Florian Tobias Schandinate7589272011-07-30 01:25:29 +000097
98 /* as EDID devices can be connected/disconnected just add the driver */
99 via_aux_add(&drv);
100}