1137593Simp/*- 2137593Simp * Copyright (c) 2004 Takanori Watanabe 3137593Simp * All rights reserved. 4137593Simp * 5137593Simp * Redistribution and use in source and binary forms, with or without 6137593Simp * modification, are permitted provided that the following conditions 7137593Simp * are met: 8137593Simp * 1. Redistributions of source code must retain the above copyright 9137593Simp * notice, this list of conditions and the following disclaimer. 10137593Simp * 2. Redistributions in binary form must reproduce the above copyright 11137593Simp * notice, this list of conditions and the following disclaimer in the 12137593Simp * documentation and/or other materials provided with the distribution. 13137593Simp * 14137593Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15137593Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16137593Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17137593Simp * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18137593Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19137593Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20137593Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21137593Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22137593Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23137593Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24137593Simp * SUCH DAMAGE. 25137593Simp */ 26137593Simp 27143002Sobrien#include <sys/cdefs.h> 28143002Sobrien__FBSDID("$FreeBSD$"); 29143002Sobrien 30137593Simp#include "opt_acpi.h" 31137593Simp#include <sys/param.h> 32137593Simp#include <sys/kernel.h> 33137593Simp#include <sys/bus.h> 34193530Sjkim 35193530Sjkim#include <contrib/dev/acpica/include/acpi.h> 36193530Sjkim 37137593Simp#include "acpi_if.h" 38137593Simp#include <sys/module.h> 39137593Simp#include <dev/acpica/acpivar.h> 40137593Simp#include <sys/sysctl.h> 41138825Snjl 42138825Snjl#define _COMPONENT ACPI_OEM 43138825SnjlACPI_MODULE_NAME("Sony") 44138825Snjl 45138197Simp#define ACPI_SONY_GET_PID "GPID" 46138825Snjl 47137593Simp/* 48137593Simp * SNY5001 49203622Sgavin * This is the ACPI handle for the "Sony Notebook Control" driver under 50203622Sgavin * Windows. 51203622Sgavin * It provides several methods within the ACPI namespace, including: 52137593Simp * [GS]BRT [GS]PBR [GS]CTR [GS]PCR [GS]CMI [CDPW GCDP]? GWDP PWAK PWRN 53137593Simp * 54203622Sgavin * SNY6001 55203622Sgavin * This is the ACPI handle for the "Sony Programmable I/O" driver under 56203622Sgavin * Windows. 57203622Sgavin * It is not yet supported by this driver, but provides control over the 58203622Sgavin * power to the bluetooth, built-in camera and HSDPA modem devices in some 59203622Sgavin * laptops, and also allows some control of the fan speed. 60137593Simp */ 61137593Simp 62138197Simpstruct acpi_sony_softc { 63137714Simp int pid; 64137593Simp}; 65138197Simpstatic struct acpi_sony_name_list 66137593Simp{ 67137714Simp char *nodename; 68137714Simp char *getmethod; 69137714Simp char *setmethod; 70137714Simp char *comment; 71138197Simp} acpi_sony_oids[] = { 72137714Simp { "brightness", "GBRT", "SBRT", "Display Brightness"}, 73203622Sgavin { "brightness_default", "GPBR", "SPBR", "Default Display Brightness"}, 74203622Sgavin { "contrast", "GCTR", "SCTR", "Display Contrast"}, 75203622Sgavin { "bass_gain", "GMGB", "SMGB", "Multimedia Bass Gain"}, 76137714Simp { "pcr", "GPCR", "SPCR", "???"}, 77137593Simp#if 0 78203622Sgavin { "cmi", "GCMI", "SCMI", "???"}, 79137593Simp#endif 80203622Sgavin { "wdp", "GWDP", NULL, "???"}, 81163856Skevlo { "cdp", "GCDP", "CDPW", "CD Power"}, /*shares [\GL03]&0x8 flag*/ 82179137Skevlo { "azp", "GAZP", "AZPW", "Audio Power"}, 83203622Sgavin { "lnp", "GLNP", "LNPW", "LAN Power"}, 84163856Skevlo { NULL, NULL, NULL } 85137593Simp}; 86137593Simp 87138197Simpstatic int acpi_sony_probe(device_t dev); 88138197Simpstatic int acpi_sony_attach(device_t dev); 89138197Simpstatic int acpi_sony_detach(device_t dev); 90138197Simpstatic int sysctl_acpi_sony_gen_handler(SYSCTL_HANDLER_ARGS); 91137593Simp 92138197Simpstatic device_method_t acpi_sony_methods[] = { 93137593Simp /* Device interface */ 94138197Simp DEVMETHOD(device_probe, acpi_sony_probe), 95138197Simp DEVMETHOD(device_attach, acpi_sony_attach), 96138197Simp DEVMETHOD(device_detach, acpi_sony_detach), 97137593Simp 98246128Ssbz DEVMETHOD_END 99137593Simp}; 100137593Simp 101138197Simpstatic driver_t acpi_sony_driver = { 102138197Simp "acpi_sony", 103138197Simp acpi_sony_methods, 104138197Simp sizeof(struct acpi_sony_softc), 105137593Simp}; 106137593Simp 107138197Simpstatic devclass_t acpi_sony_devclass; 108137593Simp 109138197SimpDRIVER_MODULE(acpi_sony, acpi, acpi_sony_driver, acpi_sony_devclass, 110137593Simp 0, 0); 111138197SimpMODULE_DEPEND(acpi_sony, acpi, 1, 1, 1); 112137593Simpstatic char *sny_id[] = {"SNY5001", NULL}; 113137593Simp 114137593Simpstatic int 115138197Simpacpi_sony_probe(device_t dev) 116137593Simp{ 117192030Sbrueffer int ret = ENXIO; 118137593Simp 119137593Simp if (ACPI_ID_PROBE(device_get_parent(dev), dev, sny_id)) { 120137593Simp device_set_desc(dev, "Sony notebook controller"); 121137593Simp ret = 0; 122137593Simp } 123137593Simp return (ret); 124137593Simp} 125137593Simp 126137593Simpstatic int 127138197Simpacpi_sony_attach(device_t dev) 128137593Simp{ 129138197Simp struct acpi_sony_softc *sc; 130137593Simp int i; 131137593Simp 132137593Simp sc = device_get_softc(dev); 133138197Simp acpi_GetInteger(acpi_get_handle(dev), ACPI_SONY_GET_PID, &sc->pid); 134137593Simp device_printf(dev, "PID %x\n", sc->pid); 135138197Simp for (i = 0 ; acpi_sony_oids[i].nodename != NULL; i++){ 136137593Simp SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 137137681Simp SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 138138197Simp i, acpi_sony_oids[i].nodename , CTLTYPE_INT | 139138197Simp ((acpi_sony_oids[i].setmethod)? CTLFLAG_RW: CTLFLAG_RD), 140138197Simp dev, i, sysctl_acpi_sony_gen_handler, "I", 141138197Simp acpi_sony_oids[i].comment); 142137593Simp } 143137714Simp return (0); 144137593Simp} 145137593Simp 146137593Simpstatic int 147138197Simpacpi_sony_detach(device_t dev) 148137593Simp{ 149137745Simp return (0); 150137593Simp} 151137714Simp 152137593Simp#if 0 153137593Simpstatic int 154138197Simpacpi_sony_suspend(device_t dev) 155137593Simp{ 156138197Simp struct acpi_sony_softc *sc = device_get_softc(dev); 157137714Simp return (0); 158137593Simp} 159137593Simp 160137593Simpstatic int 161138197Simpacpi_sony_resume(device_t dev) 162137593Simp{ 163137593Simp return (0); 164137593Simp} 165137593Simp#endif 166137593Simp 167137593Simpstatic int 168138197Simpsysctl_acpi_sony_gen_handler(SYSCTL_HANDLER_ARGS) 169137593Simp{ 170137593Simp device_t dev = arg1; 171137593Simp int function = oidp->oid_arg2; 172137593Simp int error = 0, val; 173137593Simp 174137714Simp acpi_GetInteger(acpi_get_handle(dev), 175138197Simp acpi_sony_oids[function].getmethod, &val); 176137593Simp error = sysctl_handle_int(oidp, &val, 0, req); 177138197Simp if (error || !req->newptr || !acpi_sony_oids[function].setmethod) 178137714Simp return (error); 179137714Simp acpi_SetInteger(acpi_get_handle(dev), 180138197Simp acpi_sony_oids[function].setmethod, val); 181137714Simp return (0); 182137593Simp} 183