Module Name: src
Committed By: jmcneill
Date: Sun May 17 01:27:16 UTC 2015
Modified Files:
src/sys/dev/i2c: ddc.c ddcvar.h
Log Message:
add ddc_dev_read_edid{,_block} functions, same as ddc_read_edid{,_block} but
takes a device_t instead of i2c_tag_t
To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/i2c/ddc.c
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/i2c/ddcvar.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/i2c/ddc.c
diff -u src/sys/dev/i2c/ddc.c:1.4 src/sys/dev/i2c/ddc.c:1.5
--- src/sys/dev/i2c/ddc.c:1.4 Mon Nov 17 00:46:44 2014
+++ src/sys/dev/i2c/ddc.c Sun May 17 01:27:16 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: ddc.c,v 1.4 2014/11/17 00:46:44 jmcneill Exp $ */
+/* $NetBSD: ddc.c,v 1.5 2015/05/17 01:27:16 jmcneill Exp $ */
/*-
* Copyright (c) 2006 Itronix Inc.
@@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ddc.c,v 1.4 2014/11/17 00:46:44 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ddc.c,v 1.5 2015/05/17 01:27:16 jmcneill Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -80,6 +80,7 @@ ddc_attach(device_t parent, device_t sel
struct ddc_softc *sc = device_private(self);
struct i2c_attach_args *ia = aux;
+ sc->sc_tag = ia->ia_tag;
sc->sc_address = ia->ia_addr;
aprint_naive(": DDC\n");
@@ -97,18 +98,35 @@ ddc_read_edid(i2c_tag_t tag, uint8_t *de
int
ddc_read_edid_block(i2c_tag_t tag, uint8_t *dest, size_t len, uint8_t block)
{
- uint8_t wbuf[2];
+ uint8_t wbuf[2];
+ int error;
- if (iic_acquire_bus(tag, I2C_F_POLL) != 0)
- return -1;
+ if ((error = iic_acquire_bus(tag, I2C_F_POLL)) != 0)
+ return error;
wbuf[0] = block; /* start address */
- if (iic_exec(tag, I2C_OP_READ_WITH_STOP, DDC_ADDR, wbuf, 1, dest,
- len, I2C_F_POLL)) {
+ if ((error = iic_exec(tag, I2C_OP_READ_WITH_STOP, DDC_ADDR, wbuf, 1,
+ dest, len, I2C_F_POLL)) != 0) {
iic_release_bus(tag, I2C_F_POLL);
- return -1;
+ return error;
}
iic_release_bus(tag, I2C_F_POLL);
return 0;
}
+
+int
+ddc_dev_read_edid(device_t dev, uint8_t *dest, size_t len)
+{
+ return ddc_dev_read_edid_block(dev, dest, len, DDC_EDID_START);
+}
+
+int
+ddc_dev_read_edid_block(device_t dev, uint8_t *dest, size_t len, uint8_t block)
+{
+ if (!device_is_a(dev, "ddc"))
+ return EINVAL;
+
+ const struct ddc_softc *sc = device_private(dev);
+ return ddc_read_edid_block(sc->sc_tag, dest, len, block);
+}
Index: src/sys/dev/i2c/ddcvar.h
diff -u src/sys/dev/i2c/ddcvar.h:1.2 src/sys/dev/i2c/ddcvar.h:1.3
--- src/sys/dev/i2c/ddcvar.h:1.2 Mon Nov 17 00:46:44 2014
+++ src/sys/dev/i2c/ddcvar.h Sun May 17 01:27:16 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: ddcvar.h,v 1.2 2014/11/17 00:46:44 jmcneill Exp $ */
+/* $NetBSD: ddcvar.h,v 1.3 2015/05/17 01:27:16 jmcneill Exp $ */
/*-
* Copyright (c) 2006 Itronix Inc.
@@ -35,6 +35,9 @@
#ifndef _DEV_I2C_DDCVAR_H_
#define _DEV_I2C_DDCVAR_H_
+int ddc_dev_read_edid(device_t, u_int8_t *, size_t);
+int ddc_dev_read_edid_block(device_t, u_int8_t *, size_t, uint8_t);
+
/*
* display drivers can use this to access DDC without using the
* autoconfiguration framework.