1 /*- 2 * Copyright (c) 2004 Takanori Watanabe 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $FreeBSD$ 27 */ 28 29 #include "opt_acpi.h" 30 #include <sys/param.h> 31 #include <sys/kernel.h> 32 #include <sys/bus.h> 33 #include "acpi.h" 34 #include "acpi_if.h" 35 #include <sys/module.h> 36 #include <dev/acpica/acpivar.h> 37 #include <sys/sysctl.h> 38 39 #define _COMPONENT ACPI_OEM 40 ACPI_MODULE_NAME("Sony") 41 42 #define ACPI_SONY_GET_BRIGHTNESS "GBRT" 43 #define ACPI_SONY_SET_BRIGHTNESS "SBRT" 44 #define ACPI_SONY_GET_PID "GPID" 45 46 /* 47 * SNY5001 48 * [GS]BRT [GS]PBR [GS]CTR [GS]PCR [GS]CMI [CDPW GCDP]? GWDP PWAK PWRN 49 * 50 */ 51 52 struct acpi_sony_softc { 53 int pid; 54 }; 55 static struct acpi_sony_name_list 56 { 57 char *nodename; 58 char *getmethod; 59 char *setmethod; 60 char *comment; 61 } acpi_sony_oids[] = { 62 { "brightness", "GBRT", "SBRT", "Display Brightness"}, 63 { "ctr", "GCTR", "SCTR", "??"}, 64 { "pcr", "GPCR", "SPCR", "???"}, 65 #if 0 66 { "cmi", "GCMI", "SCMI", "????"}, 67 #endif 68 { "wdp", "GWDP", NULL, "?????"}, 69 { "cdp", "GCDP", "CDPW", "??????"}, /*shares [\GL03]&0x8 flag*/ 70 {NULL, NULL,NULL} 71 }; 72 73 static int acpi_sony_probe(device_t dev); 74 static int acpi_sony_attach(device_t dev); 75 static int acpi_sony_detach(device_t dev); 76 static int sysctl_acpi_sony_gen_handler(SYSCTL_HANDLER_ARGS); 77 78 static device_method_t acpi_sony_methods[] = { 79 /* Device interface */ 80 DEVMETHOD(device_probe, acpi_sony_probe), 81 DEVMETHOD(device_attach, acpi_sony_attach), 82 DEVMETHOD(device_detach, acpi_sony_detach), 83 84 {0, 0} 85 }; 86 87 static driver_t acpi_sony_driver = { 88 "acpi_sony", 89 acpi_sony_methods, 90 sizeof(struct acpi_sony_softc), 91 }; 92 93 static devclass_t acpi_sony_devclass; 94 95 DRIVER_MODULE(acpi_sony, acpi, acpi_sony_driver, acpi_sony_devclass, 96 0, 0); 97 MODULE_DEPEND(acpi_sony, acpi, 1, 1, 1); 98 static char *sny_id[] = {"SNY5001", NULL}; 99 100 static int 101 acpi_sony_probe(device_t dev) 102 { 103 struct acpi_sony_softc *sc; 104 int ret = ENXIO; 105 106 sc = device_get_softc(dev); 107 108 if (ACPI_ID_PROBE(device_get_parent(dev), dev, sny_id)) { 109 device_set_desc(dev, "Sony notebook controller"); 110 ret = 0; 111 } 112 return (ret); 113 } 114 115 static int 116 acpi_sony_attach(device_t dev) 117 { 118 struct acpi_sony_softc *sc; 119 int i; 120 121 sc = device_get_softc(dev); 122 acpi_GetInteger(acpi_get_handle(dev), ACPI_SONY_GET_PID, &sc->pid); 123 device_printf(dev, "PID %x\n", sc->pid); 124 for (i = 0 ; acpi_sony_oids[i].nodename != NULL; i++){ 125 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 126 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 127 i, acpi_sony_oids[i].nodename , CTLTYPE_INT | 128 ((acpi_sony_oids[i].setmethod)? CTLFLAG_RW: CTLFLAG_RD), 129 dev, i, sysctl_acpi_sony_gen_handler, "I", 130 acpi_sony_oids[i].comment); 131 } 132 return (0); 133 } 134 135 static int 136 acpi_sony_detach(device_t dev) 137 { 138 return (0); 139 } 140 141 #if 0 142 static int 143 acpi_sony_suspend(device_t dev) 144 { 145 struct acpi_sony_softc *sc = device_get_softc(dev); 146 return (0); 147 } 148 149 static int 150 acpi_sony_resume(device_t dev) 151 { 152 return (0); 153 } 154 #endif 155 156 static int 157 sysctl_acpi_sony_gen_handler(SYSCTL_HANDLER_ARGS) 158 { 159 device_t dev = arg1; 160 int function = oidp->oid_arg2; 161 int error = 0, val; 162 163 acpi_GetInteger(acpi_get_handle(dev), 164 acpi_sony_oids[function].getmethod, &val); 165 error = sysctl_handle_int(oidp, &val, 0, req); 166 if (error || !req->newptr || !acpi_sony_oids[function].setmethod) 167 return (error); 168 acpi_SetInteger(acpi_get_handle(dev), 169 acpi_sony_oids[function].setmethod, val); 170 return (0); 171 } 172