| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: ddc.c,v 1.5 2015/05/17 01:27:16 jmcneill Exp $ */ | | 1 | /* $NetBSD: ddc.c,v 1.6 2015/07/25 15:20:49 jmcneill Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2006 Itronix Inc. | | 4 | * Copyright (c) 2006 Itronix Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Written by Garrett D'Amore for Itronix Inc. | | 7 | * Written by Garrett D'Amore for Itronix Inc. |
8 | * | | 8 | * |
9 | * Redistribution and use in source and binary forms, with or without | | 9 | * Redistribution and use in source and binary forms, with or without |
10 | * modification, are permitted provided that the following conditions | | 10 | * modification, are permitted provided that the following conditions |
11 | * are met: | | 11 | * are met: |
12 | * 1. Redistributions of source code must retain the above copyright | | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * 2. Redistributions in binary form must reproduce the above copyright | | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
| @@ -22,27 +22,27 @@ | | | @@ -22,27 +22,27 @@ |
22 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | 22 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY | | 24 | * ARE DISCLAIMED. IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY |
25 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 25 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | | 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
27 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 27 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | | 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | | 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | | 30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
32 | */ | | 32 | */ |
33 | | | 33 | |
34 | #include <sys/cdefs.h> | | 34 | #include <sys/cdefs.h> |
35 | __KERNEL_RCSID(0, "$NetBSD: ddc.c,v 1.5 2015/05/17 01:27:16 jmcneill Exp $"); | | 35 | __KERNEL_RCSID(0, "$NetBSD: ddc.c,v 1.6 2015/07/25 15:20:49 jmcneill Exp $"); |
36 | | | 36 | |
37 | #include <sys/param.h> | | 37 | #include <sys/param.h> |
38 | #include <sys/systm.h> | | 38 | #include <sys/systm.h> |
39 | #include <sys/device.h> | | 39 | #include <sys/device.h> |
40 | #include <sys/kernel.h> | | 40 | #include <sys/kernel.h> |
41 | | | 41 | |
42 | #include <sys/bus.h> | | 42 | #include <sys/bus.h> |
43 | #include <dev/i2c/i2cvar.h> | | 43 | #include <dev/i2c/i2cvar.h> |
44 | #include <dev/i2c/ddcreg.h> | | 44 | #include <dev/i2c/ddcreg.h> |
45 | #include <dev/i2c/ddcvar.h> | | 45 | #include <dev/i2c/ddcvar.h> |
46 | | | 46 | |
47 | /* | | 47 | /* |
48 | * VESA Display Data Channel I2C client, used to access EDID | | 48 | * VESA Display Data Channel I2C client, used to access EDID |
| @@ -88,40 +88,48 @@ ddc_attach(device_t parent, device_t sel | | | @@ -88,40 +88,48 @@ ddc_attach(device_t parent, device_t sel |
88 | } | | 88 | } |
89 | | | 89 | |
90 | /* XXX: add cdev ops? */ | | 90 | /* XXX: add cdev ops? */ |
91 | | | 91 | |
92 | int | | 92 | int |
93 | ddc_read_edid(i2c_tag_t tag, uint8_t *dest, size_t len) | | 93 | ddc_read_edid(i2c_tag_t tag, uint8_t *dest, size_t len) |
94 | { | | 94 | { |
95 | return ddc_read_edid_block(tag, dest, len, DDC_EDID_START); | | 95 | return ddc_read_edid_block(tag, dest, len, DDC_EDID_START); |
96 | } | | 96 | } |
97 | | | 97 | |
98 | int | | 98 | int |
99 | ddc_read_edid_block(i2c_tag_t tag, uint8_t *dest, size_t len, uint8_t block) | | 99 | ddc_read_edid_block(i2c_tag_t tag, uint8_t *dest, size_t len, uint8_t block) |
100 | { | | 100 | { |
| | | 101 | uint8_t edid[256]; |
101 | uint8_t wbuf[2]; | | 102 | uint8_t wbuf[2]; |
102 | int error; | | 103 | int error; |
103 | | | 104 | |
104 | if ((error = iic_acquire_bus(tag, I2C_F_POLL)) != 0) | | 105 | if ((error = iic_acquire_bus(tag, I2C_F_POLL)) != 0) |
105 | return error; | | 106 | return error; |
106 | | | 107 | |
107 | wbuf[0] = block; /* start address */ | | 108 | wbuf[0] = block >> 1; /* start address */ |
108 | | | 109 | |
109 | if ((error = iic_exec(tag, I2C_OP_READ_WITH_STOP, DDC_ADDR, wbuf, 1, | | 110 | if ((error = iic_exec(tag, I2C_OP_READ_WITH_STOP, DDC_ADDR, wbuf, 1, |
110 | dest, len, I2C_F_POLL)) != 0) { | | 111 | edid, sizeof(edid), I2C_F_POLL)) != 0) { |
111 | iic_release_bus(tag, I2C_F_POLL); | | 112 | iic_release_bus(tag, I2C_F_POLL); |
112 | return error; | | 113 | return error; |
113 | } | | 114 | } |
114 | iic_release_bus(tag, I2C_F_POLL); | | 115 | iic_release_bus(tag, I2C_F_POLL); |
| | | 116 | |
| | | 117 | if (block & 1) { |
| | | 118 | memcpy(dest, &edid[128], min(len, 128)); |
| | | 119 | } else { |
| | | 120 | memcpy(dest, &edid[0], min(len, 128)); |
| | | 121 | } |
| | | 122 | |
115 | return 0; | | 123 | return 0; |
116 | } | | 124 | } |
117 | | | 125 | |
118 | int | | 126 | int |
119 | ddc_dev_read_edid(device_t dev, uint8_t *dest, size_t len) | | 127 | ddc_dev_read_edid(device_t dev, uint8_t *dest, size_t len) |
120 | { | | 128 | { |
121 | return ddc_dev_read_edid_block(dev, dest, len, DDC_EDID_START); | | 129 | return ddc_dev_read_edid_block(dev, dest, len, DDC_EDID_START); |
122 | } | | 130 | } |
123 | | | 131 | |
124 | int | | 132 | int |
125 | ddc_dev_read_edid_block(device_t dev, uint8_t *dest, size_t len, uint8_t block) | | 133 | ddc_dev_read_edid_block(device_t dev, uint8_t *dest, size_t len, uint8_t block) |
126 | { | | 134 | { |
127 | if (!device_is_a(dev, "ddc")) | | 135 | if (!device_is_a(dev, "ddc")) |