From patchwork Wed Sep 22 03:20:16 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Walls X-Patchwork-Id: 198462 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o8M3L1Zr013751 for ; Wed, 22 Sep 2010 03:21:36 GMT Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 25AE49EEA3 for ; Tue, 21 Sep 2010 20:21:01 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from proofpoint-cluster.metrocast.net (proofpoint-cluster.metrocast.net [65.175.128.136]) by gabe.freedesktop.org (Postfix) with ESMTP id ECA979EE97 for ; Tue, 21 Sep 2010 20:20:09 -0700 (PDT) Received: from [192.168.1.7] (d-216-36-24-245.cpe.metrocast.net [216.36.24.245]) (authenticated bits=0) by mango.metrocast.net (8.13.8/8.13.8) with ESMTP id o8M3K6kj024739; Wed, 22 Sep 2010 03:20:06 GMT Subject: [PATCH v2 1/2] drm/sysfs: Provide per connector control of DRM KMS polling From: Andy Walls To: linux-kernel@vger.kernel.org In-Reply-To: <1285023750.30856.99.camel@morgan.silverblock.net> References: <1284987540.2242.29.camel@morgan.silverblock.net> <1285023750.30856.99.camel@morgan.silverblock.net> Date: Tue, 21 Sep 2010 23:20:16 -0400 Message-ID: <1285125616.2518.20.camel@morgan.silverblock.net> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 (2.28.3-1.fc12) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.0.10011, 1.0.148, 0.0.0000 definitions=2010-09-22_02:2010-09-22, 2010-09-22, 1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 ipscore=0 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx engine=5.0.0-1005130000 definitions=main-1009210245 Cc: Dave Airlie , Jon Smirl , dri-devel@lists.freedesktop.org, Greg Kroah-Hartman X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Wed, 22 Sep 2010 03:21:36 +0000 (UTC) diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c index 86118a7..8e0807d 100644 --- a/drivers/gpu/drm/drm_sysfs.c +++ b/drivers/gpu/drm/drm_sysfs.c @@ -318,11 +318,80 @@ static ssize_t select_subconnector_show(struct device *device, drm_get_dvi_i_select_name((int)subconnector)); } +static const struct { + uint8_t mask; + const char *name; +} polled_bit_names[] = { + { DRM_CONNECTOR_POLL_HPD, "hotplug_detectable" }, + { DRM_CONNECTOR_POLL_CONNECT, "connect" }, + { DRM_CONNECTOR_POLL_DISCONNECT, "disconnect" }, +}; + +/* + * Return the decoded contents of connector->polled, using the names of the + * all the bit masks. Bits that are set, have their names enclosed in brackets. + */ +static ssize_t polled_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct drm_connector *connector = to_drm_connector(dev); + char *tmp; + int i; + + tmp = buf; + for (i = 0; i < ARRAY_SIZE(polled_bit_names); i++) { + if (connector->polled & polled_bit_names[i].mask) + tmp += sprintf(tmp, "[%s] ", polled_bit_names[i].name); + else + tmp += sprintf(tmp, "%s ", polled_bit_names[i].name); + } + + if (tmp != buf) + *(tmp - 1) = '\n'; + return tmp - buf; +} + +/* + * Change the state of connector->polled, given input bit-mask name-strings + * that are separated by space or newline. + */ +static ssize_t polled_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct drm_connector *connector = to_drm_connector(dev); + const char *tmp; + int i; + uint8_t polled; + + /* Polling of this connector will cease, if no match is made below */ + polled = 0; + + /* Incrementally split and parse the input */ + while ((tmp = strsep((char **) &buf, " \n")) != NULL) { + + /* Don't waste effort on multiple adjacent separators */ + if (*tmp == '\0') + continue; + + /* Check for a match with a connector poll type name */ + for (i = 0; i < ARRAY_SIZE(polled_bit_names); i++) { + if (!strncasecmp(tmp, polled_bit_names[i].name, + strlen(polled_bit_names[i].name))) { + polled |= polled_bit_names[i].mask; + break; + } + } + } + connector->polled = polled; + return count; +} + static struct device_attribute connector_attrs[] = { __ATTR_RO(status), __ATTR_RO(enabled), __ATTR_RO(dpms), __ATTR_RO(modes), + __ATTR(polled, 0644, polled_show, polled_store), }; /* These attributes are for both DVI-I connectors and all types of tv-out. */