PERFORCE change 125225 for review
Rui Paulo
rpaulo at FreeBSD.org
Thu Aug 16 10:46:25 PDT 2007
http://perforce.freebsd.org/chv.cgi?CH=125225
Change 125225 by rpaulo at rpaulo_alpha on 2007/08/16 17:46:20
Add MacBook Pro support. Doesn't work yet.
Affected files ...
.. //depot/projects/soc2007/rpaulo-macbook/dev/backlight/backlight.c#12 edit
.. //depot/projects/soc2007/rpaulo-macbook/dev/backlight/backlightvar.h#4 edit
Differences ...
==== //depot/projects/soc2007/rpaulo-macbook/dev/backlight/backlight.c#12 (text+ko) ====
@@ -23,7 +23,7 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- * $P4: //depot/projects/soc2007/rpaulo-macbook/dev/backlight/backlight.c#11 $
+ * $P4: //depot/projects/soc2007/rpaulo-macbook/dev/backlight/backlight.c#12 $
*
*/
@@ -64,8 +64,14 @@
static int macbook_attach(device_t);
static int macbook_enable(SYSCTL_HANDLER_ARGS);
static int macbook_level(SYSCTL_HANDLER_ARGS);
+static int macbookpro_attach(device_t);
+static int macbookpro_enable(SYSCTL_HANDLER_ARGS);
+static int macbookpro_level(SYSCTL_HANDLER_ARGS);
struct backlight_model backlight_models[] = {
+ /*
+ * MacBook.
+ */
{ "MacBook1,1", 0x8086, 0x27a2,
"MacBook Core Duo Backlight Control",
macbook_attach, macbook_enable, macbook_level },
@@ -74,6 +80,25 @@
"MacBook Core 2 Duo Backlight Control",
macbook_attach, macbook_enable, macbook_level },
+ /*
+ * MacBook Pro.
+ */
+ { "MacBookPro1,1", 0x1002, 0x71c5,
+ "MacBook Pro Core Duo (15-inch) Backlight Control",
+ macbookpro_attach, macbookpro_enable, macbookpro_level },
+
+ { "MacBookPro1,2", 0x1002, 0x71c5,
+ "MacBook Pro Core Duo (17-inch) Backlight Control",
+ macbookpro_attach, macbookpro_enable, macbookpro_level },
+
+ { "MacBookPro2,1", 0x1002, 0x71c5,
+ "MacBook Pro Core 2 Duo (17-inch) Backlight Control",
+ macbookpro_attach, macbookpro_enable, macbookpro_level },
+
+ { "MacBookPro2,2", 0x1002, 0x71c5,
+ "MacBook Pro Core 2 Duo (15-inch) Backlight Control",
+ macbookpro_attach, macbookpro_enable, macbookpro_level },
+
{ NULL, 0, 0 }
};
@@ -339,3 +364,110 @@
return (error);
}
+
+/*
+ * Apple's MacBook Pro specific functions.
+ */
+static uint32_t
+macbookpro_get_current(struct backlight_softc *sc)
+{
+ uint32_t level;
+
+ level = bus_read_4(sc->sc_res, BACKLIGHT_MBP_OFFSET);
+ level = level >> BACKLIGHT_MBP_CUR_SHIFT;
+
+ return (level);
+}
+
+static void
+macbookpro_set_current(struct backlight_softc *sc, uint32_t value)
+{
+ uint32_t newlevel;
+
+ newlevel = 0x00000001 | (value << BACKLIGHT_MBP_CUR_SHIFT);
+
+ bus_write_4(sc->sc_res, BACKLIGHT_MBP_OFFSET, newlevel);
+
+ return;
+}
+
+static int
+macbookpro_attach(device_t dev)
+{
+ struct backlight_softc *sc = device_get_softc(dev);
+ int rid;
+
+ rid = PCIR_BAR(0);
+ sc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
+ RF_ACTIVE);
+
+ if (sc->sc_res == NULL)
+ return (ENOMEM);
+
+ sc->sc_enable = macbookpro_get_current(sc) >= BACKLIGHT_MBP_MIN ?
+ 1 : 0;
+ sc->sc_level = macbookpro_get_current(sc);
+
+ return (0);
+}
+
+static int
+macbookpro_enable(SYSCTL_HANDLER_ARGS)
+{
+ struct backlight_softc *sc = (struct backlight_softc *) arg1;
+ int error;
+ unsigned int enable;
+
+ enable = macbookpro_get_current(sc) >= BACKLIGHT_MBP_MIN ? 1 : 0;
+
+ error = sysctl_handle_int(oidp, &enable, 0, req);
+ if (error == 0 && req->newptr != NULL) {
+ enable = *(unsigned int *)req->newptr;
+
+ switch (enable) {
+ case 0:
+ macbookpro_set_current(sc, 0);
+ break;
+ case 1:
+ macbookpro_set_current(sc, sc->sc_level);
+ break;
+ default:
+ return EINVAL;
+ }
+ *(unsigned int *)oidp->oid_arg1 = enable;
+ }
+
+ return (error);
+}
+
+static int
+macbookpro_level(SYSCTL_HANDLER_ARGS)
+{
+ struct backlight_softc *sc = (struct backlight_softc *) arg1;
+ int error;
+ uint32_t curlevel;
+ unsigned int level;
+
+ curlevel = macbookpro_get_current(sc);
+
+ level = (curlevel - BACKLIGHT_MBP_MIN) * 100 /
+ (BACKLIGHT_MBP_MAX - BACKLIGHT_MBP_MIN);
+
+ error = sysctl_handle_int(oidp, &level, 0, req);
+
+ if (error == 0 && req->newptr != NULL) {
+ level = *(unsigned int *)req->newptr;
+
+ if (level > 100)
+ return (EINVAL);
+
+ curlevel = (level * (BACKLIGHT_MBP_MAX - BACKLIGHT_MBP_MIN)
+ / 100) + BACKLIGHT_MBP_MIN;
+ macbookpro_set_current(sc, curlevel);
+
+ *(unsigned int *)oidp->oid_arg1 = level;
+ sc->sc_level = curlevel;
+ }
+
+ return (error);
+}
==== //depot/projects/soc2007/rpaulo-macbook/dev/backlight/backlightvar.h#4 (text+ko) ====
@@ -23,7 +23,7 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- * $P4: //depot/projects/soc2007/rpaulo-macbook/dev/backlight/backlightvar.h#3 $
+ * $P4: //depot/projects/soc2007/rpaulo-macbook/dev/backlight/backlightvar.h#4 $
*
*/
@@ -62,3 +62,11 @@
#define BACKLIGHT_MB_MAX 0x94
#define BACKLIGHT_MB_OFF 0x12
#define BACKLIGHT_MB_ON 0x1f
+
+/*
+ * MacBook Pro specific.
+ */
+#define BACKLIGHT_MBP_OFFSET 0x7af8 /* register offset */
+#define BACKLIGHT_MBP_CUR_SHIFT 0x08
+#define BACKLIGHT_MBP_MIN 0x00
+#define BACKLIGHT_MBP_MAX 0xff
More information about the p4-projects
mailing list