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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  Fujitsu Lifebook Application Panel button drive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (C) 2007 Stephen Hemminger <shemminger@linux-foundation.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Copyright (C) 2001-2003 Jochen Eisinger <jochen@penguin-breeder.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Many Fujitsu Lifebook laptops have a small panel of buttons that are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * accessible via the i2c/smbus interface. This driver polls those
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * buttons and generates input events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * For more details see:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *	http://apanel.sourceforge.net/tech.php
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/leds.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define APANEL_NAME	"Fujitsu Application Panel"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define APANEL		"apanel"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) /* How often we poll keys - msecs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define POLL_INTERVAL_DEFAULT	1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) /* Magic constants in BIOS that tell about buttons */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) enum apanel_devid {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	APANEL_DEV_NONE	  = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	APANEL_DEV_APPBTN = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	APANEL_DEV_CDBTN  = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	APANEL_DEV_LCD	  = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	APANEL_DEV_LED	  = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	APANEL_DEV_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) enum apanel_chip {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	CHIP_NONE    = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	CHIP_OZ992C  = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	CHIP_OZ163T  = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	CHIP_OZ711M3 = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) /* Result of BIOS snooping/probing -- what features are supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static enum apanel_chip device_chip[APANEL_DEV_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define MAX_PANEL_KEYS	12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) struct apanel {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	struct input_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	unsigned short keymap[MAX_PANEL_KEYS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	u16 nkeys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	struct led_classdev mail_led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) static const unsigned short apanel_keymap[MAX_PANEL_KEYS] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	[0] = KEY_MAIL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	[1] = KEY_WWW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	[2] = KEY_PROG2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	[3] = KEY_PROG1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	[8] = KEY_FORWARD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	[9] = KEY_REWIND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	[10] = KEY_STOPCD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	[11] = KEY_PLAYPAUSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static void report_key(struct input_dev *input, unsigned keycode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	dev_dbg(input->dev.parent, "report key %#x\n", keycode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	input_report_key(input, keycode, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	input_sync(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	input_report_key(input, keycode, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	input_sync(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) /* Poll for key changes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  * Read Application keys via SMI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  *  A (0x4), B (0x8), Internet (0x2), Email (0x1).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  * CD keys:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  * Forward (0x100), Rewind (0x200), Stop (0x400), Pause (0x800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) static void apanel_poll(struct input_dev *idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	struct apanel *ap = input_get_drvdata(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	u8 cmd = device_chip[APANEL_DEV_APPBTN] == CHIP_OZ992C ? 0 : 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	s32 data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	data = i2c_smbus_read_word_data(ap->client, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	if (data < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		return;	/* ignore errors (due to ACPI??) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	/* write back to clear latch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	i2c_smbus_write_word_data(ap->client, cmd, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	dev_dbg(&idev->dev, APANEL ": data %#x\n", data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	for (i = 0; i < idev->keycodemax; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		if ((1u << i) & data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			report_key(idev, ap->keymap[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static int mail_led_set(struct led_classdev *led,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			 enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	struct apanel *ap = container_of(led, struct apanel, mail_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	u16 led_bits = value != LED_OFF ? 0x8000 : 0x0000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	return i2c_smbus_write_word_data(ap->client, 0x10, led_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static int apanel_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	struct apanel *ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	struct input_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	u8 cmd = device_chip[APANEL_DEV_APPBTN] == CHIP_OZ992C ? 0 : 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	ap = devm_kzalloc(&client->dev, sizeof(*ap), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	if (!ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	idev = devm_input_allocate_device(&client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	if (!idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	ap->idev = idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	ap->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	i2c_set_clientdata(client, ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	err = i2c_smbus_write_word_data(client, cmd, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		dev_warn(&client->dev, "smbus write error %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	input_set_drvdata(idev, ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	idev->name = APANEL_NAME " buttons";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	idev->phys = "apanel/input0";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	idev->id.bustype = BUS_HOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	memcpy(ap->keymap, apanel_keymap, sizeof(apanel_keymap));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	idev->keycode = ap->keymap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	idev->keycodesize = sizeof(ap->keymap[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	idev->keycodemax = (device_chip[APANEL_DEV_CDBTN] != CHIP_NONE) ? 12 : 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	set_bit(EV_KEY, idev->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	for (i = 0; i < idev->keycodemax; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		if (ap->keymap[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			set_bit(ap->keymap[i], idev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	err = input_setup_polling(idev, apanel_poll);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	input_set_poll_interval(idev, POLL_INTERVAL_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	err = input_register_device(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	if (device_chip[APANEL_DEV_LED] != CHIP_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		ap->mail_led.name = "mail:blue";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		ap->mail_led.brightness_set_blocking = mail_led_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		err = devm_led_classdev_register(&client->dev, &ap->mail_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static void apanel_shutdown(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	struct apanel *ap = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	if (device_chip[APANEL_DEV_LED] != CHIP_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		led_set_brightness(&ap->mail_led, LED_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) static const struct i2c_device_id apanel_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	{ "fujitsu_apanel", 0 },
^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) MODULE_DEVICE_TABLE(i2c, apanel_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) static struct i2c_driver apanel_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		.name = APANEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	.probe		= apanel_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	.shutdown	= apanel_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	.id_table	= apanel_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) /* Scan the system ROM for the signature "FJKEYINF" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static __init const void __iomem *bios_signature(const void __iomem *bios)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	ssize_t offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	const unsigned char signature[] = "FJKEYINF";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	for (offset = 0; offset < 0x10000; offset += 0x10) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		if (check_signature(bios + offset, signature,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 				    sizeof(signature)-1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			return bios + offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	pr_notice(APANEL ": Fujitsu BIOS signature '%s' not found...\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		  signature);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static int __init apanel_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	void __iomem *bios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	const void __iomem *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	u8 devno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	unsigned char i2c_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	int found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	bios = ioremap(0xF0000, 0x10000); /* Can't fail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	p = bios_signature(bios);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	if (!p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		iounmap(bios);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	/* just use the first address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	p += 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	i2c_addr = readb(p + 3) >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	for ( ; (devno = readb(p)) & 0x7f; p += 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		unsigned char method, slave, chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		method = readb(p + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		chip = readb(p + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		slave = readb(p + 3) >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		if (slave != i2c_addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 			pr_notice(APANEL ": only one SMBus slave "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 				  "address supported, skipping device...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		/* translate alternative device numbers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		switch (devno) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		case 6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 			devno = APANEL_DEV_APPBTN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		case 7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			devno = APANEL_DEV_LED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		if (devno >= APANEL_DEV_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 			pr_notice(APANEL ": unknown device %u found\n", devno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		else if (device_chip[devno] != CHIP_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 			pr_warn(APANEL ": duplicate entry for devno %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 				devno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		else if (method != 1 && method != 2 && method != 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 			pr_notice(APANEL ": unknown method %u for devno %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 				  method, devno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 			device_chip[devno] = (enum apanel_chip) chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			++found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	iounmap(bios);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	if (found == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		pr_info(APANEL ": no input devices reported by BIOS\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	return i2c_add_driver(&apanel_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) module_init(apanel_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) static void __exit apanel_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	i2c_del_driver(&apanel_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) module_exit(apanel_cleanup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) MODULE_AUTHOR("Stephen Hemminger <shemminger@linux-foundation.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) MODULE_DESCRIPTION(APANEL_NAME " driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) MODULE_ALIAS("dmi:*:svnFUJITSU:pnLifeBook*:pvr*:rvnFUJITSU:*");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) MODULE_ALIAS("dmi:*:svnFUJITSU:pnLifebook*:pvr*:rvnFUJITSU:*");