Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F137949264
D26250.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
15 KB
Referenced Files
None
Subscribers
None
D26250.diff
View Options
Index: head/share/man/man9/Makefile
===================================================================
--- head/share/man/man9/Makefile
+++ head/share/man/man9/Makefile
@@ -10,6 +10,7 @@
alq.9 \
altq.9 \
atomic.9 \
+ backlight.9 \
bhnd.9 \
bhnd_erom.9 \
bios.9 \
Index: head/share/man/man9/backlight.9
===================================================================
--- head/share/man/man9/backlight.9
+++ head/share/man/man9/backlight.9
@@ -0,0 +1,77 @@
+.\" Copyright (c) 2020 Emmanuel Vadot <manu@freebsd.org>
+.\"
+.\" 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 DEVELOPERS ``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 DEVELOPERS 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd October 02, 2020
+.Dt BACKLIGHT 9
+.Os
+.Sh NAME
+.Nm backlight ,
+.Nm backlight_register ,
+.Nm backlight_destroy ,
+.Nm BACKLIGHT_GET_STATUS ,
+.Nm BACKLIGHT_SET_STATUS ,
+.Nd BACKLIGHT methods
+.Sh SYNOPSIS
+.Cd "device backlight"
+.In "backlight_if.h"
+.In "sys/sys/backlight.h"
+.Ft int
+.Fn BACKLIGHT_GET_STATUS "device_t bus" "struct backlight_props *props"
+.Ft int
+.Fn BACKLIGHT_SET_STATUS "device_t bus" "struct backlight_props *props"
+.Ft struct cdev *
+.Fn backlight_register "const char *name" "device_t dev"
+.Ft int
+.Fn backlight_destroy "struct cdev *cdev"
+.Sh DESCRIPTION
+The backlight driver provides a generic way for handling a panel backlight.
+.Pp
+Drivers for backlight system register themselves globally using the
+.Fn backlight_register
+function.
+They must define two methods,
+.Fn BACKLIGHT_GET_STATUS
+which is used to query the current brightness level and
+.Fn BACKLIGHT_SET_STATUS
+which is used to update it.
+.Sh INTERFACE
+.Bl -tag -width indent
+.It Fn BACKLIGHT_GET_STATUS "device_t bus" "struct backlight_props *props"
+Driver fills the current brightless level and the optional supported levels.
+.It Fn BACKLIGHT_SET_STATUS "device_t bus" "struct backlight_props *props"
+Driver update the backlight level based on the brightness member of the props
+struct.
+.El
+.Sh FILES
+.Bl -tag -width "/dev/backlight/*"
+.It Pa /dev/backlight/*
+.Sh HISTORY
+The
+.Nm backlight
+interface first appear in
+.Fx 13.0 .
+The
+.Nm backlight
+driver and manual page was written by
+.An Emmanuel Vadot Aq Mt manu@FreeBSD.org .
Index: head/sys/conf/files
===================================================================
--- head/sys/conf/files
+++ head/sys/conf/files
@@ -1312,6 +1312,8 @@
dev/ath/ath_dfs/null/dfs_null.c optional ath \
compile-with "${NORMAL_C} -I$S/dev/ath"
#
+dev/backlight/backlight_if.m optional backlight
+dev/backlight/backlight.c optional backlight
dev/bce/if_bce.c optional bce
dev/bfe/if_bfe.c optional bfe
dev/bge/if_bge.c optional bge
Index: head/sys/dev/backlight/backlight.h
===================================================================
--- head/sys/dev/backlight/backlight.h
+++ head/sys/dev/backlight/backlight.h
@@ -0,0 +1,33 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2020 Emmanuel Vadot <manu@FreeBSD.org>
+ *
+ * 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 AUTHOR 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 AUTHOR 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/backlight.h>
+
+struct cdev *backlight_register(const char *name, device_t dev);
+int backlight_destroy(struct cdev *dev);
Index: head/sys/dev/backlight/backlight.c
===================================================================
--- head/sys/dev/backlight/backlight.c
+++ head/sys/dev/backlight/backlight.c
@@ -0,0 +1,170 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2020 Emmanuel Vadot <manu@FreeBSD.org>
+ *
+ * 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 AUTHOR 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 AUTHOR 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/limits.h>
+#include <sys/bus.h>
+#include <sys/conf.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/module.h>
+#include <sys/lock.h>
+#include <sys/sx.h>
+
+#include <dev/backlight/backlight.h>
+
+#include "backlight_if.h"
+
+static struct sx backlight_sx;
+static MALLOC_DEFINE(M_BACKLIGHT, "BACKLIGHT", "Backlight driver");
+static struct unrhdr *backlight_unit;
+
+struct backlight_softc {
+ struct cdev *cdev;
+ struct cdev *alias;
+ int unit;
+ device_t dev;
+ uint32_t cached_brightness;
+};
+
+static int
+backlight_ioctl(struct cdev *dev, u_long cmd, caddr_t data,
+ int fflag, struct thread *td)
+{
+ struct backlight_softc *sc;
+ struct backlight_props props;
+ struct backlight_info info;
+ int error;
+
+ sc = dev->si_drv1;
+
+ switch (cmd) {
+ case BACKLIGHTGETSTATUS:
+ /* Call the driver function so it fills up the props */
+ bcopy(data, &props, sizeof(struct backlight_props));
+ error = BACKLIGHT_GET_STATUS(sc->dev, &props);
+ if (error == 0)
+ bcopy(&props, data, sizeof(struct backlight_props));
+ break;
+ case BACKLIGHTUPDATESTATUS:
+ bcopy(data, &props, sizeof(struct backlight_props));
+ if (props.brightness == sc->cached_brightness)
+ return (0);
+ error = BACKLIGHT_UPDATE_STATUS(sc->dev, &props);
+ if (error == 0) {
+ bcopy(&props, data, sizeof(struct backlight_props));
+ sc->cached_brightness = props.brightness;
+ }
+ break;
+ case BACKLIGHTGETINFO:
+ memset(&info, 0, sizeof(info));
+ error = BACKLIGHT_GET_INFO(sc->dev, &info);
+ if (error == 0)
+ bcopy(&info, data, sizeof(struct backlight_info));
+ break;
+ }
+
+ return (error);
+}
+
+static struct cdevsw backlight_cdevsw = {
+ .d_version = D_VERSION,
+ .d_ioctl = backlight_ioctl,
+ .d_name = "backlight",
+};
+
+struct cdev *
+backlight_register(const char *name, device_t dev)
+{
+ struct make_dev_args args;
+ struct backlight_softc *sc;
+ struct backlight_props props;
+ int error;
+
+ sc = malloc(sizeof(*sc), M_BACKLIGHT, M_WAITOK | M_ZERO);
+
+ sx_xlock(&backlight_sx);
+ sc->unit = alloc_unr(backlight_unit);
+ sc->dev = dev;
+ make_dev_args_init(&args);
+ args.mda_flags = MAKEDEV_CHECKNAME | MAKEDEV_WAITOK;
+ args.mda_devsw = &backlight_cdevsw;
+ args.mda_uid = UID_ROOT;
+ args.mda_gid = GID_VIDEO;
+ args.mda_mode = 0660;
+ args.mda_si_drv1 = sc;
+ error = make_dev_s(&args, &sc->cdev, "backlight/backlight%d", sc->unit);
+
+ if (error != 0)
+ goto fail;
+
+ error = make_dev_alias_p(MAKEDEV_CHECKNAME | MAKEDEV_WAITOK,
+ &sc->alias, sc->cdev, "backlight/%s%d", name, sc->unit);
+ if (error != 0)
+ device_printf(dev, "Cannot register with alias %s%d\n", name,
+ sc->unit);
+
+ sx_xunlock(&backlight_sx);
+
+ error = BACKLIGHT_GET_STATUS(sc->dev, &props);
+ sc->cached_brightness = props.brightness;
+
+ return (sc->cdev);
+fail:
+ sx_xunlock(&backlight_sx);
+ return (NULL);
+}
+
+int
+backlight_destroy(struct cdev *dev)
+{
+ struct backlight_softc *sc;
+
+ sc = dev->si_drv1;
+ sx_xlock(&backlight_sx);
+ free_unr(backlight_unit, sc->unit);
+ destroy_dev(dev);
+ sx_xunlock(&backlight_sx);
+ return (0);
+}
+
+static void
+backlight_drvinit(void *unused)
+{
+
+ backlight_unit = new_unrhdr(0, INT_MAX, NULL);
+ sx_init(&backlight_sx, "Backlight sx");
+}
+
+SYSINIT(backlightdev, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, backlight_drvinit, NULL);
+MODULE_VERSION(backlight, 1);
Index: head/sys/dev/backlight/backlight_if.m
===================================================================
--- head/sys/dev/backlight/backlight_if.m
+++ head/sys/dev/backlight/backlight_if.m
@@ -0,0 +1,66 @@
+#-
+# SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+#
+# Copyright (c) 2020 Emmanuel Vadot <manu@FreeBSD.org>
+#
+# 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 AUTHOR 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 AUTHOR 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.
+#
+# $FreeBSD$
+
+#include <dev/backlight/backlight.h>
+
+INTERFACE backlight;
+
+CODE {
+ static int
+ backlight_default_update_status(device_t dev, struct backlight_props *props)
+ {
+ return (EOPNOTSUPP);
+ }
+
+ static int
+ backlight_default_get_status(device_t dev, struct backlight_props *props)
+ {
+ return (EOPNOTSUPP);
+ }
+
+ static int
+ backlight_default_get_info(device_t dev, struct backlight_info *info)
+ {
+ return (EOPNOTSUPP);
+ }
+};
+
+METHOD int update_status {
+ device_t dev;
+ struct backlight_props *props;
+} DEFAULT backlight_default_update_status;
+
+METHOD int get_status {
+ device_t dev;
+ struct backlight_props *props;
+} DEFAULT backlight_default_get_status;
+
+METHOD int get_info {
+ device_t dev;
+ struct backlight_info *info;
+} DEFAULT backlight_default_get_info;
Index: head/sys/modules/Makefile
===================================================================
--- head/sys/modules/Makefile
+++ head/sys/modules/Makefile
@@ -59,6 +59,7 @@
ath_rate \
ath_pci \
${_autofs} \
+ backlight \
${_bce} \
${_bcm283x_clkman} \
${_bcm283x_pwm} \
Index: head/sys/modules/backlight/Makefile
===================================================================
--- head/sys/modules/backlight/Makefile
+++ head/sys/modules/backlight/Makefile
@@ -0,0 +1,13 @@
+# $FreeBSD$
+
+.PATH: ${SRCTOP}/sys/dev/backlight
+KMOD= backlight
+SRCS= backlight.c
+
+SRCS+= bus_if.h \
+ device_if.h \
+ opt_platform.h \
+ backlight_if.h \
+ backlight_if.c
+
+.include <bsd.kmod.mk>
Index: head/sys/sys/backlight.h
===================================================================
--- head/sys/sys/backlight.h
+++ head/sys/sys/backlight.h
@@ -0,0 +1,61 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2020 Emmanuel Vadot <manu@FreeBSD.org>
+ *
+ * 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 AUTHOR 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 AUTHOR 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef __BACKLIGHT_H__
+#define __BACKLIGHT_H__
+
+#define BACKLIGHTMAXLEVELS 100
+
+struct backlight_props {
+ uint32_t brightness;
+ uint32_t nlevels;
+ uint32_t levels[BACKLIGHTMAXLEVELS];
+};
+
+enum backlight_info_type {
+ BACKLIGHT_TYPE_PANEL = 0,
+ BACKLIGHT_TYPE_KEYBOARD
+};
+
+#define BACKLIGHTMAXNAMELENGTH 64
+
+struct backlight_info {
+ char name[BACKLIGHTMAXNAMELENGTH];
+ enum backlight_info_type type;
+};
+
+/*
+ * ioctls
+ */
+
+#define BACKLIGHTGETSTATUS _IOWR('G', 0, struct backlight_props)
+#define BACKLIGHTUPDATESTATUS _IOWR('G', 1, struct backlight_props)
+#define BACKLIGHTGETINFO _IOWR('G', 2, struct backlight_info)
+
+#endif /* __BACKLIGHT_H__ */
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 28, 2:32 PM (11 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
26272797
Default Alt Text
D26250.diff (15 KB)
Attached To
Mode
D26250: Add backlight subsystem
Attached
Detach File
Event Timeline
Log In to Comment