Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/i2c add ddc_dev_read_edid{, _block} functions, same a...



details:   https://anonhg.NetBSD.org/src/rev/98cca5285f1f
branches:  trunk
changeset: 338278:98cca5285f1f
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun May 17 01:27:16 2015 +0000

description:
add ddc_dev_read_edid{,_block} functions, same as ddc_read_edid{,_block} but takes a device_t instead of i2c_tag_t

diffstat:

 sys/dev/i2c/ddc.c    |  34 ++++++++++++++++++++++++++--------
 sys/dev/i2c/ddcvar.h |   5 ++++-
 2 files changed, 30 insertions(+), 9 deletions(-)

diffs (87 lines):

diff -r 5ff9d676f473 -r 98cca5285f1f sys/dev/i2c/ddc.c
--- a/sys/dev/i2c/ddc.c Sun May 17 01:26:22 2015 +0000
+++ b/sys/dev/i2c/ddc.c Sun May 17 01:27:16 2015 +0000
@@ -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 @@
        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 @@
 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);
+}
diff -r 5ff9d676f473 -r 98cca5285f1f sys/dev/i2c/ddcvar.h
--- a/sys/dev/i2c/ddcvar.h      Sun May 17 01:26:22 2015 +0000
+++ b/sys/dev/i2c/ddcvar.h      Sun May 17 01:27:16 2015 +0000
@@ -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.



Home | Main Index | Thread Index | Old Index