Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * ACPI Sony Notebook Control Driver (SNC and SPIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Copyright (C) 2004-2005 Stelian Pop <stelian@popies.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * Copyright (C) 2007-2009 Mattia Dongili <malattia@linux.it>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * Parts of this driver inspired from asus_acpi.c and ibm_acpi.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  * which are copyrighted by their respective authors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  * The SNY6001 driver part is based on the sonypi driver which includes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  * material from:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  * Copyright (C) 2001-2005 Stelian Pop <stelian@popies.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  * Copyright (C) 2005 Narayanan R S <nars@kadamba.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  * Copyright (C) 2001-2002 Alcôve <www.alcove.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  * Copyright (C) 2001 Michael Ashley <m.ashley@unsw.edu.au>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  * Copyright (C) 2001 Junichi Morita <jun1m@mars.dti.ne.jp>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24)  * Copyright (C) 2000 Takaya Kinjo <t-kinjo@tc4.so-net.ne.jp>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26)  * Copyright (C) 2000 Andrew Tridgell <tridge@valinux.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  * Earlier work by Werner Almesberger, Paul `Rusty' Russell and Paul Mackerras.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #include <linux/backlight.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #include <linux/dmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) #include <linux/kfifo.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #include <linux/sonypi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #include <linux/sony-laptop.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #include <linux/rfkill.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #ifdef CONFIG_SONYPI_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #include <linux/poll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #include <linux/miscdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) #include <acpi/video.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) #define dprintk(fmt, ...)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) do {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 	if (debug)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 		pr_warn(fmt, ##__VA_ARGS__);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) #define SONY_NC_CLASS		"sony-nc"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) #define SONY_NC_HID		"SNY5001"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) #define SONY_NC_DRIVER_NAME	"Sony Notebook Control Driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) #define SONY_PIC_CLASS		"sony-pic"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) #define SONY_PIC_HID		"SNY6001"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) #define SONY_PIC_DRIVER_NAME	"Sony Programmable IO Control Driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) MODULE_AUTHOR("Stelian Pop, Mattia Dongili");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) MODULE_DESCRIPTION("Sony laptop extras driver (SPIC and SNC ACPI device)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) static int debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) module_param(debug, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) MODULE_PARM_DESC(debug, "set this to 1 (and RTFM) if you want to help "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 		 "the development of this driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) static int no_spic;		/* = 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) module_param(no_spic, int, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) MODULE_PARM_DESC(no_spic,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 		 "set this if you don't want to enable the SPIC device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) static int compat;		/* = 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) module_param(compat, int, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) MODULE_PARM_DESC(compat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 		 "set this if you want to enable backward compatibility mode");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) static unsigned long mask = 0xffffffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) module_param(mask, ulong, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) MODULE_PARM_DESC(mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 		 "set this to the mask of event you want to enable (see doc)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) static int camera;		/* = 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) module_param(camera, int, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) MODULE_PARM_DESC(camera,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 		 "set this to 1 to enable Motion Eye camera controls "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 		 "(only use it if you have a C1VE or C1VN model)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) #ifdef CONFIG_SONYPI_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) static int minor = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) module_param(minor, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) MODULE_PARM_DESC(minor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 		 "minor number of the misc device for the SPIC compatibility code, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 		 "default is -1 (automatic)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) static int kbd_backlight = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) module_param(kbd_backlight, int, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) MODULE_PARM_DESC(kbd_backlight,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 		 "set this to 0 to disable keyboard backlight, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 		 "1 to enable it with automatic control and 2 to have it always "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 		 "on (default: no change from current value)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) static int kbd_backlight_timeout = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) module_param(kbd_backlight_timeout, int, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) MODULE_PARM_DESC(kbd_backlight_timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 		 "meaningful values vary from 0 to 3 and their meaning depends "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 		 "on the model (default: no change from current value)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) static void sony_nc_thermal_resume(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) static int sony_nc_kbd_backlight_setup(struct platform_device *pd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 		unsigned int handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) static void sony_nc_kbd_backlight_cleanup(struct platform_device *pd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 		unsigned int handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) static int sony_nc_battery_care_setup(struct platform_device *pd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 		unsigned int handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) static void sony_nc_battery_care_cleanup(struct platform_device *pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) static int sony_nc_thermal_setup(struct platform_device *pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) static void sony_nc_thermal_cleanup(struct platform_device *pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) static int sony_nc_lid_resume_setup(struct platform_device *pd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 				    unsigned int handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) static void sony_nc_lid_resume_cleanup(struct platform_device *pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) static int sony_nc_gfx_switch_setup(struct platform_device *pd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 		unsigned int handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) static void sony_nc_gfx_switch_cleanup(struct platform_device *pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) static int __sony_nc_gfx_switch_status_get(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) static int sony_nc_highspeed_charging_setup(struct platform_device *pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) static int sony_nc_lowbatt_setup(struct platform_device *pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) static void sony_nc_lowbatt_cleanup(struct platform_device *pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) static int sony_nc_fanspeed_setup(struct platform_device *pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) static void sony_nc_fanspeed_cleanup(struct platform_device *pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) static int sony_nc_usb_charge_setup(struct platform_device *pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) static void sony_nc_usb_charge_cleanup(struct platform_device *pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) static int sony_nc_panelid_setup(struct platform_device *pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) static void sony_nc_panelid_cleanup(struct platform_device *pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) static int sony_nc_smart_conn_setup(struct platform_device *pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) static void sony_nc_smart_conn_cleanup(struct platform_device *pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) static int sony_nc_touchpad_setup(struct platform_device *pd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 				  unsigned int handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) static void sony_nc_touchpad_cleanup(struct platform_device *pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) enum sony_nc_rfkill {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	SONY_WIFI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	SONY_BLUETOOTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	SONY_WWAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 	SONY_WIMAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	N_SONY_RFKILL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) static int sony_rfkill_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) static struct rfkill *sony_rfkill_devices[N_SONY_RFKILL];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) static int sony_rfkill_address[N_SONY_RFKILL] = {0x300, 0x500, 0x700, 0x900};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) static int sony_nc_rfkill_setup(struct acpi_device *device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 		unsigned int handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) static void sony_nc_rfkill_cleanup(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) static void sony_nc_rfkill_update(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) /*********** Input Devices ***********/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) #define SONY_LAPTOP_BUF_SIZE	128
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) struct sony_laptop_input_s {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	atomic_t		users;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	struct input_dev	*jog_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	struct input_dev	*key_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	struct kfifo		fifo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	spinlock_t		fifo_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	struct timer_list	release_key_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) static struct sony_laptop_input_s sony_laptop_input = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	.users = ATOMIC_INIT(0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) struct sony_laptop_keypress {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	struct input_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	int key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) /* Correspondance table between sonypi events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209)  * and input layer indexes in the keymap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) static const int sony_laptop_input_index[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	-1,	/*  0 no event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	-1,	/*  1 SONYPI_EVENT_JOGDIAL_DOWN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	-1,	/*  2 SONYPI_EVENT_JOGDIAL_UP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	-1,	/*  3 SONYPI_EVENT_JOGDIAL_DOWN_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	-1,	/*  4 SONYPI_EVENT_JOGDIAL_UP_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	-1,	/*  5 SONYPI_EVENT_JOGDIAL_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	-1,	/*  6 SONYPI_EVENT_JOGDIAL_RELEASED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	 0,	/*  7 SONYPI_EVENT_CAPTURE_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	 1,	/*  8 SONYPI_EVENT_CAPTURE_RELEASED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	 2,	/*  9 SONYPI_EVENT_CAPTURE_PARTIALPRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	 3,	/* 10 SONYPI_EVENT_CAPTURE_PARTIALRELEASED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	 4,	/* 11 SONYPI_EVENT_FNKEY_ESC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	 5,	/* 12 SONYPI_EVENT_FNKEY_F1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	 6,	/* 13 SONYPI_EVENT_FNKEY_F2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	 7,	/* 14 SONYPI_EVENT_FNKEY_F3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	 8,	/* 15 SONYPI_EVENT_FNKEY_F4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	 9,	/* 16 SONYPI_EVENT_FNKEY_F5 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	10,	/* 17 SONYPI_EVENT_FNKEY_F6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	11,	/* 18 SONYPI_EVENT_FNKEY_F7 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	12,	/* 19 SONYPI_EVENT_FNKEY_F8 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	13,	/* 20 SONYPI_EVENT_FNKEY_F9 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	14,	/* 21 SONYPI_EVENT_FNKEY_F10 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	15,	/* 22 SONYPI_EVENT_FNKEY_F11 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	16,	/* 23 SONYPI_EVENT_FNKEY_F12 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	17,	/* 24 SONYPI_EVENT_FNKEY_1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	18,	/* 25 SONYPI_EVENT_FNKEY_2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	19,	/* 26 SONYPI_EVENT_FNKEY_D */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	20,	/* 27 SONYPI_EVENT_FNKEY_E */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	21,	/* 28 SONYPI_EVENT_FNKEY_F */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	22,	/* 29 SONYPI_EVENT_FNKEY_S */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	23,	/* 30 SONYPI_EVENT_FNKEY_B */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	24,	/* 31 SONYPI_EVENT_BLUETOOTH_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	25,	/* 32 SONYPI_EVENT_PKEY_P1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	26,	/* 33 SONYPI_EVENT_PKEY_P2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	27,	/* 34 SONYPI_EVENT_PKEY_P3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	28,	/* 35 SONYPI_EVENT_BACK_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	-1,	/* 36 SONYPI_EVENT_LID_CLOSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	-1,	/* 37 SONYPI_EVENT_LID_OPENED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	29,	/* 38 SONYPI_EVENT_BLUETOOTH_ON */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	30,	/* 39 SONYPI_EVENT_BLUETOOTH_OFF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	31,	/* 40 SONYPI_EVENT_HELP_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	32,	/* 41 SONYPI_EVENT_FNKEY_ONLY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	33,	/* 42 SONYPI_EVENT_JOGDIAL_FAST_DOWN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	34,	/* 43 SONYPI_EVENT_JOGDIAL_FAST_UP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	35,	/* 44 SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	36,	/* 45 SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	37,	/* 46 SONYPI_EVENT_JOGDIAL_VFAST_DOWN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	38,	/* 47 SONYPI_EVENT_JOGDIAL_VFAST_UP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 	39,	/* 48 SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	40,	/* 49 SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	41,	/* 50 SONYPI_EVENT_ZOOM_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	42,	/* 51 SONYPI_EVENT_THUMBPHRASE_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	43,	/* 52 SONYPI_EVENT_MEYE_FACE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	44,	/* 53 SONYPI_EVENT_MEYE_OPPOSITE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	45,	/* 54 SONYPI_EVENT_MEMORYSTICK_INSERT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	46,	/* 55 SONYPI_EVENT_MEMORYSTICK_EJECT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	-1,	/* 56 SONYPI_EVENT_ANYBUTTON_RELEASED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	-1,	/* 57 SONYPI_EVENT_BATTERY_INSERT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	-1,	/* 58 SONYPI_EVENT_BATTERY_REMOVE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	-1,	/* 59 SONYPI_EVENT_FNKEY_RELEASED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	47,	/* 60 SONYPI_EVENT_WIRELESS_ON */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	48,	/* 61 SONYPI_EVENT_WIRELESS_OFF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	49,	/* 62 SONYPI_EVENT_ZOOM_IN_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	50,	/* 63 SONYPI_EVENT_ZOOM_OUT_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	51,	/* 64 SONYPI_EVENT_CD_EJECT_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	52,	/* 65 SONYPI_EVENT_MODEKEY_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	53,	/* 66 SONYPI_EVENT_PKEY_P4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	54,	/* 67 SONYPI_EVENT_PKEY_P5 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	55,	/* 68 SONYPI_EVENT_SETTINGKEY_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	56,	/* 69 SONYPI_EVENT_VOLUME_INC_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	57,	/* 70 SONYPI_EVENT_VOLUME_DEC_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	-1,	/* 71 SONYPI_EVENT_BRIGHTNESS_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	58,	/* 72 SONYPI_EVENT_MEDIA_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	59,	/* 72 SONYPI_EVENT_VENDOR_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) static int sony_laptop_input_keycode_map[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	KEY_CAMERA,	/*  0 SONYPI_EVENT_CAPTURE_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	KEY_RESERVED,	/*  1 SONYPI_EVENT_CAPTURE_RELEASED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	KEY_RESERVED,	/*  2 SONYPI_EVENT_CAPTURE_PARTIALPRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	KEY_RESERVED,	/*  3 SONYPI_EVENT_CAPTURE_PARTIALRELEASED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	KEY_FN_ESC,	/*  4 SONYPI_EVENT_FNKEY_ESC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	KEY_FN_F1,	/*  5 SONYPI_EVENT_FNKEY_F1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	KEY_FN_F2,	/*  6 SONYPI_EVENT_FNKEY_F2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	KEY_FN_F3,	/*  7 SONYPI_EVENT_FNKEY_F3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	KEY_FN_F4,	/*  8 SONYPI_EVENT_FNKEY_F4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 	KEY_FN_F5,	/*  9 SONYPI_EVENT_FNKEY_F5 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 	KEY_FN_F6,	/* 10 SONYPI_EVENT_FNKEY_F6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	KEY_FN_F7,	/* 11 SONYPI_EVENT_FNKEY_F7 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	KEY_FN_F8,	/* 12 SONYPI_EVENT_FNKEY_F8 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	KEY_FN_F9,	/* 13 SONYPI_EVENT_FNKEY_F9 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	KEY_FN_F10,	/* 14 SONYPI_EVENT_FNKEY_F10 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	KEY_FN_F11,	/* 15 SONYPI_EVENT_FNKEY_F11 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	KEY_FN_F12,	/* 16 SONYPI_EVENT_FNKEY_F12 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	KEY_FN_1,	/* 17 SONYPI_EVENT_FNKEY_1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	KEY_FN_2,	/* 18 SONYPI_EVENT_FNKEY_2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	KEY_FN_D,	/* 19 SONYPI_EVENT_FNKEY_D */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	KEY_FN_E,	/* 20 SONYPI_EVENT_FNKEY_E */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	KEY_FN_F,	/* 21 SONYPI_EVENT_FNKEY_F */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	KEY_FN_S,	/* 22 SONYPI_EVENT_FNKEY_S */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	KEY_FN_B,	/* 23 SONYPI_EVENT_FNKEY_B */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	KEY_BLUETOOTH,	/* 24 SONYPI_EVENT_BLUETOOTH_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 	KEY_PROG1,	/* 25 SONYPI_EVENT_PKEY_P1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	KEY_PROG2,	/* 26 SONYPI_EVENT_PKEY_P2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	KEY_PROG3,	/* 27 SONYPI_EVENT_PKEY_P3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	KEY_BACK,	/* 28 SONYPI_EVENT_BACK_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 	KEY_BLUETOOTH,	/* 29 SONYPI_EVENT_BLUETOOTH_ON */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	KEY_BLUETOOTH,	/* 30 SONYPI_EVENT_BLUETOOTH_OFF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	KEY_HELP,	/* 31 SONYPI_EVENT_HELP_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	KEY_FN,		/* 32 SONYPI_EVENT_FNKEY_ONLY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	KEY_RESERVED,	/* 33 SONYPI_EVENT_JOGDIAL_FAST_DOWN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 	KEY_RESERVED,	/* 34 SONYPI_EVENT_JOGDIAL_FAST_UP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	KEY_RESERVED,	/* 35 SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	KEY_RESERVED,	/* 36 SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	KEY_RESERVED,	/* 37 SONYPI_EVENT_JOGDIAL_VFAST_DOWN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	KEY_RESERVED,	/* 38 SONYPI_EVENT_JOGDIAL_VFAST_UP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	KEY_RESERVED,	/* 39 SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	KEY_RESERVED,	/* 40 SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	KEY_ZOOM,	/* 41 SONYPI_EVENT_ZOOM_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	BTN_THUMB,	/* 42 SONYPI_EVENT_THUMBPHRASE_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	KEY_RESERVED,	/* 43 SONYPI_EVENT_MEYE_FACE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	KEY_RESERVED,	/* 44 SONYPI_EVENT_MEYE_OPPOSITE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 	KEY_RESERVED,	/* 45 SONYPI_EVENT_MEMORYSTICK_INSERT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 	KEY_RESERVED,	/* 46 SONYPI_EVENT_MEMORYSTICK_EJECT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	KEY_WLAN,	/* 47 SONYPI_EVENT_WIRELESS_ON */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	KEY_WLAN,	/* 48 SONYPI_EVENT_WIRELESS_OFF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	KEY_ZOOMIN,	/* 49 SONYPI_EVENT_ZOOM_IN_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	KEY_ZOOMOUT,	/* 50 SONYPI_EVENT_ZOOM_OUT_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 	KEY_EJECTCD,	/* 51 SONYPI_EVENT_CD_EJECT_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 	KEY_F13,	/* 52 SONYPI_EVENT_MODEKEY_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	KEY_PROG4,	/* 53 SONYPI_EVENT_PKEY_P4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	KEY_F14,	/* 54 SONYPI_EVENT_PKEY_P5 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	KEY_F15,	/* 55 SONYPI_EVENT_SETTINGKEY_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 	KEY_VOLUMEUP,	/* 56 SONYPI_EVENT_VOLUME_INC_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	KEY_VOLUMEDOWN,	/* 57 SONYPI_EVENT_VOLUME_DEC_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	KEY_MEDIA,	/* 58 SONYPI_EVENT_MEDIA_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	KEY_VENDOR,	/* 59 SONYPI_EVENT_VENDOR_PRESSED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) /* release buttons after a short delay if pressed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) static void do_sony_laptop_release_key(struct timer_list *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	struct sony_laptop_keypress kp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	spin_lock_irqsave(&sony_laptop_input.fifo_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 	if (kfifo_out(&sony_laptop_input.fifo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 		      (unsigned char *)&kp, sizeof(kp)) == sizeof(kp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 		input_report_key(kp.dev, kp.key, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 		input_sync(kp.dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	/* If there is something in the fifo schedule next release. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 	if (kfifo_len(&sony_laptop_input.fifo) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 		mod_timer(&sony_laptop_input.release_key_timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 			  jiffies + msecs_to_jiffies(10));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	spin_unlock_irqrestore(&sony_laptop_input.fifo_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) /* forward event to the input subsystem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) static void sony_laptop_report_input_event(u8 event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	struct input_dev *jog_dev = sony_laptop_input.jog_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	struct input_dev *key_dev = sony_laptop_input.key_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	struct sony_laptop_keypress kp = { NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	int scancode = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	if (event == SONYPI_EVENT_FNKEY_RELEASED ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 			event == SONYPI_EVENT_ANYBUTTON_RELEASED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 		/* Nothing, not all VAIOs generate this event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 	/* report events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	/* jog_dev events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	case SONYPI_EVENT_JOGDIAL_UP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	case SONYPI_EVENT_JOGDIAL_UP_PRESSED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 		input_report_rel(jog_dev, REL_WHEEL, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 		input_sync(jog_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	case SONYPI_EVENT_JOGDIAL_DOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	case SONYPI_EVENT_JOGDIAL_DOWN_PRESSED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 		input_report_rel(jog_dev, REL_WHEEL, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 		input_sync(jog_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	/* key_dev events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	case SONYPI_EVENT_JOGDIAL_PRESSED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 		kp.key = BTN_MIDDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 		kp.dev = jog_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 		if (event >= ARRAY_SIZE(sony_laptop_input_index)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 			dprintk("sony_laptop_report_input_event, event not known: %d\n", event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 		if ((scancode = sony_laptop_input_index[event]) != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 			kp.key = sony_laptop_input_keycode_map[scancode];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 			if (kp.key != KEY_UNKNOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 				kp.dev = key_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 	if (kp.dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 		/* if we have a scancode we emit it so we can always
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 		    remap the key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 		if (scancode != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 			input_event(kp.dev, EV_MSC, MSC_SCAN, scancode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 		input_report_key(kp.dev, kp.key, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 		input_sync(kp.dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 		/* schedule key release */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 		kfifo_in_locked(&sony_laptop_input.fifo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 				(unsigned char *)&kp, sizeof(kp),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 				&sony_laptop_input.fifo_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 		mod_timer(&sony_laptop_input.release_key_timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 			  jiffies + msecs_to_jiffies(10));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 		dprintk("unknown input event %.2x\n", event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) static int sony_laptop_setup_input(struct acpi_device *acpi_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	struct input_dev *jog_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	struct input_dev *key_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	/* don't run again if already initialized */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	if (atomic_add_return(1, &sony_laptop_input.users) > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	/* kfifo */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	spin_lock_init(&sony_laptop_input.fifo_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	error = kfifo_alloc(&sony_laptop_input.fifo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 			    SONY_LAPTOP_BUF_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 		pr_err("kfifo_alloc failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 		goto err_dec_users;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 	timer_setup(&sony_laptop_input.release_key_timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 		    do_sony_laptop_release_key, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	/* input keys */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	key_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	if (!key_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 		error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 		goto err_free_kfifo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	key_dev->name = "Sony Vaio Keys";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	key_dev->id.bustype = BUS_ISA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	key_dev->id.vendor = PCI_VENDOR_ID_SONY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	key_dev->dev.parent = &acpi_device->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 	/* Initialize the Input Drivers: special keys */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	input_set_capability(key_dev, EV_MSC, MSC_SCAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	__set_bit(EV_KEY, key_dev->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	key_dev->keycodesize = sizeof(sony_laptop_input_keycode_map[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	key_dev->keycodemax = ARRAY_SIZE(sony_laptop_input_keycode_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 	key_dev->keycode = &sony_laptop_input_keycode_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	for (i = 0; i < ARRAY_SIZE(sony_laptop_input_keycode_map); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 		__set_bit(sony_laptop_input_keycode_map[i], key_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	__clear_bit(KEY_RESERVED, key_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 	error = input_register_device(key_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 		goto err_free_keydev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	sony_laptop_input.key_dev = key_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	/* jogdial */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	jog_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	if (!jog_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 		error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 		goto err_unregister_keydev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	jog_dev->name = "Sony Vaio Jogdial";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	jog_dev->id.bustype = BUS_ISA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	jog_dev->id.vendor = PCI_VENDOR_ID_SONY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	jog_dev->dev.parent = &acpi_device->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	input_set_capability(jog_dev, EV_KEY, BTN_MIDDLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	input_set_capability(jog_dev, EV_REL, REL_WHEEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	error = input_register_device(jog_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 		goto err_free_jogdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	sony_laptop_input.jog_dev = jog_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) err_free_jogdev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	input_free_device(jog_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) err_unregister_keydev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	input_unregister_device(key_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	/* to avoid kref underflow below at input_free_device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	key_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) err_free_keydev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	input_free_device(key_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) err_free_kfifo:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	kfifo_free(&sony_laptop_input.fifo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) err_dec_users:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	atomic_dec(&sony_laptop_input.users);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) static void sony_laptop_remove_input(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	struct sony_laptop_keypress kp = { NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	/* Cleanup only after the last user has gone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	if (!atomic_dec_and_test(&sony_laptop_input.users))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	del_timer_sync(&sony_laptop_input.release_key_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	 * Generate key-up events for remaining keys. Note that we don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	 * need locking since nobody is adding new events to the kfifo.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	while (kfifo_out(&sony_laptop_input.fifo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 			 (unsigned char *)&kp, sizeof(kp)) == sizeof(kp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 		input_report_key(kp.dev, kp.key, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 		input_sync(kp.dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	/* destroy input devs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	input_unregister_device(sony_laptop_input.key_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	sony_laptop_input.key_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	if (sony_laptop_input.jog_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 		input_unregister_device(sony_laptop_input.jog_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 		sony_laptop_input.jog_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	kfifo_free(&sony_laptop_input.fifo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) /*********** Platform Device ***********/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) static atomic_t sony_pf_users = ATOMIC_INIT(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) static struct platform_driver sony_pf_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 		   .name = "sony-laptop",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 		   }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) static struct platform_device *sony_pf_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) static int sony_pf_add(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	/* don't run again if already initialized */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	if (atomic_add_return(1, &sony_pf_users) > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	ret = platform_driver_register(&sony_pf_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	sony_pf_device = platform_device_alloc("sony-laptop", -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	if (!sony_pf_device) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 		goto out_platform_registered;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	ret = platform_device_add(sony_pf_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 		goto out_platform_alloced;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599)       out_platform_alloced:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	platform_device_put(sony_pf_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	sony_pf_device = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602)       out_platform_registered:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	platform_driver_unregister(&sony_pf_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604)       out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	atomic_dec(&sony_pf_users);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) static void sony_pf_remove(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 	/* deregister only after the last user has gone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	if (!atomic_dec_and_test(&sony_pf_users))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	platform_device_unregister(sony_pf_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	platform_driver_unregister(&sony_pf_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) /*********** SNC (SNY5001) Device ***********/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) /* the device uses 1-based values, while the backlight subsystem uses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622)    0-based values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) #define SONY_MAX_BRIGHTNESS	8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) #define SNC_VALIDATE_IN		0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) #define SNC_VALIDATE_OUT	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) static ssize_t sony_nc_sysfs_show(struct device *, struct device_attribute *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 			      char *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) static ssize_t sony_nc_sysfs_store(struct device *, struct device_attribute *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 			       const char *, size_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) static int boolean_validate(const int, const int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) static int brightness_default_validate(const int, const int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) struct sony_nc_value {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 	char *name;		/* name of the entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	char **acpiget;		/* names of the ACPI get function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	char **acpiset;		/* names of the ACPI set function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	int (*validate)(const int, const int);	/* input/output validation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	int value;		/* current setting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	int valid;		/* Has ever been set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	int debug;		/* active only in debug mode ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	struct device_attribute devattr;	/* sysfs attribute */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) #define SNC_HANDLE_NAMES(_name, _values...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	static char *snc_##_name[] = { _values, NULL }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) #define SNC_HANDLE(_name, _getters, _setters, _validate, _debug) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	{ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 		.name		= __stringify(_name), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 		.acpiget	= _getters, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 		.acpiset	= _setters, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 		.validate	= _validate, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 		.debug		= _debug, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 		.devattr	= __ATTR(_name, 0, sony_nc_sysfs_show, sony_nc_sysfs_store), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) #define SNC_HANDLE_NULL	{ .name = NULL }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) SNC_HANDLE_NAMES(fnkey_get, "GHKE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) SNC_HANDLE_NAMES(brightness_def_get, "GPBR");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) SNC_HANDLE_NAMES(brightness_def_set, "SPBR");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) SNC_HANDLE_NAMES(cdpower_get, "GCDP");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) SNC_HANDLE_NAMES(cdpower_set, "SCDP", "CDPW");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) SNC_HANDLE_NAMES(audiopower_get, "GAZP");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) SNC_HANDLE_NAMES(audiopower_set, "AZPW");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) SNC_HANDLE_NAMES(lanpower_get, "GLNP");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) SNC_HANDLE_NAMES(lanpower_set, "LNPW");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) SNC_HANDLE_NAMES(lidstate_get, "GLID");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) SNC_HANDLE_NAMES(indicatorlamp_get, "GILS");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) SNC_HANDLE_NAMES(indicatorlamp_set, "SILS");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) SNC_HANDLE_NAMES(gainbass_get, "GMGB");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) SNC_HANDLE_NAMES(gainbass_set, "CMGB");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) SNC_HANDLE_NAMES(PID_get, "GPID");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) SNC_HANDLE_NAMES(CTR_get, "GCTR");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) SNC_HANDLE_NAMES(CTR_set, "SCTR");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) SNC_HANDLE_NAMES(PCR_get, "GPCR");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) SNC_HANDLE_NAMES(PCR_set, "SPCR");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) SNC_HANDLE_NAMES(CMI_get, "GCMI");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) SNC_HANDLE_NAMES(CMI_set, "SCMI");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) static struct sony_nc_value sony_nc_values[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	SNC_HANDLE(brightness_default, snc_brightness_def_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 			snc_brightness_def_set, brightness_default_validate, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	SNC_HANDLE(fnkey, snc_fnkey_get, NULL, NULL, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	SNC_HANDLE(cdpower, snc_cdpower_get, snc_cdpower_set, boolean_validate, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	SNC_HANDLE(audiopower, snc_audiopower_get, snc_audiopower_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 			boolean_validate, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	SNC_HANDLE(lanpower, snc_lanpower_get, snc_lanpower_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 			boolean_validate, 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 	SNC_HANDLE(lidstate, snc_lidstate_get, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 			boolean_validate, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	SNC_HANDLE(indicatorlamp, snc_indicatorlamp_get, snc_indicatorlamp_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 			boolean_validate, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	SNC_HANDLE(gainbass, snc_gainbass_get, snc_gainbass_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 			boolean_validate, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	/* unknown methods */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	SNC_HANDLE(PID, snc_PID_get, NULL, NULL, 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	SNC_HANDLE(CTR, snc_CTR_get, snc_CTR_set, NULL, 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	SNC_HANDLE(PCR, snc_PCR_get, snc_PCR_set, NULL, 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	SNC_HANDLE(CMI, snc_CMI_get, snc_CMI_set, NULL, 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	SNC_HANDLE_NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) static acpi_handle sony_nc_acpi_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) static struct acpi_device *sony_nc_acpi_device = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721)  * acpi_evaluate_object wrappers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722)  * all useful calls into SNC methods take one or zero parameters and return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723)  * integers or arrays.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) static union acpi_object *__call_snc_method(acpi_handle handle, char *method,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 		u64 *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	union acpi_object *result = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 	if (value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 		struct acpi_object_list params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 		union acpi_object in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 		in.type = ACPI_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 		in.integer.value = *value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 		params.count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 		params.pointer = &in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 		status = acpi_evaluate_object(handle, method, &params, &output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 		dprintk("__call_snc_method: [%s:0x%.8x%.8x]\n", method,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 				(unsigned int)(*value >> 32),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 				(unsigned int)*value & 0xffffffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 		status = acpi_evaluate_object(handle, method, NULL, &output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 		dprintk("__call_snc_method: [%s]\n", method);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 		pr_err("Failed to evaluate [%s]\n", method);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	result = (union acpi_object *) output.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	if (!result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 		dprintk("No return object [%s]\n", method);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) #define MIN(a, b)	(a > b ? b : a)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) static int sony_nc_buffer_call(acpi_handle handle, char *name, u64 *value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 		void *buffer, size_t buflen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	size_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	union acpi_object *object = __call_snc_method(handle, name, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	if (!object)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	if (!buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 		/* do nothing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	} else if (object->type == ACPI_TYPE_BUFFER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 		len = MIN(buflen, object->buffer.length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 		memset(buffer, 0, buflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 		memcpy(buffer, object->buffer.pointer, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	} else if (object->type == ACPI_TYPE_INTEGER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 		len = MIN(buflen, sizeof(object->integer.value));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 		memset(buffer, 0, buflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 		memcpy(buffer, &object->integer.value, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 		pr_warn("Unexpected acpi_object: 0x%x\n", object->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	kfree(object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) static int sony_nc_int_call(acpi_handle handle, char *name, int *value, int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 		*result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	if (value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 		u64 v = *value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 		ret = sony_nc_buffer_call(handle, name, &v, result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 				sizeof(*result));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 		ret =  sony_nc_buffer_call(handle, name, NULL, result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 				sizeof(*result));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) struct sony_nc_handles {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	u16 cap[0x10];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	struct device_attribute devattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) static struct sony_nc_handles *handles;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) static ssize_t sony_nc_handles_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 		struct device_attribute *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	ssize_t len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	for (i = 0; i < ARRAY_SIZE(handles->cap); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 		len += scnprintf(buffer + len, PAGE_SIZE - len, "0x%.4x ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 				handles->cap[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	len += scnprintf(buffer + len, PAGE_SIZE - len, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) static int sony_nc_handles_setup(struct platform_device *pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 	int i, r, result, arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	handles = kzalloc(sizeof(*handles), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	if (!handles)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	for (i = 0; i < ARRAY_SIZE(handles->cap); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 		arg = i + 0x20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 		r = sony_nc_int_call(sony_nc_acpi_handle, "SN00", &arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 					&result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 		if (!r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 			dprintk("caching handle 0x%.4x (offset: 0x%.2x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 					result, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 			handles->cap[i] = result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	if (debug) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 		sysfs_attr_init(&handles->devattr.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 		handles->devattr.attr.name = "handles";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 		handles->devattr.attr.mode = S_IRUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 		handles->devattr.show = sony_nc_handles_show;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 		/* allow reading capabilities via sysfs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 		if (device_create_file(&pd->dev, &handles->devattr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 			kfree(handles);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 			handles = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) static int sony_nc_handles_cleanup(struct platform_device *pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	if (handles) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 		if (debug)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 			device_remove_file(&pd->dev, &handles->devattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 		kfree(handles);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 		handles = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) static int sony_find_snc_handle(int handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	/* not initialized yet, return early */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	if (!handles || !handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	for (i = 0; i < 0x10; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 		if (handles->cap[i] == handle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 			dprintk("found handle 0x%.4x (offset: 0x%.2x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 					handle, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 			return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	dprintk("handle 0x%.4x not found\n", handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) static int sony_call_snc_handle(int handle, int argument, int *result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	int arg, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	int offset = sony_find_snc_handle(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	if (offset < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 		return offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	arg = offset | argument;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	ret = sony_nc_int_call(sony_nc_acpi_handle, "SN07", &arg, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	dprintk("called SN07 with 0x%.4x (result: 0x%.4x)\n", arg, *result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912)  * sony_nc_values input/output validate functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) /* brightness_default_validate:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917)  * manipulate input output values to keep consistency with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918)  * backlight framework for which brightness values are 0-based.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) static int brightness_default_validate(const int direction, const int value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	switch (direction) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 		case SNC_VALIDATE_OUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 			return value - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 		case SNC_VALIDATE_IN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 			if (value >= 0 && value < SONY_MAX_BRIGHTNESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 				return value + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) /* boolean_validate:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934)  * on input validate boolean values 0/1, on output just pass the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935)  * received value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) static int boolean_validate(const int direction, const int value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	if (direction == SNC_VALIDATE_IN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 		if (value != 0 && value != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	return value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947)  * Sysfs show/store common to all sony_nc_values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) static ssize_t sony_nc_sysfs_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 			      char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	int value, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	struct sony_nc_value *item =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 	    container_of(attr, struct sony_nc_value, devattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	if (!*item->acpiget)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 	ret = sony_nc_int_call(sony_nc_acpi_handle, *item->acpiget, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 				&value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	if (item->validate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 		value = item->validate(SNC_VALIDATE_OUT, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	return snprintf(buffer, PAGE_SIZE, "%d\n", value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) static ssize_t sony_nc_sysfs_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 			       struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 			       const char *buffer, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	int value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 	struct sony_nc_value *item =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	    container_of(attr, struct sony_nc_value, devattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	if (!item->acpiset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	if (count > 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	if (kstrtoint(buffer, 10, &value))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 	if (item->validate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 		value = item->validate(SNC_VALIDATE_IN, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	if (value < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 		return value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	ret = sony_nc_int_call(sony_nc_acpi_handle, *item->acpiset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 			       &value, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	item->value = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	item->valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006)  * Backlight device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) struct sony_backlight_props {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	struct backlight_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	int			handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	int			cmd_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	u8			offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	u8			maxlvl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) static struct sony_backlight_props sony_bl_props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) static int sony_backlight_update_status(struct backlight_device *bd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	int arg = bd->props.brightness + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	return sony_nc_int_call(sony_nc_acpi_handle, "SBRT", &arg, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) static int sony_backlight_get_brightness(struct backlight_device *bd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	int value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	if (sony_nc_int_call(sony_nc_acpi_handle, "GBRT", NULL, &value))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 	/* brightness levels are 1-based, while backlight ones are 0-based */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 	return value - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) static int sony_nc_get_brightness_ng(struct backlight_device *bd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	struct sony_backlight_props *sdev =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 		(struct sony_backlight_props *)bl_get_data(bd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	sony_call_snc_handle(sdev->handle, sdev->cmd_base + 0x100, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 	return (result & 0xff) - sdev->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) static int sony_nc_update_status_ng(struct backlight_device *bd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	int value, result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	struct sony_backlight_props *sdev =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 		(struct sony_backlight_props *)bl_get_data(bd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	value = bd->props.brightness + sdev->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	if (sony_call_snc_handle(sdev->handle, sdev->cmd_base | (value << 0x10),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 				&result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	return value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) static const struct backlight_ops sony_backlight_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 	.options = BL_CORE_SUSPENDRESUME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	.update_status = sony_backlight_update_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	.get_brightness = sony_backlight_get_brightness,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) static const struct backlight_ops sony_backlight_ng_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	.options = BL_CORE_SUSPENDRESUME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	.update_status = sony_nc_update_status_ng,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	.get_brightness = sony_nc_get_brightness_ng,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070)  * New SNC-only Vaios event mapping to driver known keys
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) struct sony_nc_event {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	u8	data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	u8	event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) static struct sony_nc_event sony_100_events[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	{ 0x90, SONYPI_EVENT_PKEY_P1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 	{ 0x10, SONYPI_EVENT_ANYBUTTON_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	{ 0x91, SONYPI_EVENT_PKEY_P2 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 	{ 0x11, SONYPI_EVENT_ANYBUTTON_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	{ 0x81, SONYPI_EVENT_FNKEY_F1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	{ 0x01, SONYPI_EVENT_FNKEY_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	{ 0x82, SONYPI_EVENT_FNKEY_F2 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	{ 0x02, SONYPI_EVENT_FNKEY_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	{ 0x83, SONYPI_EVENT_FNKEY_F3 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	{ 0x03, SONYPI_EVENT_FNKEY_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	{ 0x84, SONYPI_EVENT_FNKEY_F4 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	{ 0x04, SONYPI_EVENT_FNKEY_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	{ 0x85, SONYPI_EVENT_FNKEY_F5 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	{ 0x05, SONYPI_EVENT_FNKEY_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	{ 0x86, SONYPI_EVENT_FNKEY_F6 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 	{ 0x06, SONYPI_EVENT_FNKEY_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	{ 0x87, SONYPI_EVENT_FNKEY_F7 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	{ 0x07, SONYPI_EVENT_FNKEY_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	{ 0x88, SONYPI_EVENT_FNKEY_F8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	{ 0x08, SONYPI_EVENT_FNKEY_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	{ 0x89, SONYPI_EVENT_FNKEY_F9 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 	{ 0x09, SONYPI_EVENT_FNKEY_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 	{ 0x8A, SONYPI_EVENT_FNKEY_F10 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	{ 0x0A, SONYPI_EVENT_FNKEY_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	{ 0x8B, SONYPI_EVENT_FNKEY_F11 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	{ 0x0B, SONYPI_EVENT_FNKEY_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 	{ 0x8C, SONYPI_EVENT_FNKEY_F12 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	{ 0x0C, SONYPI_EVENT_FNKEY_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	{ 0x9d, SONYPI_EVENT_ZOOM_PRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	{ 0x1d, SONYPI_EVENT_ANYBUTTON_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	{ 0x9f, SONYPI_EVENT_CD_EJECT_PRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	{ 0x1f, SONYPI_EVENT_ANYBUTTON_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	{ 0xa1, SONYPI_EVENT_MEDIA_PRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	{ 0x21, SONYPI_EVENT_ANYBUTTON_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	{ 0xa4, SONYPI_EVENT_CD_EJECT_PRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	{ 0x24, SONYPI_EVENT_ANYBUTTON_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	{ 0xa5, SONYPI_EVENT_VENDOR_PRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	{ 0x25, SONYPI_EVENT_ANYBUTTON_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	{ 0xa6, SONYPI_EVENT_HELP_PRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	{ 0x26, SONYPI_EVENT_ANYBUTTON_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	{ 0xa8, SONYPI_EVENT_FNKEY_1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	{ 0x28, SONYPI_EVENT_ANYBUTTON_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	{ 0, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) static struct sony_nc_event sony_127_events[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 	{ 0x81, SONYPI_EVENT_MODEKEY_PRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	{ 0x01, SONYPI_EVENT_ANYBUTTON_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 	{ 0x82, SONYPI_EVENT_PKEY_P1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 	{ 0x02, SONYPI_EVENT_ANYBUTTON_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 	{ 0x83, SONYPI_EVENT_PKEY_P2 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 	{ 0x03, SONYPI_EVENT_ANYBUTTON_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	{ 0x84, SONYPI_EVENT_PKEY_P3 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	{ 0x04, SONYPI_EVENT_ANYBUTTON_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	{ 0x85, SONYPI_EVENT_PKEY_P4 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	{ 0x05, SONYPI_EVENT_ANYBUTTON_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	{ 0x86, SONYPI_EVENT_PKEY_P5 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	{ 0x06, SONYPI_EVENT_ANYBUTTON_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	{ 0x87, SONYPI_EVENT_SETTINGKEY_PRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	{ 0x07, SONYPI_EVENT_ANYBUTTON_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	{ 0, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) static int sony_nc_hotkeys_decode(u32 event, unsigned int handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 	int ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 	unsigned int result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 	struct sony_nc_event *key_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	if (sony_call_snc_handle(handle, 0x200, &result)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 		dprintk("Unable to decode event 0x%.2x 0x%.2x\n", handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 				event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 	result &= 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	if (handle == 0x0100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 		key_event = sony_100_events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 		key_event = sony_127_events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 	for (; key_event->data; key_event++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 		if (key_event->data == result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 			ret = key_event->event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	if (!key_event->data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 		pr_info("Unknown hotkey 0x%.2x/0x%.2x (handle 0x%.2x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 				event, result, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175)  * ACPI callbacks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) enum event_types {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	HOTKEY = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 	KILLSWITCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	GFX_SWITCH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) static void sony_nc_notify(struct acpi_device *device, u32 event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	u32 real_ev = event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 	u8 ev_type = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	dprintk("sony_nc_notify, event: 0x%.2x\n", event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 	if (event >= 0x90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 		unsigned int result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 		unsigned int arg = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 		unsigned int handle = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 		unsigned int offset = event - 0x90;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 		if (offset >= ARRAY_SIZE(handles->cap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 			pr_err("Event 0x%x outside of capabilities list\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 					event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 		handle = handles->cap[offset];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 		/* list of handles known for generating events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 		switch (handle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 		/* hotkey event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 		case 0x0100:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 		case 0x0127:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 			ev_type = HOTKEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 			ret = sony_nc_hotkeys_decode(event, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 			if (ret > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 				sony_laptop_report_input_event(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 				real_ev = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 		/* wlan switch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 		case 0x0124:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 		case 0x0135:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 			/* events on this handle are reported when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 			 * switch changes position or for battery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 			 * events. We'll notify both of them but only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 			 * update the rfkill device status when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 			 * switch is moved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 			ev_type = KILLSWITCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 			sony_call_snc_handle(handle, 0x0100, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 			real_ev = result & 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 			/* hw switch event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 			if (real_ev == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 				sony_nc_rfkill_update();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 		case 0x0128:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 		case 0x0146:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 			/* Hybrid GFX switching */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 			sony_call_snc_handle(handle, 0x0000, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 			dprintk("GFX switch event received (reason: %s)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 					(result == 0x1) ? "switch change" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 					(result == 0x2) ? "output switch" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 					(result == 0x3) ? "output switch" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 					"");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 			ev_type = GFX_SWITCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 			real_ev = __sony_nc_gfx_switch_status_get();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 		case 0x015B:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 			/* Hybrid GFX switching SVS151290S */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 			ev_type = GFX_SWITCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 			real_ev = __sony_nc_gfx_switch_status_get();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 			dprintk("Unknown event 0x%x for handle 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 					event, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 		/* clear the event (and the event reason when present) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 		arg = 1 << offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 		sony_nc_int_call(sony_nc_acpi_handle, "SN05", &arg, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 		/* old style event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 		ev_type = HOTKEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 		sony_laptop_report_input_event(real_ev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	acpi_bus_generate_netlink_event(sony_nc_acpi_device->pnp.device_class,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 			dev_name(&sony_nc_acpi_device->dev), ev_type, real_ev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) static acpi_status sony_walk_callback(acpi_handle handle, u32 level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 				      void *context, void **return_value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 	struct acpi_device_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 	if (ACPI_SUCCESS(acpi_get_object_info(handle, &info))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 		pr_warn("method: name: %4.4s, args %X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 			(char *)&info->name, info->param_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 		kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 	return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291)  * ACPI device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) static void sony_nc_function_setup(struct acpi_device *device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 		struct platform_device *pf_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 	unsigned int i, result, bitmask, arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 	if (!handles)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 	/* setup found handles here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 	for (i = 0; i < ARRAY_SIZE(handles->cap); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 		unsigned int handle = handles->cap[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 		if (!handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 		dprintk("setting up handle 0x%.4x\n", handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 		switch (handle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 		case 0x0100:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 		case 0x0101:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 		case 0x0127:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 			/* setup hotkeys */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 			sony_call_snc_handle(handle, 0, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 		case 0x0102:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 			/* setup hotkeys */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 			sony_call_snc_handle(handle, 0x100, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 		case 0x0105:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 		case 0x0148:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 			/* touchpad enable/disable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 			result = sony_nc_touchpad_setup(pf_device, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 			if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 				pr_err("couldn't set up touchpad control function (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 						result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 		case 0x0115:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 		case 0x0136:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 		case 0x013f:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 			result = sony_nc_battery_care_setup(pf_device, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 			if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 				pr_err("couldn't set up battery care function (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 						result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 		case 0x0119:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 		case 0x015D:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 			result = sony_nc_lid_resume_setup(pf_device, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 			if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 				pr_err("couldn't set up lid resume function (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 						result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 		case 0x0122:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 			result = sony_nc_thermal_setup(pf_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 			if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 				pr_err("couldn't set up thermal profile function (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 						result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 		case 0x0128:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 		case 0x0146:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 		case 0x015B:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 			result = sony_nc_gfx_switch_setup(pf_device, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 			if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 				pr_err("couldn't set up GFX Switch status (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 						result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 		case 0x0131:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 			result = sony_nc_highspeed_charging_setup(pf_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 			if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 				pr_err("couldn't set up high speed charging function (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 				       result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 		case 0x0124:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 		case 0x0135:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 			result = sony_nc_rfkill_setup(device, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 			if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 				pr_err("couldn't set up rfkill support (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 						result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 		case 0x0137:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 		case 0x0143:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 		case 0x014b:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 		case 0x014c:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 		case 0x0153:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 		case 0x0163:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 			result = sony_nc_kbd_backlight_setup(pf_device, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 			if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 				pr_err("couldn't set up keyboard backlight function (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 						result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 		case 0x0121:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 			result = sony_nc_lowbatt_setup(pf_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 			if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 				pr_err("couldn't set up low battery function (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 				       result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 		case 0x0149:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 			result = sony_nc_fanspeed_setup(pf_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 			if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 				pr_err("couldn't set up fan speed function (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 				       result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 		case 0x0155:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 			result = sony_nc_usb_charge_setup(pf_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 			if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 				pr_err("couldn't set up USB charge support (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 						result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 		case 0x011D:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 			result = sony_nc_panelid_setup(pf_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 			if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 				pr_err("couldn't set up panel ID function (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 				       result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 		case 0x0168:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 			result = sony_nc_smart_conn_setup(pf_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 			if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 				pr_err("couldn't set up smart connect support (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 						result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 	/* Enable all events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 	arg = 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 	if (!sony_nc_int_call(sony_nc_acpi_handle, "SN00", &arg, &bitmask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 		sony_nc_int_call(sony_nc_acpi_handle, "SN02", &bitmask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 				&result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) static void sony_nc_function_cleanup(struct platform_device *pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 	unsigned int i, result, bitmask, handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 	if (!handles)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 	/* get enabled events and disable them */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 	sony_nc_int_call(sony_nc_acpi_handle, "SN01", NULL, &bitmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 	sony_nc_int_call(sony_nc_acpi_handle, "SN03", &bitmask, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 	/* cleanup handles here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 	for (i = 0; i < ARRAY_SIZE(handles->cap); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 		handle = handles->cap[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 		if (!handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 		switch (handle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 		case 0x0105:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 		case 0x0148:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 			sony_nc_touchpad_cleanup(pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 		case 0x0115:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 		case 0x0136:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 		case 0x013f:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 			sony_nc_battery_care_cleanup(pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 		case 0x0119:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 		case 0x015D:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 			sony_nc_lid_resume_cleanup(pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 		case 0x0122:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 			sony_nc_thermal_cleanup(pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 		case 0x0128:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 		case 0x0146:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 		case 0x015B:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 			sony_nc_gfx_switch_cleanup(pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 		case 0x0131:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 			sony_nc_highspeed_charging_cleanup(pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 		case 0x0124:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 		case 0x0135:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 			sony_nc_rfkill_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 		case 0x0137:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 		case 0x0143:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 		case 0x014b:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 		case 0x014c:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 		case 0x0153:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 		case 0x0163:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 			sony_nc_kbd_backlight_cleanup(pd, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 		case 0x0121:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 			sony_nc_lowbatt_cleanup(pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 		case 0x0149:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 			sony_nc_fanspeed_cleanup(pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 		case 0x0155:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 			sony_nc_usb_charge_cleanup(pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 		case 0x011D:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 			sony_nc_panelid_cleanup(pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 		case 0x0168:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 			sony_nc_smart_conn_cleanup(pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 	/* finally cleanup the handles list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 	sony_nc_handles_cleanup(pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) static void sony_nc_function_resume(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 	unsigned int i, result, bitmask, arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 	dprintk("Resuming SNC device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 	for (i = 0; i < ARRAY_SIZE(handles->cap); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 		unsigned int handle = handles->cap[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 		if (!handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 		switch (handle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 		case 0x0100:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 		case 0x0101:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 		case 0x0127:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 			/* re-enable hotkeys */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 			sony_call_snc_handle(handle, 0, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 		case 0x0102:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 			/* re-enable hotkeys */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 			sony_call_snc_handle(handle, 0x100, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 		case 0x0122:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 			sony_nc_thermal_resume();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 		case 0x0124:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 		case 0x0135:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 			sony_nc_rfkill_update();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 	/* Enable all events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 	arg = 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 	if (!sony_nc_int_call(sony_nc_acpi_handle, "SN00", &arg, &bitmask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 		sony_nc_int_call(sony_nc_acpi_handle, "SN02", &bitmask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 				&result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) static int sony_nc_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 	struct sony_nc_value *item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 	for (item = sony_nc_values; item->name; item++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 		int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 		if (!item->valid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 		ret = sony_nc_int_call(sony_nc_acpi_handle, *item->acpiset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 				       &item->value, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 		if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 			pr_err("%s: %d\n", __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 	if (acpi_has_method(sony_nc_acpi_handle, "ECON")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 		int arg = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 		if (sony_nc_int_call(sony_nc_acpi_handle, "ECON", &arg, NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 			dprintk("ECON Method failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 	if (acpi_has_method(sony_nc_acpi_handle, "SN00"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 		sony_nc_function_resume();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) static SIMPLE_DEV_PM_OPS(sony_nc_pm, NULL, sony_nc_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) static void sony_nc_rfkill_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 	for (i = 0; i < N_SONY_RFKILL; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 		if (sony_rfkill_devices[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 			rfkill_unregister(sony_rfkill_devices[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 			rfkill_destroy(sony_rfkill_devices[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) static int sony_nc_rfkill_set(void *data, bool blocked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 	int argument = sony_rfkill_address[(long) data] + 0x100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 	if (!blocked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 		argument |= 0x070000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 	return sony_call_snc_handle(sony_rfkill_handle, argument, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) static const struct rfkill_ops sony_rfkill_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 	.set_block = sony_nc_rfkill_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) static int sony_nc_setup_rfkill(struct acpi_device *device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 				enum sony_nc_rfkill nc_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 	struct rfkill *rfk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 	enum rfkill_type type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 	const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 	bool hwblock, swblock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 	switch (nc_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 	case SONY_WIFI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 		type = RFKILL_TYPE_WLAN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 		name = "sony-wifi";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 	case SONY_BLUETOOTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 		type = RFKILL_TYPE_BLUETOOTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 		name = "sony-bluetooth";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 	case SONY_WWAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 		type = RFKILL_TYPE_WWAN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 		name = "sony-wwan";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 	case SONY_WIMAX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 		type = RFKILL_TYPE_WIMAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 		name = "sony-wimax";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 	rfk = rfkill_alloc(name, &device->dev, type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 			   &sony_rfkill_ops, (void *)nc_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 	if (!rfk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 	err = sony_call_snc_handle(sony_rfkill_handle, 0x200, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 		rfkill_destroy(rfk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 	hwblock = !(result & 0x1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 	err = sony_call_snc_handle(sony_rfkill_handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 				   sony_rfkill_address[nc_type],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 				   &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 		rfkill_destroy(rfk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 	swblock = !(result & 0x2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 	rfkill_init_sw_state(rfk, swblock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 	rfkill_set_hw_state(rfk, hwblock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 	err = rfkill_register(rfk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 		rfkill_destroy(rfk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 	sony_rfkill_devices[nc_type] = rfk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) static void sony_nc_rfkill_update(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 	enum sony_nc_rfkill i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 	bool hwblock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 	sony_call_snc_handle(sony_rfkill_handle, 0x200, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 	hwblock = !(result & 0x1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 	for (i = 0; i < N_SONY_RFKILL; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 		int argument = sony_rfkill_address[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 		if (!sony_rfkill_devices[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 		if (hwblock) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 			if (rfkill_set_hw_state(sony_rfkill_devices[i], true)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 				/* we already know we're blocked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 		sony_call_snc_handle(sony_rfkill_handle, argument, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 		rfkill_set_states(sony_rfkill_devices[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 				  !(result & 0x2), false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) static int sony_nc_rfkill_setup(struct acpi_device *device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) 		unsigned int handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 	u64 offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) 	unsigned char buffer[32] = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 	offset = sony_find_snc_handle(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 	sony_rfkill_handle = handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 	i = sony_nc_buffer_call(sony_nc_acpi_handle, "SN06", &offset, buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) 			32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 	if (i < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 		return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 	/* The buffer is filled with magic numbers describing the devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 	 * available, 0xff terminates the enumeration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 	 * Known codes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 	 *	0x00 WLAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 	 *	0x10 BLUETOOTH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 	 *	0x20 WWAN GPRS-EDGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 	 *	0x21 WWAN HSDPA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 	 *	0x22 WWAN EV-DO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 	 *	0x23 WWAN GPS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 	 *	0x25 Gobi WWAN no GPS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 	 *	0x26 Gobi WWAN + GPS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 	 *	0x28 Gobi WWAN no GPS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 	 *	0x29 Gobi WWAN + GPS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 	 *	0x30 WIMAX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 	 *	0x50 Gobi WWAN no GPS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 	 *	0x51 Gobi WWAN + GPS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 	 *	0x70 no SIM card slot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 	 *	0x71 SIM card slot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 	for (i = 0; i < ARRAY_SIZE(buffer); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 		if (buffer[i] == 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 		dprintk("Radio devices, found 0x%.2x\n", buffer[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 		if (buffer[i] == 0 && !sony_rfkill_devices[SONY_WIFI])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) 			sony_nc_setup_rfkill(device, SONY_WIFI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 		if (buffer[i] == 0x10 && !sony_rfkill_devices[SONY_BLUETOOTH])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 			sony_nc_setup_rfkill(device, SONY_BLUETOOTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 		if (((0xf0 & buffer[i]) == 0x20 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 					(0xf0 & buffer[i]) == 0x50) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 				!sony_rfkill_devices[SONY_WWAN])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 			sony_nc_setup_rfkill(device, SONY_WWAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 		if (buffer[i] == 0x30 && !sony_rfkill_devices[SONY_WIMAX])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 			sony_nc_setup_rfkill(device, SONY_WIMAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) /* Keyboard backlight feature */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) struct kbd_backlight {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 	unsigned int handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 	unsigned int base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 	unsigned int mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 	unsigned int timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 	unsigned int has_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 	struct device_attribute mode_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 	struct device_attribute timeout_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) static struct kbd_backlight *kbdbl_ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) static ssize_t __sony_nc_kbd_backlight_mode_set(u8 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 	if (value > 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 	if (sony_call_snc_handle(kbdbl_ctl->handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 				(value << 0x10) | (kbdbl_ctl->base), &result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) 	/* Try to turn the light on/off immediately */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 	if (value != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 		sony_call_snc_handle(kbdbl_ctl->handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 				(value << 0x0f) | (kbdbl_ctl->base + 0x100),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 				&result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) 	kbdbl_ctl->mode = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) static ssize_t sony_nc_kbd_backlight_mode_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) 		struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) 		const char *buffer, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 	unsigned long value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 	if (count > 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 	if (kstrtoul(buffer, 10, &value))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 	ret = __sony_nc_kbd_backlight_mode_set(value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) static ssize_t sony_nc_kbd_backlight_mode_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 		struct device_attribute *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 	ssize_t count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) 	count = snprintf(buffer, PAGE_SIZE, "%d\n", kbdbl_ctl->mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) static int __sony_nc_kbd_backlight_timeout_set(u8 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 	if (value > 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 	if (sony_call_snc_handle(kbdbl_ctl->handle, (value << 0x10) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 				(kbdbl_ctl->base + 0x200), &result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 	kbdbl_ctl->timeout = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) static ssize_t sony_nc_kbd_backlight_timeout_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 		struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 		const char *buffer, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) 	unsigned long value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 	if (count > 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 	if (kstrtoul(buffer, 10, &value))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) 	ret = __sony_nc_kbd_backlight_timeout_set(value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) static ssize_t sony_nc_kbd_backlight_timeout_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) 		struct device_attribute *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) 	ssize_t count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 	count = snprintf(buffer, PAGE_SIZE, "%d\n", kbdbl_ctl->timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) static int sony_nc_kbd_backlight_setup(struct platform_device *pd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 		unsigned int handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 	int probe_base = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 	int ctl_base = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 	if (kbdbl_ctl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 		pr_warn("handle 0x%.4x: keyboard backlight setup already done for 0x%.4x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 				handle, kbdbl_ctl->handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) 	/* verify the kbd backlight presence, some of these handles are not used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) 	 * for keyboard backlight only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 	switch (handle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) 	case 0x0153:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 		probe_base = 0x0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) 		ctl_base = 0x0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) 	case 0x0137:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 		probe_base = 0x0B00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 		ctl_base = 0x0C00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 		probe_base = 0x0100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) 		ctl_base = 0x4000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) 	ret = sony_call_snc_handle(handle, probe_base, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) 	if ((handle == 0x0137 && !(result & 0x02)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) 			!(result & 0x01)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) 		dprintk("no backlight keyboard found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 	kbdbl_ctl = kzalloc(sizeof(*kbdbl_ctl), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) 	if (!kbdbl_ctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) 	kbdbl_ctl->mode = kbd_backlight;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) 	kbdbl_ctl->timeout = kbd_backlight_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) 	kbdbl_ctl->handle = handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) 	kbdbl_ctl->base = ctl_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) 	/* Some models do not allow timeout control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) 	kbdbl_ctl->has_timeout = handle != 0x0153;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) 	sysfs_attr_init(&kbdbl_ctl->mode_attr.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) 	kbdbl_ctl->mode_attr.attr.name = "kbd_backlight";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) 	kbdbl_ctl->mode_attr.attr.mode = S_IRUGO | S_IWUSR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) 	kbdbl_ctl->mode_attr.show = sony_nc_kbd_backlight_mode_show;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) 	kbdbl_ctl->mode_attr.store = sony_nc_kbd_backlight_mode_store;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) 	ret = device_create_file(&pd->dev, &kbdbl_ctl->mode_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) 		goto outkzalloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) 	__sony_nc_kbd_backlight_mode_set(kbdbl_ctl->mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) 	if (kbdbl_ctl->has_timeout) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) 		sysfs_attr_init(&kbdbl_ctl->timeout_attr.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) 		kbdbl_ctl->timeout_attr.attr.name = "kbd_backlight_timeout";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) 		kbdbl_ctl->timeout_attr.attr.mode = S_IRUGO | S_IWUSR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) 		kbdbl_ctl->timeout_attr.show =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) 			sony_nc_kbd_backlight_timeout_show;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) 		kbdbl_ctl->timeout_attr.store =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) 			sony_nc_kbd_backlight_timeout_store;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) 		ret = device_create_file(&pd->dev, &kbdbl_ctl->timeout_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) 			goto outmode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) 		__sony_nc_kbd_backlight_timeout_set(kbdbl_ctl->timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) outmode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) 	device_remove_file(&pd->dev, &kbdbl_ctl->mode_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) outkzalloc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) 	kfree(kbdbl_ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) 	kbdbl_ctl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) static void sony_nc_kbd_backlight_cleanup(struct platform_device *pd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) 		unsigned int handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) 	if (kbdbl_ctl && handle == kbdbl_ctl->handle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) 		device_remove_file(&pd->dev, &kbdbl_ctl->mode_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) 		if (kbdbl_ctl->has_timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) 			device_remove_file(&pd->dev, &kbdbl_ctl->timeout_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) 		kfree(kbdbl_ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) 		kbdbl_ctl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) struct battery_care_control {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) 	struct device_attribute attrs[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) 	unsigned int handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) static struct battery_care_control *bcare_ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) static ssize_t sony_nc_battery_care_limit_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) 		struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) 		const char *buffer, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) 	unsigned int result, cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) 	unsigned long value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) 	if (count > 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) 	if (kstrtoul(buffer, 10, &value))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) 	/*  limit values (2 bits):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) 	 *  00 - none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) 	 *  01 - 80%
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) 	 *  10 - 50%
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) 	 *  11 - 100%
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) 	 *  bit 0: 0 disable BCL, 1 enable BCL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) 	 *  bit 1: 1 tell to store the battery limit (see bits 6,7) too
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) 	 *  bits 2,3: reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) 	 *  bits 4,5: store the limit into the EC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) 	 *  bits 6,7: store the limit into the battery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) 	cmd = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) 	if (value > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) 		if (value <= 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) 			cmd = 0x20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) 		else if (value <= 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) 			cmd = 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) 		else if (value <= 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) 			cmd = 0x30;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) 		 * handle 0x0115 should allow storing on battery too;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) 		 * handle 0x0136 same as 0x0115 + health status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) 		 * handle 0x013f, same as 0x0136 but no storing on the battery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) 		if (bcare_ctl->handle != 0x013f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) 			cmd = cmd | (cmd << 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) 		cmd = (cmd | 0x1) << 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) 	if (sony_call_snc_handle(bcare_ctl->handle, cmd | 0x0100, &result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) static ssize_t sony_nc_battery_care_limit_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) 		struct device_attribute *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) 	unsigned int result, status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) 	if (sony_call_snc_handle(bcare_ctl->handle, 0x0000, &result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) 	status = (result & 0x01) ? ((result & 0x30) >> 0x04) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) 	switch (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) 	case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) 		status = 80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) 	case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) 		status = 50;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) 	case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) 		status = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) 		status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) 	return snprintf(buffer, PAGE_SIZE, "%d\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) static ssize_t sony_nc_battery_care_health_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) 		struct device_attribute *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) 	ssize_t count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) 	unsigned int health;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) 	if (sony_call_snc_handle(bcare_ctl->handle, 0x0200, &health))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) 	count = snprintf(buffer, PAGE_SIZE, "%d\n", health & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) static int sony_nc_battery_care_setup(struct platform_device *pd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) 		unsigned int handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) 	bcare_ctl = kzalloc(sizeof(struct battery_care_control), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) 	if (!bcare_ctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) 	bcare_ctl->handle = handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) 	sysfs_attr_init(&bcare_ctl->attrs[0].attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) 	bcare_ctl->attrs[0].attr.name = "battery_care_limiter";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) 	bcare_ctl->attrs[0].attr.mode = S_IRUGO | S_IWUSR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) 	bcare_ctl->attrs[0].show = sony_nc_battery_care_limit_show;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) 	bcare_ctl->attrs[0].store = sony_nc_battery_care_limit_store;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) 	ret = device_create_file(&pd->dev, &bcare_ctl->attrs[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) 		goto outkzalloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) 	/* 0x0115 is for models with no health reporting capability */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) 	if (handle == 0x0115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) 	sysfs_attr_init(&bcare_ctl->attrs[1].attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) 	bcare_ctl->attrs[1].attr.name = "battery_care_health";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) 	bcare_ctl->attrs[1].attr.mode = S_IRUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) 	bcare_ctl->attrs[1].show = sony_nc_battery_care_health_show;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) 	ret = device_create_file(&pd->dev, &bcare_ctl->attrs[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) 		goto outlimiter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) outlimiter:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) 	device_remove_file(&pd->dev, &bcare_ctl->attrs[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) outkzalloc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) 	kfree(bcare_ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) 	bcare_ctl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) static void sony_nc_battery_care_cleanup(struct platform_device *pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) 	if (bcare_ctl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) 		device_remove_file(&pd->dev, &bcare_ctl->attrs[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) 		if (bcare_ctl->handle != 0x0115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) 			device_remove_file(&pd->dev, &bcare_ctl->attrs[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) 		kfree(bcare_ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) 		bcare_ctl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) struct snc_thermal_ctrl {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) 	unsigned int mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) 	unsigned int profiles;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) 	struct device_attribute mode_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) 	struct device_attribute profiles_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) static struct snc_thermal_ctrl *th_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) #define THM_PROFILE_MAX 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) static const char * const snc_thermal_profiles[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) 	"balanced",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) 	"silent",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) 	"performance"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) static int sony_nc_thermal_mode_set(unsigned short mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) 	unsigned int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) 	/* the thermal profile seems to be a two bit bitmask:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) 	 * lsb -> silent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) 	 * msb -> performance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) 	 * no bit set is the normal operation and is always valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) 	 * Some vaio models only have "balanced" and "performance"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) 	if ((mode && !(th_handle->profiles & mode)) || mode >= THM_PROFILE_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) 	if (sony_call_snc_handle(0x0122, mode << 0x10 | 0x0200, &result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) 	th_handle->mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) static int sony_nc_thermal_mode_get(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) 	unsigned int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) 	if (sony_call_snc_handle(0x0122, 0x0100, &result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) 	return result & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) static ssize_t sony_nc_thermal_profiles_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) 		struct device_attribute *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) 	short cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) 	size_t idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) 	for (cnt = 0; cnt < THM_PROFILE_MAX; cnt++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) 		if (!cnt || (th_handle->profiles & cnt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) 			idx += scnprintf(buffer + idx, PAGE_SIZE - idx, "%s ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) 					snc_thermal_profiles[cnt]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) 	idx += scnprintf(buffer + idx, PAGE_SIZE - idx, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) 	return idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) static ssize_t sony_nc_thermal_mode_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) 		struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) 		const char *buffer, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) 	unsigned short cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) 	size_t len = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) 	if (count == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) 	/* skip the newline if present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) 	if (buffer[len - 1] == '\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) 		len--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) 	for (cmd = 0; cmd < THM_PROFILE_MAX; cmd++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) 		if (strncmp(buffer, snc_thermal_profiles[cmd], len) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) 	if (sony_nc_thermal_mode_set(cmd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) static ssize_t sony_nc_thermal_mode_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) 		struct device_attribute *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) 	ssize_t count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) 	int mode = sony_nc_thermal_mode_get();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) 	if (mode < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) 		return mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) 	count = snprintf(buffer, PAGE_SIZE, "%s\n", snc_thermal_profiles[mode]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) static int sony_nc_thermal_setup(struct platform_device *pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) 	th_handle = kzalloc(sizeof(struct snc_thermal_ctrl), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) 	if (!th_handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) 	ret = sony_call_snc_handle(0x0122, 0x0000, &th_handle->profiles);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) 		pr_warn("couldn't to read the thermal profiles\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) 		goto outkzalloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) 	ret = sony_nc_thermal_mode_get();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) 		pr_warn("couldn't to read the current thermal profile");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) 		goto outkzalloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) 	th_handle->mode = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) 	sysfs_attr_init(&th_handle->profiles_attr.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) 	th_handle->profiles_attr.attr.name = "thermal_profiles";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) 	th_handle->profiles_attr.attr.mode = S_IRUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) 	th_handle->profiles_attr.show = sony_nc_thermal_profiles_show;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) 	sysfs_attr_init(&th_handle->mode_attr.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) 	th_handle->mode_attr.attr.name = "thermal_control";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) 	th_handle->mode_attr.attr.mode = S_IRUGO | S_IWUSR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) 	th_handle->mode_attr.show = sony_nc_thermal_mode_show;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) 	th_handle->mode_attr.store = sony_nc_thermal_mode_store;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) 	ret = device_create_file(&pd->dev, &th_handle->profiles_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) 		goto outkzalloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) 	ret = device_create_file(&pd->dev, &th_handle->mode_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) 		goto outprofiles;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) outprofiles:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) 	device_remove_file(&pd->dev, &th_handle->profiles_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) outkzalloc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) 	kfree(th_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) 	th_handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) static void sony_nc_thermal_cleanup(struct platform_device *pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) 	if (th_handle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) 		device_remove_file(&pd->dev, &th_handle->profiles_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) 		device_remove_file(&pd->dev, &th_handle->mode_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) 		kfree(th_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) 		th_handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) static void sony_nc_thermal_resume(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) 	if (!th_handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) 	status = sony_nc_thermal_mode_get();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) 	if (status != th_handle->mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) 		sony_nc_thermal_mode_set(th_handle->mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) /* resume on LID open */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) #define LID_RESUME_S5	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) #define LID_RESUME_S4	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) #define LID_RESUME_S3	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) #define LID_RESUME_MAX	3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) struct snc_lid_resume_control {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) 	struct device_attribute attrs[LID_RESUME_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) 	unsigned int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) 	int handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) static struct snc_lid_resume_control *lid_ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) static ssize_t sony_nc_lid_resume_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) 					struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) 					const char *buffer, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) 	unsigned int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) 	unsigned long value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) 	unsigned int pos = LID_RESUME_S5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) 	if (count > 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) 	if (kstrtoul(buffer, 10, &value) || value > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) 	/* the value we have to write to SNC is a bitmask:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) 	 * +--------------+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) 	 * | S3 | S4 | S5 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) 	 * +--------------+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) 	 *   2    1    0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) 	while (pos < LID_RESUME_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) 		if (&lid_ctl->attrs[pos].attr == &attr->attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) 		pos++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) 	if (pos == LID_RESUME_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) 	if (value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) 		value = lid_ctl->status | (1 << pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) 		value = lid_ctl->status & ~(1 << pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) 	if (sony_call_snc_handle(lid_ctl->handle, value << 0x10 | 0x0100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) 				&result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) 	lid_ctl->status = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) static ssize_t sony_nc_lid_resume_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) 					struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) 					char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) 	unsigned int pos = LID_RESUME_S5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) 	while (pos < LID_RESUME_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) 		if (&lid_ctl->attrs[pos].attr == &attr->attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) 			return snprintf(buffer, PAGE_SIZE, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) 					(lid_ctl->status >> pos) & 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) 		pos++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) static int sony_nc_lid_resume_setup(struct platform_device *pd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) 					unsigned int handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) 	unsigned int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) 	if (sony_call_snc_handle(handle, 0x0000, &result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) 	lid_ctl = kzalloc(sizeof(struct snc_lid_resume_control), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) 	if (!lid_ctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) 	lid_ctl->status = result & 0x7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) 	lid_ctl->handle = handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) 	sysfs_attr_init(&lid_ctl->attrs[0].attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) 	lid_ctl->attrs[LID_RESUME_S5].attr.name = "lid_resume_S5";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) 	lid_ctl->attrs[LID_RESUME_S5].attr.mode = S_IRUGO | S_IWUSR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) 	lid_ctl->attrs[LID_RESUME_S5].show = sony_nc_lid_resume_show;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) 	lid_ctl->attrs[LID_RESUME_S5].store = sony_nc_lid_resume_store;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) 	if (handle == 0x0119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) 		sysfs_attr_init(&lid_ctl->attrs[1].attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) 		lid_ctl->attrs[LID_RESUME_S4].attr.name = "lid_resume_S4";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) 		lid_ctl->attrs[LID_RESUME_S4].attr.mode = S_IRUGO | S_IWUSR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) 		lid_ctl->attrs[LID_RESUME_S4].show = sony_nc_lid_resume_show;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) 		lid_ctl->attrs[LID_RESUME_S4].store = sony_nc_lid_resume_store;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) 		sysfs_attr_init(&lid_ctl->attrs[2].attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) 		lid_ctl->attrs[LID_RESUME_S3].attr.name = "lid_resume_S3";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) 		lid_ctl->attrs[LID_RESUME_S3].attr.mode = S_IRUGO | S_IWUSR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) 		lid_ctl->attrs[LID_RESUME_S3].show = sony_nc_lid_resume_show;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) 		lid_ctl->attrs[LID_RESUME_S3].store = sony_nc_lid_resume_store;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) 	for (i = 0; i < LID_RESUME_MAX &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) 			lid_ctl->attrs[i].attr.name; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) 		result = device_create_file(&pd->dev, &lid_ctl->attrs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) 		if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) 			goto liderror;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) liderror:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) 	for (i--; i >= 0; i--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) 		device_remove_file(&pd->dev, &lid_ctl->attrs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) 	kfree(lid_ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) 	lid_ctl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) static void sony_nc_lid_resume_cleanup(struct platform_device *pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) 	if (lid_ctl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) 		for (i = 0; i < LID_RESUME_MAX; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) 			if (!lid_ctl->attrs[i].attr.name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) 			device_remove_file(&pd->dev, &lid_ctl->attrs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) 		kfree(lid_ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) 		lid_ctl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) /* GFX Switch position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) enum gfx_switch {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) 	SPEED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) 	STAMINA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) 	AUTO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) struct snc_gfx_switch_control {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) 	struct device_attribute attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) 	unsigned int handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) static struct snc_gfx_switch_control *gfxs_ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) /* returns 0 for speed, 1 for stamina */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) static int __sony_nc_gfx_switch_status_get(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) 	unsigned int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) 	if (sony_call_snc_handle(gfxs_ctl->handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) 				gfxs_ctl->handle == 0x015B ? 0x0000 : 0x0100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) 				&result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) 	switch (gfxs_ctl->handle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) 	case 0x0146:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) 		/* 1: discrete GFX (speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) 		 * 0: integrated GFX (stamina)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) 		return result & 0x1 ? SPEED : STAMINA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) 	case 0x015B:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) 		/* 0: discrete GFX (speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) 		 * 1: integrated GFX (stamina)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) 		return result & 0x1 ? STAMINA : SPEED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) 	case 0x0128:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) 		/* it's a more elaborated bitmask, for now:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) 		 * 2: integrated GFX (stamina)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) 		 * 0: discrete GFX (speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) 		dprintk("GFX Status: 0x%x\n", result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) 		return result & 0x80 ? AUTO :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) 			result & 0x02 ? STAMINA : SPEED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) static ssize_t sony_nc_gfx_switch_status_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) 				       struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) 				       char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) 	int pos = __sony_nc_gfx_switch_status_get();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) 	if (pos < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) 		return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) 	return snprintf(buffer, PAGE_SIZE, "%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) 					pos == SPEED ? "speed" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) 					pos == STAMINA ? "stamina" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) 					pos == AUTO ? "auto" : "unknown");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) static int sony_nc_gfx_switch_setup(struct platform_device *pd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) 		unsigned int handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) 	unsigned int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) 	gfxs_ctl = kzalloc(sizeof(struct snc_gfx_switch_control), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) 	if (!gfxs_ctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) 	gfxs_ctl->handle = handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) 	sysfs_attr_init(&gfxs_ctl->attr.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) 	gfxs_ctl->attr.attr.name = "gfx_switch_status";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) 	gfxs_ctl->attr.attr.mode = S_IRUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) 	gfxs_ctl->attr.show = sony_nc_gfx_switch_status_show;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) 	result = device_create_file(&pd->dev, &gfxs_ctl->attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) 		goto gfxerror;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) gfxerror:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) 	kfree(gfxs_ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) 	gfxs_ctl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) 	if (gfxs_ctl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) 		device_remove_file(&pd->dev, &gfxs_ctl->attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) 		kfree(gfxs_ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) 		gfxs_ctl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) /* High speed charging function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) static struct device_attribute *hsc_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) 		struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) 		const char *buffer, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) 	unsigned int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) 	unsigned long value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) 	if (count > 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) 	if (kstrtoul(buffer, 10, &value) || value > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) 	if (sony_call_snc_handle(0x0131, value << 0x10 | 0x0200, &result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) static ssize_t sony_nc_highspeed_charging_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) 		struct device_attribute *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) 	unsigned int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) 	if (sony_call_snc_handle(0x0131, 0x0100, &result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) 	return snprintf(buffer, PAGE_SIZE, "%d\n", result & 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) static int sony_nc_highspeed_charging_setup(struct platform_device *pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) 	unsigned int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) 	if (sony_call_snc_handle(0x0131, 0x0000, &result) || !(result & 0x01)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) 		/* some models advertise the handle but have no implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) 		 * for it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) 		pr_info("No High Speed Charging capability found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) 	hsc_handle = kzalloc(sizeof(struct device_attribute), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) 	if (!hsc_handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) 	sysfs_attr_init(&hsc_handle->attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) 	hsc_handle->attr.name = "battery_highspeed_charging";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) 	hsc_handle->attr.mode = S_IRUGO | S_IWUSR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) 	hsc_handle->show = sony_nc_highspeed_charging_show;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) 	hsc_handle->store = sony_nc_highspeed_charging_store;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) 	result = device_create_file(&pd->dev, hsc_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) 		kfree(hsc_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) 		hsc_handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) 	if (hsc_handle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) 		device_remove_file(&pd->dev, hsc_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) 		kfree(hsc_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) 		hsc_handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) /* low battery function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) static struct device_attribute *lowbatt_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) static ssize_t sony_nc_lowbatt_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) 		struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) 		const char *buffer, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) 	unsigned int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) 	unsigned long value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) 	if (count > 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) 	if (kstrtoul(buffer, 10, &value) || value > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) 	if (sony_call_snc_handle(0x0121, value << 8, &result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) static ssize_t sony_nc_lowbatt_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) 		struct device_attribute *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) 	unsigned int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) 	if (sony_call_snc_handle(0x0121, 0x0200, &result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) 	return snprintf(buffer, PAGE_SIZE, "%d\n", result & 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) static int sony_nc_lowbatt_setup(struct platform_device *pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) 	unsigned int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) 	lowbatt_handle = kzalloc(sizeof(struct device_attribute), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) 	if (!lowbatt_handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) 	sysfs_attr_init(&lowbatt_handle->attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) 	lowbatt_handle->attr.name = "lowbatt_hibernate";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) 	lowbatt_handle->attr.mode = S_IRUGO | S_IWUSR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) 	lowbatt_handle->show = sony_nc_lowbatt_show;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) 	lowbatt_handle->store = sony_nc_lowbatt_store;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) 	result = device_create_file(&pd->dev, lowbatt_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) 		kfree(lowbatt_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) 		lowbatt_handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) 	if (lowbatt_handle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) 		device_remove_file(&pd->dev, lowbatt_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) 		kfree(lowbatt_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) 		lowbatt_handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) /* fan speed function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) static struct device_attribute *fan_handle, *hsf_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) static ssize_t sony_nc_hsfan_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) 		struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) 		const char *buffer, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) 	unsigned int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) 	unsigned long value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) 	if (count > 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) 	if (kstrtoul(buffer, 10, &value) || value > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) 	if (sony_call_snc_handle(0x0149, value << 0x10 | 0x0200, &result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) static ssize_t sony_nc_hsfan_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) 		struct device_attribute *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) 	unsigned int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) 	if (sony_call_snc_handle(0x0149, 0x0100, &result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) 	return snprintf(buffer, PAGE_SIZE, "%d\n", result & 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) static ssize_t sony_nc_fanspeed_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) 		struct device_attribute *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) 	unsigned int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) 	if (sony_call_snc_handle(0x0149, 0x0300, &result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) 	return snprintf(buffer, PAGE_SIZE, "%d\n", result & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) static int sony_nc_fanspeed_setup(struct platform_device *pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) 	unsigned int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) 	fan_handle = kzalloc(sizeof(struct device_attribute), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) 	if (!fan_handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) 	hsf_handle = kzalloc(sizeof(struct device_attribute), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) 	if (!hsf_handle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) 		result = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) 		goto out_hsf_handle_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) 	sysfs_attr_init(&fan_handle->attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) 	fan_handle->attr.name = "fanspeed";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) 	fan_handle->attr.mode = S_IRUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) 	fan_handle->show = sony_nc_fanspeed_show;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) 	fan_handle->store = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) 	sysfs_attr_init(&hsf_handle->attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) 	hsf_handle->attr.name = "fan_forced";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) 	hsf_handle->attr.mode = S_IRUGO | S_IWUSR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) 	hsf_handle->show = sony_nc_hsfan_show;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) 	hsf_handle->store = sony_nc_hsfan_store;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) 	result = device_create_file(&pd->dev, fan_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) 		goto out_fan_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) 	result = device_create_file(&pd->dev, hsf_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) 		goto out_hsf_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) out_hsf_handle:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) 	device_remove_file(&pd->dev, fan_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) out_fan_handle:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) 	kfree(hsf_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) 	hsf_handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) out_hsf_handle_alloc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) 	kfree(fan_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) 	fan_handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) 	if (fan_handle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) 		device_remove_file(&pd->dev, fan_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) 		kfree(fan_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) 		fan_handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) 	if (hsf_handle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) 		device_remove_file(&pd->dev, hsf_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) 		kfree(hsf_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) 		hsf_handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) /* USB charge function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) static struct device_attribute *uc_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) static ssize_t sony_nc_usb_charge_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) 		struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) 		const char *buffer, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) 	unsigned int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) 	unsigned long value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) 	if (count > 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) 	if (kstrtoul(buffer, 10, &value) || value > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) 	if (sony_call_snc_handle(0x0155, value << 0x10 | 0x0100, &result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) static ssize_t sony_nc_usb_charge_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) 		struct device_attribute *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) 	unsigned int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) 	if (sony_call_snc_handle(0x0155, 0x0000, &result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) 	return snprintf(buffer, PAGE_SIZE, "%d\n", result & 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) static int sony_nc_usb_charge_setup(struct platform_device *pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) 	unsigned int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) 	if (sony_call_snc_handle(0x0155, 0x0000, &result) || !(result & 0x01)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) 		/* some models advertise the handle but have no implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) 		 * for it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) 		pr_info("No USB Charge capability found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) 	uc_handle = kzalloc(sizeof(struct device_attribute), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) 	if (!uc_handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) 	sysfs_attr_init(&uc_handle->attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) 	uc_handle->attr.name = "usb_charge";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) 	uc_handle->attr.mode = S_IRUGO | S_IWUSR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) 	uc_handle->show = sony_nc_usb_charge_show;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) 	uc_handle->store = sony_nc_usb_charge_store;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) 	result = device_create_file(&pd->dev, uc_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) 		kfree(uc_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) 		uc_handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) 	if (uc_handle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) 		device_remove_file(&pd->dev, uc_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) 		kfree(uc_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) 		uc_handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) /* Panel ID function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) static struct device_attribute *panel_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) static ssize_t sony_nc_panelid_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) 		struct device_attribute *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) 	unsigned int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) 	if (sony_call_snc_handle(0x011D, 0x0000, &result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) 	return snprintf(buffer, PAGE_SIZE, "%d\n", result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) static int sony_nc_panelid_setup(struct platform_device *pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) 	unsigned int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) 	panel_handle = kzalloc(sizeof(struct device_attribute), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) 	if (!panel_handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) 	sysfs_attr_init(&panel_handle->attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) 	panel_handle->attr.name = "panel_id";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) 	panel_handle->attr.mode = S_IRUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) 	panel_handle->show = sony_nc_panelid_show;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) 	panel_handle->store = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) 	result = device_create_file(&pd->dev, panel_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) 		kfree(panel_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) 		panel_handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) static void sony_nc_panelid_cleanup(struct platform_device *pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) 	if (panel_handle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) 		device_remove_file(&pd->dev, panel_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) 		kfree(panel_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) 		panel_handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) /* smart connect function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) static struct device_attribute *sc_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) static ssize_t sony_nc_smart_conn_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) 		struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) 		const char *buffer, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) 	unsigned int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) 	unsigned long value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) 	if (count > 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) 	if (kstrtoul(buffer, 10, &value) || value > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928) 	if (sony_call_snc_handle(0x0168, value << 0x10, &result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) static int sony_nc_smart_conn_setup(struct platform_device *pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) 	unsigned int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) 	sc_handle = kzalloc(sizeof(struct device_attribute), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) 	if (!sc_handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) 	sysfs_attr_init(&sc_handle->attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) 	sc_handle->attr.name = "smart_connect";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) 	sc_handle->attr.mode = S_IWUSR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) 	sc_handle->show = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) 	sc_handle->store = sony_nc_smart_conn_store;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) 	result = device_create_file(&pd->dev, sc_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) 		kfree(sc_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) 		sc_handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) static void sony_nc_smart_conn_cleanup(struct platform_device *pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) 	if (sc_handle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961) 		device_remove_file(&pd->dev, sc_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) 		kfree(sc_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) 		sc_handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) /* Touchpad enable/disable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) struct touchpad_control {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969) 	struct device_attribute attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) 	int handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) static struct touchpad_control *tp_ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) static ssize_t sony_nc_touchpad_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) 		struct device_attribute *attr, const char *buffer, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) 	unsigned int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) 	unsigned long value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) 	if (count > 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) 	if (kstrtoul(buffer, 10, &value) || value > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) 	/* sysfs: 0 disabled, 1 enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) 	 * EC: 0 enabled, 1 disabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) 	if (sony_call_snc_handle(tp_ctl->handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) 				(!value << 0x10) | 0x100, &result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) static ssize_t sony_nc_touchpad_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997) 		struct device_attribute *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) 	unsigned int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001) 	if (sony_call_snc_handle(tp_ctl->handle, 0x000, &result))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) 	return snprintf(buffer, PAGE_SIZE, "%d\n", !(result & 0x01));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) static int sony_nc_touchpad_setup(struct platform_device *pd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) 		unsigned int handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) 	tp_ctl = kzalloc(sizeof(struct touchpad_control), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) 	if (!tp_ctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) 	tp_ctl->handle = handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018) 	sysfs_attr_init(&tp_ctl->attr.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) 	tp_ctl->attr.attr.name = "touchpad";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020) 	tp_ctl->attr.attr.mode = S_IRUGO | S_IWUSR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) 	tp_ctl->attr.show = sony_nc_touchpad_show;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022) 	tp_ctl->attr.store = sony_nc_touchpad_store;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) 	ret = device_create_file(&pd->dev, &tp_ctl->attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) 		kfree(tp_ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) 		tp_ctl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) static void sony_nc_touchpad_cleanup(struct platform_device *pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) 	if (tp_ctl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) 		device_remove_file(&pd->dev, &tp_ctl->attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) 		kfree(tp_ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) 		tp_ctl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) static void sony_nc_backlight_ng_read_limits(int handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043) 		struct sony_backlight_props *props)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) 	u64 offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047) 	int lvl_table_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) 	u8 min = 0xff, max = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049) 	unsigned char buffer[32] = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051) 	props->handle = handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) 	props->offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053) 	props->maxlvl = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055) 	offset = sony_find_snc_handle(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057) 	/* try to read the boundaries from ACPI tables, if we fail the above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058) 	 * defaults should be reasonable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) 	i = sony_nc_buffer_call(sony_nc_acpi_handle, "SN06", &offset, buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) 			32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) 	if (i < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065) 	switch (handle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) 	case 0x012f:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) 	case 0x0137:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) 		lvl_table_len = 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070) 	case 0x143:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071) 	case 0x14b:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) 	case 0x14c:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073) 		lvl_table_len = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077) 	/* the buffer lists brightness levels available, brightness levels are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) 	 * from position 0 to 8 in the array, other values are used by ALS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079) 	 * control.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081) 	for (i = 0; i < lvl_table_len && i < ARRAY_SIZE(buffer); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083) 		dprintk("Brightness level: %d\n", buffer[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) 		if (!buffer[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088) 		if (buffer[i] > max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089) 			max = buffer[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090) 		if (buffer[i] < min)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091) 			min = buffer[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093) 	props->offset = min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094) 	props->maxlvl = max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) 	dprintk("Brightness levels: min=%d max=%d\n", props->offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096) 			props->maxlvl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099) static void sony_nc_backlight_setup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101) 	int max_brightness = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) 	const struct backlight_ops *ops = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103) 	struct backlight_properties props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105) 	if (sony_find_snc_handle(0x12f) >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106) 		ops = &sony_backlight_ng_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107) 		sony_bl_props.cmd_base = 0x0100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108) 		sony_nc_backlight_ng_read_limits(0x12f, &sony_bl_props);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109) 		max_brightness = sony_bl_props.maxlvl - sony_bl_props.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111) 	} else if (sony_find_snc_handle(0x137) >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112) 		ops = &sony_backlight_ng_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113) 		sony_bl_props.cmd_base = 0x0100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114) 		sony_nc_backlight_ng_read_limits(0x137, &sony_bl_props);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115) 		max_brightness = sony_bl_props.maxlvl - sony_bl_props.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117) 	} else if (sony_find_snc_handle(0x143) >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118) 		ops = &sony_backlight_ng_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) 		sony_bl_props.cmd_base = 0x3000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120) 		sony_nc_backlight_ng_read_limits(0x143, &sony_bl_props);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121) 		max_brightness = sony_bl_props.maxlvl - sony_bl_props.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) 	} else if (sony_find_snc_handle(0x14b) >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124) 		ops = &sony_backlight_ng_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) 		sony_bl_props.cmd_base = 0x3000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126) 		sony_nc_backlight_ng_read_limits(0x14b, &sony_bl_props);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127) 		max_brightness = sony_bl_props.maxlvl - sony_bl_props.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129) 	} else if (sony_find_snc_handle(0x14c) >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130) 		ops = &sony_backlight_ng_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131) 		sony_bl_props.cmd_base = 0x3000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132) 		sony_nc_backlight_ng_read_limits(0x14c, &sony_bl_props);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133) 		max_brightness = sony_bl_props.maxlvl - sony_bl_props.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) 	} else if (acpi_has_method(sony_nc_acpi_handle, "GBRT")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136) 		ops = &sony_backlight_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) 		max_brightness = SONY_MAX_BRIGHTNESS - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142) 	memset(&props, 0, sizeof(struct backlight_properties));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143) 	props.type = BACKLIGHT_PLATFORM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144) 	props.max_brightness = max_brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145) 	sony_bl_props.dev = backlight_device_register("sony", NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146) 						      &sony_bl_props,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147) 						      ops, &props);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149) 	if (IS_ERR(sony_bl_props.dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150) 		pr_warn("unable to register backlight device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) 		sony_bl_props.dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153) 		sony_bl_props.dev->props.brightness =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154) 			ops->get_brightness(sony_bl_props.dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157) static void sony_nc_backlight_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159) 	backlight_device_unregister(sony_bl_props.dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162) static int sony_nc_add(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165) 	int result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) 	struct sony_nc_value *item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168) 	sony_nc_acpi_device = device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169) 	strcpy(acpi_device_class(device), "sony/hotkey");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171) 	sony_nc_acpi_handle = device->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) 	/* read device status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) 	result = acpi_bus_get_status(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175) 	/* bail IFF the above call was successful and the device is not present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176) 	if (!result && !device->status.present) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177) 		dprintk("Device not present\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178) 		result = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179) 		goto outwalk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182) 	result = sony_pf_add();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184) 		goto outpresent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186) 	if (debug) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187) 		status = acpi_walk_namespace(ACPI_TYPE_METHOD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188) 				sony_nc_acpi_handle, 1, sony_walk_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189) 				NULL, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190) 		if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) 			pr_warn("unable to walk acpi resources\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192) 			result = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193) 			goto outpresent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197) 	result = sony_laptop_setup_input(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199) 		pr_err("Unable to create input devices\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200) 		goto outplatform;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203) 	if (acpi_has_method(sony_nc_acpi_handle, "ECON")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204) 		int arg = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205) 		if (sony_nc_int_call(sony_nc_acpi_handle, "ECON", &arg, NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) 			dprintk("ECON Method failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209) 	if (acpi_has_method(sony_nc_acpi_handle, "SN00")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210) 		dprintk("Doing SNC setup\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211) 		/* retrieve the available handles */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212) 		result = sony_nc_handles_setup(sony_pf_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213) 		if (!result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214) 			sony_nc_function_setup(device, sony_pf_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217) 	if (acpi_video_get_backlight_type() == acpi_backlight_vendor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218) 		sony_nc_backlight_setup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220) 	/* create sony_pf sysfs attributes related to the SNC device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221) 	for (item = sony_nc_values; item->name; ++item) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223) 		if (!debug && item->debug)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226) 		/* find the available acpiget as described in the DSDT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227) 		for (; item->acpiget && *item->acpiget; ++item->acpiget) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228) 			if (acpi_has_method(sony_nc_acpi_handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229) 							*item->acpiget)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230) 				dprintk("Found %s getter: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231) 						item->name, *item->acpiget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232) 				item->devattr.attr.mode |= S_IRUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3237) 		/* find the available acpiset as described in the DSDT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3238) 		for (; item->acpiset && *item->acpiset; ++item->acpiset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3239) 			if (acpi_has_method(sony_nc_acpi_handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3240) 							*item->acpiset)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3241) 				dprintk("Found %s setter: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3242) 						item->name, *item->acpiset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3243) 				item->devattr.attr.mode |= S_IWUSR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3244) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3245) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3246) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3248) 		if (item->devattr.attr.mode != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3249) 			result =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3250) 			    device_create_file(&sony_pf_device->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3251) 					       &item->devattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3252) 			if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3253) 				goto out_sysfs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3254) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3255) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3257) 	pr_info("SNC setup done.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3258) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3260) out_sysfs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3261) 	for (item = sony_nc_values; item->name; ++item) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3262) 		device_remove_file(&sony_pf_device->dev, &item->devattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3263) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3264) 	sony_nc_backlight_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3265) 	sony_nc_function_cleanup(sony_pf_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3266) 	sony_nc_handles_cleanup(sony_pf_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3268) outplatform:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3269) 	sony_laptop_remove_input();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3271) outpresent:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3272) 	sony_pf_remove();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3274) outwalk:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3275) 	sony_nc_rfkill_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3276) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3279) static int sony_nc_remove(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3281) 	struct sony_nc_value *item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3283) 	sony_nc_backlight_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3285) 	sony_nc_acpi_device = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3287) 	for (item = sony_nc_values; item->name; ++item) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3288) 		device_remove_file(&sony_pf_device->dev, &item->devattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3289) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3291) 	sony_nc_function_cleanup(sony_pf_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3292) 	sony_nc_handles_cleanup(sony_pf_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3293) 	sony_pf_remove();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3294) 	sony_laptop_remove_input();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3295) 	dprintk(SONY_NC_DRIVER_NAME " removed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3297) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3300) static const struct acpi_device_id sony_device_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3301) 	{SONY_NC_HID, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3302) 	{SONY_PIC_HID, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3303) 	{"", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3304) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3305) MODULE_DEVICE_TABLE(acpi, sony_device_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3307) static const struct acpi_device_id sony_nc_device_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3308) 	{SONY_NC_HID, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3309) 	{"", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3310) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3312) static struct acpi_driver sony_nc_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3313) 	.name = SONY_NC_DRIVER_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3314) 	.class = SONY_NC_CLASS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3315) 	.ids = sony_nc_device_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3316) 	.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3317) 	.ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3318) 		.add = sony_nc_add,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3319) 		.remove = sony_nc_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3320) 		.notify = sony_nc_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3321) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3322) 	.drv.pm = &sony_nc_pm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3323) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3325) /*********** SPIC (SNY6001) Device ***********/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3327) #define SONYPI_DEVICE_TYPE1	0x00000001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3328) #define SONYPI_DEVICE_TYPE2	0x00000002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3329) #define SONYPI_DEVICE_TYPE3	0x00000004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3331) #define SONYPI_TYPE1_OFFSET	0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3332) #define SONYPI_TYPE2_OFFSET	0x12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3333) #define SONYPI_TYPE3_OFFSET	0x12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3335) struct sony_pic_ioport {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3336) 	struct acpi_resource_io	io1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3337) 	struct acpi_resource_io	io2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3338) 	struct list_head	list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3339) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3341) struct sony_pic_irq {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3342) 	struct acpi_resource_irq	irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3343) 	struct list_head		list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3344) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3346) struct sonypi_eventtypes {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3347) 	u8			data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3348) 	unsigned long		mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3349) 	struct sonypi_event	*events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3350) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3352) struct sony_pic_dev {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3353) 	struct acpi_device		*acpi_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3354) 	struct sony_pic_irq		*cur_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3355) 	struct sony_pic_ioport		*cur_ioport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3356) 	struct list_head		interrupts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3357) 	struct list_head		ioports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3358) 	struct mutex			lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3359) 	struct sonypi_eventtypes	*event_types;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3360) 	int                             (*handle_irq)(const u8, const u8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3361) 	int				model;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3362) 	u16				evport_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3363) 	u8				camera_power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3364) 	u8				bluetooth_power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3365) 	u8				wwan_power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3366) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3368) static struct sony_pic_dev spic_dev = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3369) 	.interrupts	= LIST_HEAD_INIT(spic_dev.interrupts),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3370) 	.ioports	= LIST_HEAD_INIT(spic_dev.ioports),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3371) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3373) static int spic_drv_registered;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3375) /* Event masks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3376) #define SONYPI_JOGGER_MASK			0x00000001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3377) #define SONYPI_CAPTURE_MASK			0x00000002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3378) #define SONYPI_FNKEY_MASK			0x00000004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3379) #define SONYPI_BLUETOOTH_MASK			0x00000008
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3380) #define SONYPI_PKEY_MASK			0x00000010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3381) #define SONYPI_BACK_MASK			0x00000020
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3382) #define SONYPI_HELP_MASK			0x00000040
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3383) #define SONYPI_LID_MASK				0x00000080
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3384) #define SONYPI_ZOOM_MASK			0x00000100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3385) #define SONYPI_THUMBPHRASE_MASK			0x00000200
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3386) #define SONYPI_MEYE_MASK			0x00000400
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3387) #define SONYPI_MEMORYSTICK_MASK			0x00000800
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3388) #define SONYPI_BATTERY_MASK			0x00001000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3389) #define SONYPI_WIRELESS_MASK			0x00002000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3391) struct sonypi_event {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3392) 	u8	data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3393) 	u8	event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3394) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3396) /* The set of possible button release events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3397) static struct sonypi_event sonypi_releaseev[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3398) 	{ 0x00, SONYPI_EVENT_ANYBUTTON_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3399) 	{ 0, 0 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3400) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3402) /* The set of possible jogger events  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3403) static struct sonypi_event sonypi_joggerev[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3404) 	{ 0x1f, SONYPI_EVENT_JOGDIAL_UP },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3405) 	{ 0x01, SONYPI_EVENT_JOGDIAL_DOWN },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3406) 	{ 0x5f, SONYPI_EVENT_JOGDIAL_UP_PRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3407) 	{ 0x41, SONYPI_EVENT_JOGDIAL_DOWN_PRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3408) 	{ 0x1e, SONYPI_EVENT_JOGDIAL_FAST_UP },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3409) 	{ 0x02, SONYPI_EVENT_JOGDIAL_FAST_DOWN },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3410) 	{ 0x5e, SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3411) 	{ 0x42, SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3412) 	{ 0x1d, SONYPI_EVENT_JOGDIAL_VFAST_UP },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3413) 	{ 0x03, SONYPI_EVENT_JOGDIAL_VFAST_DOWN },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3414) 	{ 0x5d, SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3415) 	{ 0x43, SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3416) 	{ 0x40, SONYPI_EVENT_JOGDIAL_PRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3417) 	{ 0, 0 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3418) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3420) /* The set of possible capture button events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3421) static struct sonypi_event sonypi_captureev[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3422) 	{ 0x05, SONYPI_EVENT_CAPTURE_PARTIALPRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3423) 	{ 0x07, SONYPI_EVENT_CAPTURE_PRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3424) 	{ 0x40, SONYPI_EVENT_CAPTURE_PRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3425) 	{ 0x01, SONYPI_EVENT_CAPTURE_PARTIALRELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3426) 	{ 0, 0 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3427) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3429) /* The set of possible fnkeys events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3430) static struct sonypi_event sonypi_fnkeyev[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3431) 	{ 0x10, SONYPI_EVENT_FNKEY_ESC },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3432) 	{ 0x11, SONYPI_EVENT_FNKEY_F1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3433) 	{ 0x12, SONYPI_EVENT_FNKEY_F2 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3434) 	{ 0x13, SONYPI_EVENT_FNKEY_F3 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3435) 	{ 0x14, SONYPI_EVENT_FNKEY_F4 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3436) 	{ 0x15, SONYPI_EVENT_FNKEY_F5 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3437) 	{ 0x16, SONYPI_EVENT_FNKEY_F6 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3438) 	{ 0x17, SONYPI_EVENT_FNKEY_F7 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3439) 	{ 0x18, SONYPI_EVENT_FNKEY_F8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3440) 	{ 0x19, SONYPI_EVENT_FNKEY_F9 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3441) 	{ 0x1a, SONYPI_EVENT_FNKEY_F10 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3442) 	{ 0x1b, SONYPI_EVENT_FNKEY_F11 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3443) 	{ 0x1c, SONYPI_EVENT_FNKEY_F12 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3444) 	{ 0x1f, SONYPI_EVENT_FNKEY_RELEASED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3445) 	{ 0x21, SONYPI_EVENT_FNKEY_1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3446) 	{ 0x22, SONYPI_EVENT_FNKEY_2 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3447) 	{ 0x31, SONYPI_EVENT_FNKEY_D },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3448) 	{ 0x32, SONYPI_EVENT_FNKEY_E },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3449) 	{ 0x33, SONYPI_EVENT_FNKEY_F },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3450) 	{ 0x34, SONYPI_EVENT_FNKEY_S },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3451) 	{ 0x35, SONYPI_EVENT_FNKEY_B },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3452) 	{ 0x36, SONYPI_EVENT_FNKEY_ONLY },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3453) 	{ 0, 0 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3454) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3456) /* The set of possible program key events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3457) static struct sonypi_event sonypi_pkeyev[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3458) 	{ 0x01, SONYPI_EVENT_PKEY_P1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3459) 	{ 0x02, SONYPI_EVENT_PKEY_P2 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3460) 	{ 0x04, SONYPI_EVENT_PKEY_P3 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3461) 	{ 0x20, SONYPI_EVENT_PKEY_P1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3462) 	{ 0, 0 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3463) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3465) /* The set of possible bluetooth events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3466) static struct sonypi_event sonypi_blueev[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3467) 	{ 0x55, SONYPI_EVENT_BLUETOOTH_PRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3468) 	{ 0x59, SONYPI_EVENT_BLUETOOTH_ON },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3469) 	{ 0x5a, SONYPI_EVENT_BLUETOOTH_OFF },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3470) 	{ 0, 0 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3471) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3473) /* The set of possible wireless events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3474) static struct sonypi_event sonypi_wlessev[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3475) 	{ 0x59, SONYPI_EVENT_IGNORE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3476) 	{ 0x5a, SONYPI_EVENT_IGNORE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3477) 	{ 0, 0 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3478) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3480) /* The set of possible back button events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3481) static struct sonypi_event sonypi_backev[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3482) 	{ 0x20, SONYPI_EVENT_BACK_PRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3483) 	{ 0, 0 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3484) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3486) /* The set of possible help button events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3487) static struct sonypi_event sonypi_helpev[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3488) 	{ 0x3b, SONYPI_EVENT_HELP_PRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3489) 	{ 0, 0 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3490) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3493) /* The set of possible lid events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3494) static struct sonypi_event sonypi_lidev[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3495) 	{ 0x51, SONYPI_EVENT_LID_CLOSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3496) 	{ 0x50, SONYPI_EVENT_LID_OPENED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3497) 	{ 0, 0 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3498) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3500) /* The set of possible zoom events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3501) static struct sonypi_event sonypi_zoomev[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3502) 	{ 0x39, SONYPI_EVENT_ZOOM_PRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3503) 	{ 0x10, SONYPI_EVENT_ZOOM_IN_PRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3504) 	{ 0x20, SONYPI_EVENT_ZOOM_OUT_PRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3505) 	{ 0x04, SONYPI_EVENT_ZOOM_PRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3506) 	{ 0, 0 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3507) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3509) /* The set of possible thumbphrase events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3510) static struct sonypi_event sonypi_thumbphraseev[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3511) 	{ 0x3a, SONYPI_EVENT_THUMBPHRASE_PRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3512) 	{ 0, 0 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3513) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3515) /* The set of possible motioneye camera events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3516) static struct sonypi_event sonypi_meyeev[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3517) 	{ 0x00, SONYPI_EVENT_MEYE_FACE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3518) 	{ 0x01, SONYPI_EVENT_MEYE_OPPOSITE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3519) 	{ 0, 0 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3520) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3522) /* The set of possible memorystick events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3523) static struct sonypi_event sonypi_memorystickev[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3524) 	{ 0x53, SONYPI_EVENT_MEMORYSTICK_INSERT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3525) 	{ 0x54, SONYPI_EVENT_MEMORYSTICK_EJECT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3526) 	{ 0, 0 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3527) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3529) /* The set of possible battery events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3530) static struct sonypi_event sonypi_batteryev[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3531) 	{ 0x20, SONYPI_EVENT_BATTERY_INSERT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3532) 	{ 0x30, SONYPI_EVENT_BATTERY_REMOVE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3533) 	{ 0, 0 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3534) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3536) /* The set of possible volume events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3537) static struct sonypi_event sonypi_volumeev[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3538) 	{ 0x01, SONYPI_EVENT_VOLUME_INC_PRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3539) 	{ 0x02, SONYPI_EVENT_VOLUME_DEC_PRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3540) 	{ 0, 0 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3541) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3543) /* The set of possible brightness events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3544) static struct sonypi_event sonypi_brightnessev[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3545) 	{ 0x80, SONYPI_EVENT_BRIGHTNESS_PRESSED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3546) 	{ 0, 0 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3547) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3549) static struct sonypi_eventtypes type1_events[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3550) 	{ 0, 0xffffffff, sonypi_releaseev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3551) 	{ 0x70, SONYPI_MEYE_MASK, sonypi_meyeev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3552) 	{ 0x30, SONYPI_LID_MASK, sonypi_lidev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3553) 	{ 0x60, SONYPI_CAPTURE_MASK, sonypi_captureev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3554) 	{ 0x10, SONYPI_JOGGER_MASK, sonypi_joggerev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3555) 	{ 0x20, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3556) 	{ 0x30, SONYPI_BLUETOOTH_MASK, sonypi_blueev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3557) 	{ 0x40, SONYPI_PKEY_MASK, sonypi_pkeyev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3558) 	{ 0x30, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3559) 	{ 0x40, SONYPI_BATTERY_MASK, sonypi_batteryev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3560) 	{ 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3561) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3562) static struct sonypi_eventtypes type2_events[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3563) 	{ 0, 0xffffffff, sonypi_releaseev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3564) 	{ 0x38, SONYPI_LID_MASK, sonypi_lidev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3565) 	{ 0x11, SONYPI_JOGGER_MASK, sonypi_joggerev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3566) 	{ 0x61, SONYPI_CAPTURE_MASK, sonypi_captureev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3567) 	{ 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3568) 	{ 0x31, SONYPI_BLUETOOTH_MASK, sonypi_blueev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3569) 	{ 0x08, SONYPI_PKEY_MASK, sonypi_pkeyev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3570) 	{ 0x11, SONYPI_BACK_MASK, sonypi_backev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3571) 	{ 0x21, SONYPI_HELP_MASK, sonypi_helpev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3572) 	{ 0x21, SONYPI_ZOOM_MASK, sonypi_zoomev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3573) 	{ 0x20, SONYPI_THUMBPHRASE_MASK, sonypi_thumbphraseev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3574) 	{ 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3575) 	{ 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3576) 	{ 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3577) 	{ 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3578) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3579) static struct sonypi_eventtypes type3_events[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3580) 	{ 0, 0xffffffff, sonypi_releaseev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3581) 	{ 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3582) 	{ 0x31, SONYPI_WIRELESS_MASK, sonypi_wlessev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3583) 	{ 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3584) 	{ 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3585) 	{ 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3586) 	{ 0x05, SONYPI_PKEY_MASK, sonypi_pkeyev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3587) 	{ 0x05, SONYPI_ZOOM_MASK, sonypi_zoomev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3588) 	{ 0x05, SONYPI_CAPTURE_MASK, sonypi_captureev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3589) 	{ 0x05, SONYPI_PKEY_MASK, sonypi_volumeev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3590) 	{ 0x05, SONYPI_PKEY_MASK, sonypi_brightnessev },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3591) 	{ 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3592) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3594) /* low level spic calls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3595) #define ITERATIONS_LONG		10000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3596) #define ITERATIONS_SHORT	10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3597) #define wait_on_command(command, iterations) {				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3598) 	unsigned int n = iterations;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3599) 	while (--n && (command))					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3600) 		udelay(1);						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3601) 	if (!n)								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3602) 		dprintk("command failed at %s : %s (line %d)\n",	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3603) 				__FILE__, __func__, __LINE__);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3604) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3606) static u8 sony_pic_call1(u8 dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3607) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3608) 	u8 v1, v2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3610) 	wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3611) 			ITERATIONS_LONG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3612) 	outb(dev, spic_dev.cur_ioport->io1.minimum + 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3613) 	v1 = inb_p(spic_dev.cur_ioport->io1.minimum + 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3614) 	v2 = inb_p(spic_dev.cur_ioport->io1.minimum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3615) 	dprintk("sony_pic_call1(0x%.2x): 0x%.4x\n", dev, (v2 << 8) | v1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3616) 	return v2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3619) static u8 sony_pic_call2(u8 dev, u8 fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3620) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3621) 	u8 v1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3623) 	wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3624) 			ITERATIONS_LONG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3625) 	outb(dev, spic_dev.cur_ioport->io1.minimum + 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3626) 	wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3627) 			ITERATIONS_LONG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3628) 	outb(fn, spic_dev.cur_ioport->io1.minimum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3629) 	v1 = inb_p(spic_dev.cur_ioport->io1.minimum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3630) 	dprintk("sony_pic_call2(0x%.2x - 0x%.2x): 0x%.4x\n", dev, fn, v1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3631) 	return v1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3634) static u8 sony_pic_call3(u8 dev, u8 fn, u8 v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3635) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3636) 	u8 v1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3638) 	wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2, ITERATIONS_LONG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3639) 	outb(dev, spic_dev.cur_ioport->io1.minimum + 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3640) 	wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2, ITERATIONS_LONG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3641) 	outb(fn, spic_dev.cur_ioport->io1.minimum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3642) 	wait_on_command(inb_p(spic_dev.cur_ioport->io1.minimum + 4) & 2, ITERATIONS_LONG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3643) 	outb(v, spic_dev.cur_ioport->io1.minimum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3644) 	v1 = inb_p(spic_dev.cur_ioport->io1.minimum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3645) 	dprintk("sony_pic_call3(0x%.2x - 0x%.2x - 0x%.2x): 0x%.4x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3646) 			dev, fn, v, v1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3647) 	return v1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3650) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3651)  * minidrivers for SPIC models
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3652)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3653) static int type3_handle_irq(const u8 data_mask, const u8 ev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3654) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3655) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3656) 	 * 0x31 could mean we have to take some extra action and wait for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3657) 	 * the next irq for some Type3 models, it will generate a new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3658) 	 * irq and we can read new data from the device:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3659) 	 *  - 0x5c and 0x5f requires 0xA0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3660) 	 *  - 0x61 requires 0xB3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3661) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3662) 	if (data_mask == 0x31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3663) 		if (ev == 0x5c || ev == 0x5f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3664) 			sony_pic_call1(0xA0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3665) 		else if (ev == 0x61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3666) 			sony_pic_call1(0xB3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3667) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3668) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3669) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3672) static void sony_pic_detect_device_type(struct sony_pic_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3673) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3674) 	struct pci_dev *pcidev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3676) 	pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3677) 			PCI_DEVICE_ID_INTEL_82371AB_3, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3678) 	if (pcidev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3679) 		dev->model = SONYPI_DEVICE_TYPE1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3680) 		dev->evport_offset = SONYPI_TYPE1_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3681) 		dev->event_types = type1_events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3682) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3683) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3685) 	pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3686) 			PCI_DEVICE_ID_INTEL_ICH6_1, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3687) 	if (pcidev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3688) 		dev->model = SONYPI_DEVICE_TYPE2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3689) 		dev->evport_offset = SONYPI_TYPE2_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3690) 		dev->event_types = type2_events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3691) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3692) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3694) 	pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3695) 			PCI_DEVICE_ID_INTEL_ICH7_1, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3696) 	if (pcidev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3697) 		dev->model = SONYPI_DEVICE_TYPE3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3698) 		dev->handle_irq = type3_handle_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3699) 		dev->evport_offset = SONYPI_TYPE3_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3700) 		dev->event_types = type3_events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3701) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3702) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3704) 	pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3705) 			PCI_DEVICE_ID_INTEL_ICH8_4, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3706) 	if (pcidev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3707) 		dev->model = SONYPI_DEVICE_TYPE3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3708) 		dev->handle_irq = type3_handle_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3709) 		dev->evport_offset = SONYPI_TYPE3_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3710) 		dev->event_types = type3_events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3711) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3712) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3714) 	pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3715) 			PCI_DEVICE_ID_INTEL_ICH9_1, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3716) 	if (pcidev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3717) 		dev->model = SONYPI_DEVICE_TYPE3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3718) 		dev->handle_irq = type3_handle_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3719) 		dev->evport_offset = SONYPI_TYPE3_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3720) 		dev->event_types = type3_events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3721) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3722) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3724) 	/* default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3725) 	dev->model = SONYPI_DEVICE_TYPE2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3726) 	dev->evport_offset = SONYPI_TYPE2_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3727) 	dev->event_types = type2_events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3729) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3730) 	pci_dev_put(pcidev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3732) 	pr_info("detected Type%d model\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3733) 		dev->model == SONYPI_DEVICE_TYPE1 ? 1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3734) 		dev->model == SONYPI_DEVICE_TYPE2 ? 2 : 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3737) /* camera tests and poweron/poweroff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3738) #define SONYPI_CAMERA_PICTURE		5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3739) #define SONYPI_CAMERA_CONTROL		0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3741) #define SONYPI_CAMERA_BRIGHTNESS		0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3742) #define SONYPI_CAMERA_CONTRAST			1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3743) #define SONYPI_CAMERA_HUE			2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3744) #define SONYPI_CAMERA_COLOR			3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3745) #define SONYPI_CAMERA_SHARPNESS			4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3747) #define SONYPI_CAMERA_EXPOSURE_MASK		0xC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3748) #define SONYPI_CAMERA_WHITE_BALANCE_MASK	0x3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3749) #define SONYPI_CAMERA_PICTURE_MODE_MASK		0x30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3750) #define SONYPI_CAMERA_MUTE_MASK			0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3752) /* the rest don't need a loop until not 0xff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3753) #define SONYPI_CAMERA_AGC			6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3754) #define SONYPI_CAMERA_AGC_MASK			0x30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3755) #define SONYPI_CAMERA_SHUTTER_MASK 		0x7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3757) #define SONYPI_CAMERA_SHUTDOWN_REQUEST		7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3758) #define SONYPI_CAMERA_CONTROL			0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3760) #define SONYPI_CAMERA_STATUS 			7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3761) #define SONYPI_CAMERA_STATUS_READY 		0x2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3762) #define SONYPI_CAMERA_STATUS_POSITION		0x4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3764) #define SONYPI_DIRECTION_BACKWARDS 		0x4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3765) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3766) #define SONYPI_CAMERA_REVISION 			8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3767) #define SONYPI_CAMERA_ROMVERSION 		9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3769) static int __sony_pic_camera_ready(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3770) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3771) 	u8 v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3773) 	v = sony_pic_call2(0x8f, SONYPI_CAMERA_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3774) 	return (v != 0xff && (v & SONYPI_CAMERA_STATUS_READY));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3775) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3777) static int __sony_pic_camera_off(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3778) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3779) 	if (!camera) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3780) 		pr_warn("camera control not enabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3781) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3782) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3784) 	wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3785) 				SONYPI_CAMERA_MUTE_MASK),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3786) 			ITERATIONS_SHORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3787) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3788) 	if (spic_dev.camera_power) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3789) 		sony_pic_call2(0x91, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3790) 		spic_dev.camera_power = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3791) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3792) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3795) static int __sony_pic_camera_on(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3796) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3797) 	int i, j, x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3799) 	if (!camera) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3800) 		pr_warn("camera control not enabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3801) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3802) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3804) 	if (spic_dev.camera_power)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3805) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3807) 	for (j = 5; j > 0; j--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3809) 		for (x = 0; x < 100 && sony_pic_call2(0x91, 0x1); x++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3810) 			msleep(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3811) 		sony_pic_call1(0x93);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3812) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3813) 		for (i = 400; i > 0; i--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3814) 			if (__sony_pic_camera_ready())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3815) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3816) 			msleep(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3817) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3818) 		if (i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3819) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3820) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3822) 	if (j == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3823) 		pr_warn("failed to power on camera\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3824) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3825) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3827) 	wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTROL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3828) 				0x5a),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3829) 			ITERATIONS_SHORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3831) 	spic_dev.camera_power = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3832) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3833) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3835) /* External camera command (exported to the motion eye v4l driver) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3836) int sony_pic_camera_command(int command, u8 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3837) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3838) 	if (!camera)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3839) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3841) 	mutex_lock(&spic_dev.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3843) 	switch (command) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3844) 	case SONY_PIC_COMMAND_SETCAMERA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3845) 		if (value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3846) 			__sony_pic_camera_on();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3847) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3848) 			__sony_pic_camera_off();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3849) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3850) 	case SONY_PIC_COMMAND_SETCAMERABRIGHTNESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3851) 		wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_BRIGHTNESS, value),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3852) 				ITERATIONS_SHORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3853) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3854) 	case SONY_PIC_COMMAND_SETCAMERACONTRAST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3855) 		wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTRAST, value),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3856) 				ITERATIONS_SHORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3857) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3858) 	case SONY_PIC_COMMAND_SETCAMERAHUE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3859) 		wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_HUE, value),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3860) 				ITERATIONS_SHORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3861) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3862) 	case SONY_PIC_COMMAND_SETCAMERACOLOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3863) 		wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_COLOR, value),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3864) 				ITERATIONS_SHORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3865) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3866) 	case SONY_PIC_COMMAND_SETCAMERASHARPNESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3867) 		wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_SHARPNESS, value),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3868) 				ITERATIONS_SHORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3869) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3870) 	case SONY_PIC_COMMAND_SETCAMERAPICTURE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3871) 		wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE, value),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3872) 				ITERATIONS_SHORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3873) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3874) 	case SONY_PIC_COMMAND_SETCAMERAAGC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3875) 		wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_AGC, value),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3876) 				ITERATIONS_SHORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3877) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3878) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3879) 		pr_err("sony_pic_camera_command invalid: %d\n", command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3880) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3881) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3882) 	mutex_unlock(&spic_dev.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3883) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3884) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3885) EXPORT_SYMBOL(sony_pic_camera_command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3887) /* gprs/edge modem (SZ460N and SZ210P), thanks to Joshua Wise */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3888) static void __sony_pic_set_wwanpower(u8 state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3889) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3890) 	state = !!state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3891) 	if (spic_dev.wwan_power == state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3892) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3893) 	sony_pic_call2(0xB0, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3894) 	sony_pic_call1(0x82);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3895) 	spic_dev.wwan_power = state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3896) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3898) static ssize_t sony_pic_wwanpower_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3899) 		struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3900) 		const char *buffer, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3901) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3902) 	unsigned long value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3903) 	if (count > 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3904) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3906) 	if (kstrtoul(buffer, 10, &value))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3907) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3909) 	mutex_lock(&spic_dev.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3910) 	__sony_pic_set_wwanpower(value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3911) 	mutex_unlock(&spic_dev.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3912) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3913) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3914) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3916) static ssize_t sony_pic_wwanpower_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3917) 		struct device_attribute *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3918) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3919) 	ssize_t count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3920) 	mutex_lock(&spic_dev.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3921) 	count = snprintf(buffer, PAGE_SIZE, "%d\n", spic_dev.wwan_power);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3922) 	mutex_unlock(&spic_dev.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3923) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3924) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3926) /* bluetooth subsystem power state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3927) static void __sony_pic_set_bluetoothpower(u8 state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3928) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3929) 	state = !!state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3930) 	if (spic_dev.bluetooth_power == state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3931) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3932) 	sony_pic_call2(0x96, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3933) 	sony_pic_call1(0x82);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3934) 	spic_dev.bluetooth_power = state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3935) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3937) static ssize_t sony_pic_bluetoothpower_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3938) 		struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3939) 		const char *buffer, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3940) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3941) 	unsigned long value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3942) 	if (count > 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3943) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3944) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3945) 	if (kstrtoul(buffer, 10, &value))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3946) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3947) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3948) 	mutex_lock(&spic_dev.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3949) 	__sony_pic_set_bluetoothpower(value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3950) 	mutex_unlock(&spic_dev.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3952) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3953) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3955) static ssize_t sony_pic_bluetoothpower_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3956) 		struct device_attribute *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3957) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3958) 	ssize_t count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3959) 	mutex_lock(&spic_dev.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3960) 	count = snprintf(buffer, PAGE_SIZE, "%d\n", spic_dev.bluetooth_power);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3961) 	mutex_unlock(&spic_dev.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3962) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3963) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3965) /* fan speed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3966) /* FAN0 information (reverse engineered from ACPI tables) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3967) #define SONY_PIC_FAN0_STATUS	0x93
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3968) static int sony_pic_set_fanspeed(unsigned long value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3969) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3970) 	return ec_write(SONY_PIC_FAN0_STATUS, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3971) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3973) static int sony_pic_get_fanspeed(u8 *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3974) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3975) 	return ec_read(SONY_PIC_FAN0_STATUS, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3976) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3977) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3978) static ssize_t sony_pic_fanspeed_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3979) 		struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3980) 		const char *buffer, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3981) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3982) 	unsigned long value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3983) 	if (count > 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3984) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3986) 	if (kstrtoul(buffer, 10, &value))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3987) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3988) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3989) 	if (sony_pic_set_fanspeed(value))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3990) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3992) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3993) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3994) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3995) static ssize_t sony_pic_fanspeed_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3996) 		struct device_attribute *attr, char *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3997) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3998) 	u8 value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3999) 	if (sony_pic_get_fanspeed(&value))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4000) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4002) 	return snprintf(buffer, PAGE_SIZE, "%d\n", value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4003) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4004) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4005) #define SPIC_ATTR(_name, _mode)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4006) struct device_attribute spic_attr_##_name = __ATTR(_name,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4007) 		_mode, sony_pic_## _name ##_show,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4008) 		sony_pic_## _name ##_store)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4010) static SPIC_ATTR(bluetoothpower, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4011) static SPIC_ATTR(wwanpower, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4012) static SPIC_ATTR(fanspeed, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4014) static struct attribute *spic_attributes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4015) 	&spic_attr_bluetoothpower.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4016) 	&spic_attr_wwanpower.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4017) 	&spic_attr_fanspeed.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4018) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4019) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4021) static const struct attribute_group spic_attribute_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4022) 	.attrs = spic_attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4023) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4025) /******** SONYPI compatibility **********/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4026) #ifdef CONFIG_SONYPI_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4028) /* battery / brightness / temperature  addresses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4029) #define SONYPI_BAT_FLAGS	0x81
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4030) #define SONYPI_LCD_LIGHT	0x96
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4031) #define SONYPI_BAT1_PCTRM	0xa0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4032) #define SONYPI_BAT1_LEFT	0xa2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4033) #define SONYPI_BAT1_MAXRT	0xa4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4034) #define SONYPI_BAT2_PCTRM	0xa8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4035) #define SONYPI_BAT2_LEFT	0xaa
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4036) #define SONYPI_BAT2_MAXRT	0xac
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4037) #define SONYPI_BAT1_MAXTK	0xb0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4038) #define SONYPI_BAT1_FULL	0xb2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4039) #define SONYPI_BAT2_MAXTK	0xb8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4040) #define SONYPI_BAT2_FULL	0xba
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4041) #define SONYPI_TEMP_STATUS	0xC1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4043) struct sonypi_compat_s {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4044) 	struct fasync_struct	*fifo_async;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4045) 	struct kfifo		fifo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4046) 	spinlock_t		fifo_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4047) 	wait_queue_head_t	fifo_proc_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4048) 	atomic_t		open_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4049) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4050) static struct sonypi_compat_s sonypi_compat = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4051) 	.open_count = ATOMIC_INIT(0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4052) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4053) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4054) static int sonypi_misc_fasync(int fd, struct file *filp, int on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4055) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4056) 	return fasync_helper(fd, filp, on, &sonypi_compat.fifo_async);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4058) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4059) static int sonypi_misc_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4060) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4061) 	atomic_dec(&sonypi_compat.open_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4062) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4063) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4064) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4065) static int sonypi_misc_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4066) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4067) 	/* Flush input queue on first open */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4068) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4069) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4070) 	spin_lock_irqsave(&sonypi_compat.fifo_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4071) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4072) 	if (atomic_inc_return(&sonypi_compat.open_count) == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4073) 		kfifo_reset(&sonypi_compat.fifo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4074) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4075) 	spin_unlock_irqrestore(&sonypi_compat.fifo_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4077) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4078) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4079) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4080) static ssize_t sonypi_misc_read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4081) 				size_t count, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4082) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4083) 	ssize_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4084) 	unsigned char c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4086) 	if ((kfifo_len(&sonypi_compat.fifo) == 0) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4087) 	    (file->f_flags & O_NONBLOCK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4088) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4089) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4090) 	ret = wait_event_interruptible(sonypi_compat.fifo_proc_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4091) 				       kfifo_len(&sonypi_compat.fifo) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4092) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4093) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4094) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4095) 	while (ret < count &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4096) 	       (kfifo_out_locked(&sonypi_compat.fifo, &c, sizeof(c),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4097) 			  &sonypi_compat.fifo_lock) == sizeof(c))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4098) 		if (put_user(c, buf++))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4099) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4100) 		ret++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4101) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4103) 	if (ret > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4104) 		struct inode *inode = file_inode(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4105) 		inode->i_atime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4106) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4108) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4111) static __poll_t sonypi_misc_poll(struct file *file, poll_table *wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4113) 	poll_wait(file, &sonypi_compat.fifo_proc_list, wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4114) 	if (kfifo_len(&sonypi_compat.fifo))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4115) 		return EPOLLIN | EPOLLRDNORM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4116) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4119) static int ec_read16(u8 addr, u16 *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4121) 	u8 val_lb, val_hb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4122) 	if (ec_read(addr, &val_lb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4123) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4124) 	if (ec_read(addr + 1, &val_hb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4125) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4126) 	*value = val_lb | (val_hb << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4127) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4130) static long sonypi_misc_ioctl(struct file *fp, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4131) 							unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4133) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4134) 	void __user *argp = (void __user *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4135) 	u8 val8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4136) 	u16 val16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4137) 	int value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4139) 	mutex_lock(&spic_dev.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4140) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4141) 	case SONYPI_IOCGBRT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4142) 		if (sony_bl_props.dev == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4143) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4144) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4145) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4146) 		if (sony_nc_int_call(sony_nc_acpi_handle, "GBRT", NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4147) 					&value)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4148) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4149) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4150) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4151) 		val8 = ((value & 0xff) - 1) << 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4152) 		if (copy_to_user(argp, &val8, sizeof(val8)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4153) 				ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4154) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4155) 	case SONYPI_IOCSBRT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4156) 		if (sony_bl_props.dev == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4157) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4158) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4159) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4160) 		if (copy_from_user(&val8, argp, sizeof(val8))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4161) 			ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4162) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4163) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4164) 		value = (val8 >> 5) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4165) 		if (sony_nc_int_call(sony_nc_acpi_handle, "SBRT", &value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4166) 					NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4167) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4168) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4169) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4170) 		/* sync the backlight device status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4171) 		sony_bl_props.dev->props.brightness =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4172) 		    sony_backlight_get_brightness(sony_bl_props.dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4173) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4174) 	case SONYPI_IOCGBAT1CAP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4175) 		if (ec_read16(SONYPI_BAT1_FULL, &val16)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4176) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4177) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4178) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4179) 		if (copy_to_user(argp, &val16, sizeof(val16)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4180) 			ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4181) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4182) 	case SONYPI_IOCGBAT1REM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4183) 		if (ec_read16(SONYPI_BAT1_LEFT, &val16)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4184) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4185) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4186) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4187) 		if (copy_to_user(argp, &val16, sizeof(val16)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4188) 			ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4189) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4190) 	case SONYPI_IOCGBAT2CAP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4191) 		if (ec_read16(SONYPI_BAT2_FULL, &val16)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4192) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4193) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4194) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4195) 		if (copy_to_user(argp, &val16, sizeof(val16)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4196) 			ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4197) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4198) 	case SONYPI_IOCGBAT2REM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4199) 		if (ec_read16(SONYPI_BAT2_LEFT, &val16)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4200) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4201) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4202) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4203) 		if (copy_to_user(argp, &val16, sizeof(val16)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4204) 			ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4205) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4206) 	case SONYPI_IOCGBATFLAGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4207) 		if (ec_read(SONYPI_BAT_FLAGS, &val8)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4208) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4209) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4210) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4211) 		val8 &= 0x07;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4212) 		if (copy_to_user(argp, &val8, sizeof(val8)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4213) 			ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4214) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4215) 	case SONYPI_IOCGBLUE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4216) 		val8 = spic_dev.bluetooth_power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4217) 		if (copy_to_user(argp, &val8, sizeof(val8)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4218) 			ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4219) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4220) 	case SONYPI_IOCSBLUE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4221) 		if (copy_from_user(&val8, argp, sizeof(val8))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4222) 			ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4223) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4224) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4225) 		__sony_pic_set_bluetoothpower(val8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4226) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4227) 	/* FAN Controls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4228) 	case SONYPI_IOCGFAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4229) 		if (sony_pic_get_fanspeed(&val8)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4230) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4231) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4232) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4233) 		if (copy_to_user(argp, &val8, sizeof(val8)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4234) 			ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4235) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4236) 	case SONYPI_IOCSFAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4237) 		if (copy_from_user(&val8, argp, sizeof(val8))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4238) 			ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4239) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4240) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4241) 		if (sony_pic_set_fanspeed(val8))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4242) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4243) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4244) 	/* GET Temperature (useful under APM) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4245) 	case SONYPI_IOCGTEMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4246) 		if (ec_read(SONYPI_TEMP_STATUS, &val8)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4247) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4248) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4249) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4250) 		if (copy_to_user(argp, &val8, sizeof(val8)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4251) 			ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4252) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4253) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4254) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4255) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4256) 	mutex_unlock(&spic_dev.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4257) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4260) static const struct file_operations sonypi_misc_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4261) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4262) 	.read		= sonypi_misc_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4263) 	.poll		= sonypi_misc_poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4264) 	.open		= sonypi_misc_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4265) 	.release	= sonypi_misc_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4266) 	.fasync		= sonypi_misc_fasync,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4267) 	.unlocked_ioctl	= sonypi_misc_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4268) 	.llseek		= noop_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4269) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4271) static struct miscdevice sonypi_misc_device = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4272) 	.minor		= MISC_DYNAMIC_MINOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4273) 	.name		= "sonypi",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4274) 	.fops		= &sonypi_misc_fops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4275) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4277) static void sonypi_compat_report_event(u8 event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4279) 	kfifo_in_locked(&sonypi_compat.fifo, (unsigned char *)&event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4280) 			sizeof(event), &sonypi_compat.fifo_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4281) 	kill_fasync(&sonypi_compat.fifo_async, SIGIO, POLL_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4282) 	wake_up_interruptible(&sonypi_compat.fifo_proc_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4285) static int sonypi_compat_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4287) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4289) 	spin_lock_init(&sonypi_compat.fifo_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4290) 	error =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4291) 	 kfifo_alloc(&sonypi_compat.fifo, SONY_LAPTOP_BUF_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4292) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4293) 		pr_err("kfifo_alloc failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4294) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4295) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4297) 	init_waitqueue_head(&sonypi_compat.fifo_proc_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4299) 	if (minor != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4300) 		sonypi_misc_device.minor = minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4301) 	error = misc_register(&sonypi_misc_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4302) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4303) 		pr_err("misc_register failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4304) 		goto err_free_kfifo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4305) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4306) 	if (minor == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4307) 		pr_info("device allocated minor is %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4308) 			sonypi_misc_device.minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4310) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4312) err_free_kfifo:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4313) 	kfifo_free(&sonypi_compat.fifo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4314) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4317) static void sonypi_compat_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4319) 	misc_deregister(&sonypi_misc_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4320) 	kfifo_free(&sonypi_compat.fifo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4322) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4323) static int sonypi_compat_init(void) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4324) static void sonypi_compat_exit(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4325) static void sonypi_compat_report_event(u8 event) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4326) #endif /* CONFIG_SONYPI_COMPAT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4328) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4329)  * ACPI callbacks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4330)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4331) static acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4332) sony_pic_read_possible_resource(struct acpi_resource *resource, void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4333) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4334) 	u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4335) 	struct sony_pic_dev *dev = (struct sony_pic_dev *)context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4337) 	switch (resource->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4338) 	case ACPI_RESOURCE_TYPE_START_DEPENDENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4339) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4340) 			/* start IO enumeration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4341) 			struct sony_pic_ioport *ioport = kzalloc(sizeof(*ioport), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4342) 			if (!ioport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4343) 				return AE_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4345) 			list_add(&ioport->list, &dev->ioports);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4346) 			return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4347) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4349) 	case ACPI_RESOURCE_TYPE_END_DEPENDENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4350) 		/* end IO enumeration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4351) 		return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4353) 	case ACPI_RESOURCE_TYPE_IRQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4354) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4355) 			struct acpi_resource_irq *p = &resource->data.irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4356) 			struct sony_pic_irq *interrupt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4357) 			if (!p || !p->interrupt_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4358) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4359) 				 * IRQ descriptors may have no IRQ# bits set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4360) 				 * particularly those those w/ _STA disabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4361) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4362) 				dprintk("Blank IRQ resource\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4363) 				return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4364) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4365) 			for (i = 0; i < p->interrupt_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4366) 				if (!p->interrupts[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4367) 					pr_warn("Invalid IRQ %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4368) 						p->interrupts[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4369) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4370) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4371) 				interrupt = kzalloc(sizeof(*interrupt),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4372) 						GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4373) 				if (!interrupt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4374) 					return AE_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4376) 				list_add(&interrupt->list, &dev->interrupts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4377) 				interrupt->irq.triggering = p->triggering;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4378) 				interrupt->irq.polarity = p->polarity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4379) 				interrupt->irq.shareable = p->shareable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4380) 				interrupt->irq.interrupt_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4381) 				interrupt->irq.interrupts[0] = p->interrupts[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4382) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4383) 			return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4384) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4385) 	case ACPI_RESOURCE_TYPE_IO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4386) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4387) 			struct acpi_resource_io *io = &resource->data.io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4388) 			struct sony_pic_ioport *ioport =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4389) 				list_first_entry(&dev->ioports, struct sony_pic_ioport, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4390) 			if (!io) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4391) 				dprintk("Blank IO resource\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4392) 				return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4393) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4395) 			if (!ioport->io1.minimum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4396) 				memcpy(&ioport->io1, io, sizeof(*io));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4397) 				dprintk("IO1 at 0x%.4x (0x%.2x)\n", ioport->io1.minimum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4398) 						ioport->io1.address_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4399) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4400) 			else if (!ioport->io2.minimum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4401) 				memcpy(&ioport->io2, io, sizeof(*io));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4402) 				dprintk("IO2 at 0x%.4x (0x%.2x)\n", ioport->io2.minimum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4403) 						ioport->io2.address_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4404) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4405) 			else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4406) 				pr_err("Unknown SPIC Type, more than 2 IO Ports\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4407) 				return AE_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4408) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4409) 			return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4410) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4412) 	case ACPI_RESOURCE_TYPE_END_TAG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4413) 		return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4415) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4416) 		dprintk("Resource %d isn't an IRQ nor an IO port\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4417) 			resource->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4418) 		return AE_CTRL_TERMINATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4420) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4423) static int sony_pic_possible_resources(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4425) 	int result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4426) 	acpi_status status = AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4428) 	if (!device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4429) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4431) 	/* get device status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4432) 	/* see acpi_pci_link_get_current acpi_pci_link_get_possible */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4433) 	dprintk("Evaluating _STA\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4434) 	result = acpi_bus_get_status(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4435) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4436) 		pr_warn("Unable to read status\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4437) 		goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4438) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4440) 	if (!device->status.enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4441) 		dprintk("Device disabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4442) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4443) 		dprintk("Device enabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4445) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4446) 	 * Query and parse 'method'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4447) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4448) 	dprintk("Evaluating %s\n", METHOD_NAME__PRS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4449) 	status = acpi_walk_resources(device->handle, METHOD_NAME__PRS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4450) 			sony_pic_read_possible_resource, &spic_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4451) 	if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4452) 		pr_warn("Failure evaluating %s\n", METHOD_NAME__PRS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4453) 		result = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4454) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4455) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4456) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4459) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4460)  *  Disable the spic device by calling its _DIS method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4461)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4462) static int sony_pic_disable(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4463) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4464) 	acpi_status ret = acpi_evaluate_object(device->handle, "_DIS", NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4465) 					       NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4467) 	if (ACPI_FAILURE(ret) && ret != AE_NOT_FOUND)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4468) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4470) 	dprintk("Device disabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4471) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4475) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4476)  *  Based on drivers/acpi/pci_link.c:acpi_pci_link_set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4477)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4478)  *  Call _SRS to set current resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4479)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4480) static int sony_pic_enable(struct acpi_device *device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4481) 		struct sony_pic_ioport *ioport, struct sony_pic_irq *irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4482) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4483) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4484) 	int result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4485) 	/* Type 1 resource layout is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4486) 	 *    IO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4487) 	 *    IO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4488) 	 *    IRQNoFlags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4489) 	 *    End
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4490) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4491) 	 * Type 2 and 3 resource layout is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4492) 	 *    IO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4493) 	 *    IRQNoFlags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4494) 	 *    End
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4495) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4496) 	struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4497) 		struct acpi_resource res1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4498) 		struct acpi_resource res2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4499) 		struct acpi_resource res3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4500) 		struct acpi_resource res4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4501) 	} *resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4502) 	struct acpi_buffer buffer = { 0, NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4504) 	if (!ioport || !irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4505) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4507) 	/* init acpi_buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4508) 	resource = kzalloc(sizeof(*resource) + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4509) 	if (!resource)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4510) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4512) 	buffer.length = sizeof(*resource) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4513) 	buffer.pointer = resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4515) 	/* setup Type 1 resources */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4516) 	if (spic_dev.model == SONYPI_DEVICE_TYPE1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4518) 		/* setup io resources */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4519) 		resource->res1.type = ACPI_RESOURCE_TYPE_IO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4520) 		resource->res1.length = sizeof(struct acpi_resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4521) 		memcpy(&resource->res1.data.io, &ioport->io1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4522) 				sizeof(struct acpi_resource_io));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4524) 		resource->res2.type = ACPI_RESOURCE_TYPE_IO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4525) 		resource->res2.length = sizeof(struct acpi_resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4526) 		memcpy(&resource->res2.data.io, &ioport->io2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4527) 				sizeof(struct acpi_resource_io));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4529) 		/* setup irq resource */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4530) 		resource->res3.type = ACPI_RESOURCE_TYPE_IRQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4531) 		resource->res3.length = sizeof(struct acpi_resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4532) 		memcpy(&resource->res3.data.irq, &irq->irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4533) 				sizeof(struct acpi_resource_irq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4534) 		/* we requested a shared irq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4535) 		resource->res3.data.irq.shareable = ACPI_SHARED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4537) 		resource->res4.type = ACPI_RESOURCE_TYPE_END_TAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4538) 		resource->res4.length = sizeof(struct acpi_resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4539) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4540) 	/* setup Type 2/3 resources */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4541) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4542) 		/* setup io resource */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4543) 		resource->res1.type = ACPI_RESOURCE_TYPE_IO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4544) 		resource->res1.length = sizeof(struct acpi_resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4545) 		memcpy(&resource->res1.data.io, &ioport->io1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4546) 				sizeof(struct acpi_resource_io));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4548) 		/* setup irq resource */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4549) 		resource->res2.type = ACPI_RESOURCE_TYPE_IRQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4550) 		resource->res2.length = sizeof(struct acpi_resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4551) 		memcpy(&resource->res2.data.irq, &irq->irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4552) 				sizeof(struct acpi_resource_irq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4553) 		/* we requested a shared irq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4554) 		resource->res2.data.irq.shareable = ACPI_SHARED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4556) 		resource->res3.type = ACPI_RESOURCE_TYPE_END_TAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4557) 		resource->res3.length = sizeof(struct acpi_resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4558) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4560) 	/* Attempt to set the resource */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4561) 	dprintk("Evaluating _SRS\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4562) 	status = acpi_set_current_resources(device->handle, &buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4564) 	/* check for total failure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4565) 	if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4566) 		pr_err("Error evaluating _SRS\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4567) 		result = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4568) 		goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4569) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4571) 	/* Necessary device initializations calls (from sonypi) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4572) 	sony_pic_call1(0x82);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4573) 	sony_pic_call2(0x81, 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4574) 	sony_pic_call1(compat ? 0x92 : 0x82);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4576) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4577) 	kfree(resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4578) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4581) /*****************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4582)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4583)  * ISR: some event is available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4584)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4585)  *****************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4586) static irqreturn_t sony_pic_irq(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4587) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4588) 	int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4589) 	u8 ev = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4590) 	u8 data_mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4591) 	u8 device_event = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4593) 	struct sony_pic_dev *dev = (struct sony_pic_dev *) dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4595) 	ev = inb_p(dev->cur_ioport->io1.minimum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4596) 	if (dev->cur_ioport->io2.minimum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4597) 		data_mask = inb_p(dev->cur_ioport->io2.minimum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4598) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4599) 		data_mask = inb_p(dev->cur_ioport->io1.minimum +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4600) 				dev->evport_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4602) 	dprintk("event ([%.2x] [%.2x]) at port 0x%.4x(+0x%.2x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4603) 			ev, data_mask, dev->cur_ioport->io1.minimum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4604) 			dev->evport_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4606) 	if (ev == 0x00 || ev == 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4607) 		return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4609) 	for (i = 0; dev->event_types[i].mask; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4611) 		if ((data_mask & dev->event_types[i].data) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4612) 		    dev->event_types[i].data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4613) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4615) 		if (!(mask & dev->event_types[i].mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4616) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4618) 		for (j = 0; dev->event_types[i].events[j].event; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4619) 			if (ev == dev->event_types[i].events[j].data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4620) 				device_event =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4621) 					dev->event_types[i].events[j].event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4622) 				/* some events may require ignoring */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4623) 				if (!device_event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4624) 					return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4625) 				goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4626) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4627) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4628) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4629) 	/* Still not able to decode the event try to pass
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4630) 	 * it over to the minidriver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4631) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4632) 	if (dev->handle_irq && dev->handle_irq(data_mask, ev) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4633) 		return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4635) 	dprintk("unknown event ([%.2x] [%.2x]) at port 0x%.4x(+0x%.2x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4636) 			ev, data_mask, dev->cur_ioport->io1.minimum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4637) 			dev->evport_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4638) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4640) found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4641) 	sony_laptop_report_input_event(device_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4642) 	sonypi_compat_report_event(device_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4643) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4646) /*****************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4647)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4648)  *  ACPI driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4649)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4650)  *****************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4651) static int sony_pic_remove(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4652) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4653) 	struct sony_pic_ioport *io, *tmp_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4654) 	struct sony_pic_irq *irq, *tmp_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4656) 	if (sony_pic_disable(device)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4657) 		pr_err("Couldn't disable device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4658) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4659) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4661) 	free_irq(spic_dev.cur_irq->irq.interrupts[0], &spic_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4662) 	release_region(spic_dev.cur_ioport->io1.minimum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4663) 			spic_dev.cur_ioport->io1.address_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4664) 	if (spic_dev.cur_ioport->io2.minimum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4665) 		release_region(spic_dev.cur_ioport->io2.minimum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4666) 				spic_dev.cur_ioport->io2.address_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4668) 	sonypi_compat_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4670) 	sony_laptop_remove_input();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4672) 	/* pf attrs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4673) 	sysfs_remove_group(&sony_pf_device->dev.kobj, &spic_attribute_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4674) 	sony_pf_remove();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4676) 	list_for_each_entry_safe(io, tmp_io, &spic_dev.ioports, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4677) 		list_del(&io->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4678) 		kfree(io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4679) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4680) 	list_for_each_entry_safe(irq, tmp_irq, &spic_dev.interrupts, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4681) 		list_del(&irq->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4682) 		kfree(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4683) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4684) 	spic_dev.cur_ioport = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4685) 	spic_dev.cur_irq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4687) 	dprintk(SONY_PIC_DRIVER_NAME " removed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4688) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4689) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4691) static int sony_pic_add(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4692) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4693) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4694) 	struct sony_pic_ioport *io, *tmp_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4695) 	struct sony_pic_irq *irq, *tmp_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4697) 	spic_dev.acpi_dev = device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4698) 	strcpy(acpi_device_class(device), "sony/hotkey");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4699) 	sony_pic_detect_device_type(&spic_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4700) 	mutex_init(&spic_dev.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4702) 	/* read _PRS resources */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4703) 	result = sony_pic_possible_resources(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4704) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4705) 		pr_err("Unable to read possible resources\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4706) 		goto err_free_resources;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4707) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4709) 	/* setup input devices and helper fifo */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4710) 	result = sony_laptop_setup_input(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4711) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4712) 		pr_err("Unable to create input devices\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4713) 		goto err_free_resources;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4714) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4716) 	result = sonypi_compat_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4717) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4718) 		goto err_remove_input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4720) 	/* request io port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4721) 	list_for_each_entry_reverse(io, &spic_dev.ioports, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4722) 		if (request_region(io->io1.minimum, io->io1.address_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4723) 					"Sony Programmable I/O Device")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4724) 			dprintk("I/O port1: 0x%.4x (0x%.4x) + 0x%.2x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4725) 					io->io1.minimum, io->io1.maximum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4726) 					io->io1.address_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4727) 			/* Type 1 have 2 ioports */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4728) 			if (io->io2.minimum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4729) 				if (request_region(io->io2.minimum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4730) 						io->io2.address_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4731) 						"Sony Programmable I/O Device")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4732) 					dprintk("I/O port2: 0x%.4x (0x%.4x) + 0x%.2x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4733) 							io->io2.minimum, io->io2.maximum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4734) 							io->io2.address_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4735) 					spic_dev.cur_ioport = io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4736) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4737) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4738) 				else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4739) 					dprintk("Unable to get I/O port2: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4740) 							"0x%.4x (0x%.4x) + 0x%.2x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4741) 							io->io2.minimum, io->io2.maximum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4742) 							io->io2.address_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4743) 					release_region(io->io1.minimum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4744) 							io->io1.address_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4745) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4746) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4747) 			else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4748) 				spic_dev.cur_ioport = io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4749) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4750) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4751) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4752) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4753) 	if (!spic_dev.cur_ioport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4754) 		pr_err("Failed to request_region\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4755) 		result = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4756) 		goto err_remove_compat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4757) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4759) 	/* request IRQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4760) 	list_for_each_entry_reverse(irq, &spic_dev.interrupts, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4761) 		if (!request_irq(irq->irq.interrupts[0], sony_pic_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4762) 					0, "sony-laptop", &spic_dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4763) 			dprintk("IRQ: %d - triggering: %d - "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4764) 					"polarity: %d - shr: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4765) 					irq->irq.interrupts[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4766) 					irq->irq.triggering,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4767) 					irq->irq.polarity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4768) 					irq->irq.shareable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4769) 			spic_dev.cur_irq = irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4770) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4771) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4772) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4773) 	if (!spic_dev.cur_irq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4774) 		pr_err("Failed to request_irq\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4775) 		result = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4776) 		goto err_release_region;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4777) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4779) 	/* set resource status _SRS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4780) 	result = sony_pic_enable(device, spic_dev.cur_ioport, spic_dev.cur_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4781) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4782) 		pr_err("Couldn't enable device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4783) 		goto err_free_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4784) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4786) 	spic_dev.bluetooth_power = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4787) 	/* create device attributes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4788) 	result = sony_pf_add();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4789) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4790) 		goto err_disable_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4792) 	result = sysfs_create_group(&sony_pf_device->dev.kobj, &spic_attribute_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4793) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4794) 		goto err_remove_pf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4796) 	pr_info("SPIC setup done.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4797) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4799) err_remove_pf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4800) 	sony_pf_remove();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4802) err_disable_device:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4803) 	sony_pic_disable(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4805) err_free_irq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4806) 	free_irq(spic_dev.cur_irq->irq.interrupts[0], &spic_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4808) err_release_region:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4809) 	release_region(spic_dev.cur_ioport->io1.minimum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4810) 			spic_dev.cur_ioport->io1.address_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4811) 	if (spic_dev.cur_ioport->io2.minimum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4812) 		release_region(spic_dev.cur_ioport->io2.minimum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4813) 				spic_dev.cur_ioport->io2.address_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4815) err_remove_compat:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4816) 	sonypi_compat_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4818) err_remove_input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4819) 	sony_laptop_remove_input();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4820) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4821) err_free_resources:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4822) 	list_for_each_entry_safe(io, tmp_io, &spic_dev.ioports, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4823) 		list_del(&io->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4824) 		kfree(io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4825) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4826) 	list_for_each_entry_safe(irq, tmp_irq, &spic_dev.interrupts, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4827) 		list_del(&irq->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4828) 		kfree(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4829) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4830) 	spic_dev.cur_ioport = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4831) 	spic_dev.cur_irq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4833) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4834) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4836) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4837) static int sony_pic_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4838) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4839) 	if (sony_pic_disable(to_acpi_device(dev)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4840) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4841) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4843) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4844) static int sony_pic_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4845) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4846) 	sony_pic_enable(to_acpi_device(dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4847) 			spic_dev.cur_ioport, spic_dev.cur_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4848) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4849) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4850) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4852) static SIMPLE_DEV_PM_OPS(sony_pic_pm, sony_pic_suspend, sony_pic_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4853) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4854) static const struct acpi_device_id sony_pic_device_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4855) 	{SONY_PIC_HID, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4856) 	{"", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4857) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4859) static struct acpi_driver sony_pic_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4860) 	.name = SONY_PIC_DRIVER_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4861) 	.class = SONY_PIC_CLASS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4862) 	.ids = sony_pic_device_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4863) 	.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4864) 	.ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4865) 		.add = sony_pic_add,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4866) 		.remove = sony_pic_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4867) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4868) 	.drv.pm = &sony_pic_pm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4869) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4871) static const struct dmi_system_id sonypi_dmi_table[] __initconst = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4872) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4873) 		.ident = "Sony Vaio",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4874) 		.matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4875) 			DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4876) 			DMI_MATCH(DMI_PRODUCT_NAME, "PCG-"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4877) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4878) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4879) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4880) 		.ident = "Sony Vaio",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4881) 		.matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4882) 			DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4883) 			DMI_MATCH(DMI_PRODUCT_NAME, "VGN-"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4884) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4885) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4886) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4887) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4888) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4889) static int __init sony_laptop_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4890) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4891) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4893) 	if (!no_spic && dmi_check_system(sonypi_dmi_table)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4894) 		result = acpi_bus_register_driver(&sony_pic_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4895) 		if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4896) 			pr_err("Unable to register SPIC driver\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4897) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4898) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4899) 		spic_drv_registered = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4900) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4901) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4902) 	result = acpi_bus_register_driver(&sony_nc_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4903) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4904) 		pr_err("Unable to register SNC driver\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4905) 		goto out_unregister_pic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4906) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4908) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4910) out_unregister_pic:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4911) 	if (spic_drv_registered)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4912) 		acpi_bus_unregister_driver(&sony_pic_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4913) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4914) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4915) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4917) static void __exit sony_laptop_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4918) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4919) 	acpi_bus_unregister_driver(&sony_nc_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4920) 	if (spic_drv_registered)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4921) 		acpi_bus_unregister_driver(&sony_pic_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4922) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4924) module_init(sony_laptop_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4925) module_exit(sony_laptop_exit);