Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Rewrite drm_encoder_slave.c, as nouveau will need.
details: https://anonhg.NetBSD.org/src/rev/80a7dc22b6f2
branches: trunk
changeset: 336549:80a7dc22b6f2
user: riastradh <riastradh%NetBSD.org@localhost>
date: Thu Mar 05 17:42:48 2015 +0000
description:
Rewrite drm_encoder_slave.c, as nouveau will need.
diffstat:
sys/external/bsd/drm2/drm/drm_module.c | 8 +-
sys/external/bsd/drm2/drm/files.drmkms | 4 +-
sys/external/bsd/drm2/i2c/drm_encoder_slave.c | 274 ++++++++++++++++++
sys/external/bsd/drm2/include/drm/drm_encoder_slave.h | 112 +++++++
sys/modules/drmkms/Makefile | 5 +-
5 files changed, 397 insertions(+), 6 deletions(-)
diffs (truncated from 479 to 300 lines):
diff -r 48f6124aa9ca -r 80a7dc22b6f2 sys/external/bsd/drm2/drm/drm_module.c
--- a/sys/external/bsd/drm2/drm/drm_module.c Thu Mar 05 17:42:29 2015 +0000
+++ b/sys/external/bsd/drm2/drm/drm_module.c Thu Mar 05 17:42:48 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: drm_module.c,v 1.9 2014/11/12 03:14:00 christos Exp $ */
+/* $NetBSD: drm_module.c,v 1.10 2015/03/05 17:42:48 riastradh Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_module.c,v 1.9 2014/11/12 03:14:00 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_module.c,v 1.10 2015/03/05 17:42:48 riastradh Exp $");
#include <sys/types.h>
#include <sys/conf.h>
@@ -45,6 +45,7 @@
#include <linux/mutex.h>
#include <drm/drmP.h>
+#include <drm/drm_encoder_slave.h>
#include <drm/drm_sysctl.h>
/*
@@ -75,6 +76,7 @@
drm_connector_ida_init();
drm_global_init();
drm_sysctl_init(&drm_def);
+ drm_i2c_encoders_init();
return 0;
}
@@ -95,6 +97,8 @@
static void
drm_fini(void)
{
+
+ drm_i2c_encoders_fini();
drm_sysctl_fini(&drm_def);
drm_global_release();
drm_connector_ida_destroy();
diff -r 48f6124aa9ca -r 80a7dc22b6f2 sys/external/bsd/drm2/drm/files.drmkms
--- a/sys/external/bsd/drm2/drm/files.drmkms Thu Mar 05 17:42:29 2015 +0000
+++ b/sys/external/bsd/drm2/drm/files.drmkms Thu Mar 05 17:42:48 2015 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.drmkms,v 1.9 2014/11/12 02:24:40 christos Exp $
+# $NetBSD: files.drmkms,v 1.10 2015/03/05 17:42:48 riastradh Exp $
include "external/bsd/drm2/linux/files.drmkms_linux"
@@ -37,7 +37,7 @@
file external/bsd/drm2/dist/drm/drm_dp_helper.c drmkms_i2c
file external/bsd/drm2/drm/drm_drv.c drmkms
file external/bsd/drm2/dist/drm/drm_edid.c drmkms_i2c
-#file external/bsd/drm2/dist/drm/drm_encoder_slave.c drmkms_i2c
+file external/bsd/drm2/i2c/drm_encoder_slave.c drmkms_i2c
file external/bsd/drm2/dist/drm/drm_fb_helper.c drmkms
file external/bsd/drm2/dist/drm/drm_flip_work.c drmkms
file external/bsd/drm2/drm/drm_fops.c drmkms
diff -r 48f6124aa9ca -r 80a7dc22b6f2 sys/external/bsd/drm2/i2c/drm_encoder_slave.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/external/bsd/drm2/i2c/drm_encoder_slave.c Thu Mar 05 17:42:48 2015 +0000
@@ -0,0 +1,274 @@
+/* $NetBSD: drm_encoder_slave.c,v 1.1 2015/03/05 17:42:48 riastradh Exp $ */
+
+/*-
+ * Copyright (c) 2015 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Taylor R. Campbell.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: drm_encoder_slave.c,v 1.1 2015/03/05 17:42:48 riastradh Exp $");
+
+#include <sys/types.h>
+#include <sys/atomic.h>
+#include <sys/errno.h>
+#include <sys/kmem.h>
+#include <sys/mutex.h>
+#include <sys/rbtree.h>
+#include <sys/systm.h>
+
+#include <linux/i2c.h>
+
+#include <drm/drm_encoder_slave.h>
+
+static struct {
+ kmutex_t lock;
+ rb_tree_t tree; /* struct drm_i2c_encoder_driver */
+} drm_i2c_encoder_drivers;
+
+static int
+compare_i2c_encoders(void *cookie __unused, const void *va, const void *vb)
+{
+ const struct drm_i2c_encoder_driver *const da = va;
+ const struct drm_i2c_encoder_driver *const db = vb;
+
+ return strncmp(da->i2c_driver.driver.name, db->i2c_driver.driver.name,
+ I2C_NAME_SIZE);
+}
+
+static int
+compare_i2c_encoder_key(void *cookie __unused, const void *n, const void *k)
+{
+ const struct drm_i2c_encoder_driver *const driver = n;
+ const char *const name = k;
+
+ return strncmp(driver->i2c_driver.driver.name, name, I2C_NAME_SIZE);
+}
+
+static rb_tree_ops_t drm_i2c_encoder_rb_ops = {
+ .rbto_compare_nodes = &compare_i2c_encoders,
+ .rbto_compare_key = &compare_i2c_encoder_key,
+ .rbto_node_offset = offsetof(struct drm_i2c_encoder_driver, rb_node),
+ .rbto_context = NULL,
+};
+
+void
+drm_i2c_encoders_init(void)
+{
+
+ mutex_init(&drm_i2c_encoder_drivers.lock, MUTEX_DEFAULT, IPL_NONE);
+ rb_tree_init(&drm_i2c_encoder_drivers.tree, &drm_i2c_encoder_rb_ops);
+}
+
+void
+drm_i2c_encoders_fini(void)
+{
+
+ KASSERT(RB_TREE_MIN(&drm_i2c_encoder_drivers.tree) == NULL);
+#if 0 /* XXX no rb_tree_destroy */
+ rb_tree_destroy(&drm_i2c_encoder_drivers.tree);
+#endif
+ mutex_destroy(&drm_i2c_encoder_drivers.lock);
+}
+
+int
+drm_i2c_encoder_register(struct module *owner __unused,
+ struct drm_i2c_encoder_driver *driver)
+{
+ struct drm_i2c_encoder_driver *collision;
+ int ret = 0;
+
+ mutex_enter(&drm_i2c_encoder_drivers.lock);
+ collision = rb_tree_insert_node(&drm_i2c_encoder_drivers.tree, driver);
+ if (collision != driver)
+ ret = -EEXIST;
+ mutex_exit(&drm_i2c_encoder_drivers.lock);
+
+ return ret;
+}
+
+void
+drm_i2c_encoder_unregister(struct drm_i2c_encoder_driver *driver)
+{
+
+ /* XXX How to guarantee? */
+ KASSERT(driver->refcnt == 0);
+
+ mutex_enter(&drm_i2c_encoder_drivers.lock);
+ rb_tree_remove_node(&drm_i2c_encoder_drivers.tree, driver);
+ mutex_exit(&drm_i2c_encoder_drivers.lock);
+}
+
+struct drm_i2c_encoder_bus_priv {
+ struct i2c_client *i2c_client;
+ struct drm_i2c_encoder_driver *i2c_driver;
+};
+
+int
+drm_i2c_encoder_init(struct drm_device *dev, struct drm_encoder_slave *slave,
+ struct i2c_adapter *adapter, const struct i2c_board_info *info)
+{
+ struct drm_i2c_encoder_driver *driver;
+ struct drm_i2c_encoder_bus_priv *bus_priv;
+ struct i2c_client *client;
+ unsigned refcnt;
+ int ret;
+
+ bus_priv = kmem_alloc(sizeof(*bus_priv), KM_SLEEP);
+ slave->bus_priv = bus_priv;
+
+ mutex_enter(&drm_i2c_encoder_drivers.lock);
+ driver = rb_tree_find_node(&drm_i2c_encoder_drivers.tree, info->type);
+ mutex_exit(&drm_i2c_encoder_drivers.lock);
+ if (driver == NULL) {
+ ret = -ENODEV;
+ goto fail0;
+ }
+ do {
+ refcnt = driver->refcnt;
+ if (refcnt == UINT_MAX) {
+ ret = -ENFILE;
+ goto fail0;
+ }
+ } while (atomic_cas_uint(&driver->refcnt, refcnt, refcnt + 1)
+ != refcnt);
+ bus_priv->i2c_driver = driver;
+
+ client = i2c_new_device(adapter, info);
+ KASSERT(client != NULL);
+ bus_priv->i2c_client = client;
+
+ ret = (*driver->encoder_init)(client, dev, slave);
+ if (ret)
+ goto fail1;
+
+ if (info->platform_data)
+ (*slave->slave_funcs->set_config)(&slave->base,
+ info->platform_data);
+
+ /* Success! */
+ return 0;
+
+fail1: bus_priv->i2c_client = NULL;
+ i2c_unregister_device(client);
+ bus_priv->i2c_driver = NULL;
+ atomic_dec_uint(&driver->refcnt);
+fail0: KASSERT(ret < 0);
+ slave->bus_priv = NULL;
+ kmem_free(bus_priv, sizeof(*bus_priv));
+ return ret;
+}
+
+void
+drm_i2c_encoder_destroy(struct drm_encoder *encoder)
+{
+ struct drm_encoder_slave *const slave = to_encoder_slave(encoder);
+ struct drm_i2c_encoder_bus_priv *const bus_priv = slave->bus_priv;
+ struct i2c_client *const client = bus_priv->i2c_client;
+ struct drm_i2c_encoder_driver *const driver = bus_priv->i2c_driver;
+
+ bus_priv->i2c_client = NULL;
+ i2c_unregister_device(client);
+ bus_priv->i2c_driver = NULL;
+ atomic_dec_uint(&driver->refcnt);
+}
+
+struct i2c_client *
+drm_i2c_encoder_get_client(struct drm_encoder *encoder)
+{
+ struct drm_encoder_slave *const slave = to_encoder_slave(encoder);
+ struct drm_i2c_encoder_bus_priv *const bus_priv = slave->bus_priv;
+
+ return bus_priv->i2c_client;
+}
+
+static inline struct drm_encoder_slave_funcs *
+slave_funcs(struct drm_encoder *encoder)
+{
+
+ return to_encoder_slave(encoder)->slave_funcs;
+}
+
+void
+drm_i2c_encoder_dpms(struct drm_encoder *encoder, int mode)
+{
+
+ (*slave_funcs(encoder)->dpms)(encoder, mode);
+}
+
+void
+drm_i2c_encoder_prepare(struct drm_encoder *encoder)
+{
+
+ drm_i2c_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
+}
+
+void
+drm_i2c_encoder_commit(struct drm_encoder *encoder)
+{
+
+ drm_i2c_encoder_dpms(encoder, DRM_MODE_DPMS_ON);
+}
+
Home |
Main Index |
Thread Index |
Old Index