^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) * Support for rfkill on some Fujitsu-Siemens Amilo laptops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright 2011 Ben Hutchings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Based in part on the fsam7440 driver, which is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright 2005 Alejandro Vidal Mata & Javier Vidal Mata.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * and on the fsaa1655g driver, which is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright 2006 Martin Večeřa.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/dmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/i8042.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/rfkill.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * These values were obtained from disassembling and debugging the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * PM.exe program installed in the Fujitsu-Siemens AMILO A1655G
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define A1655_WIFI_COMMAND 0x10C5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define A1655_WIFI_ON 0x25
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define A1655_WIFI_OFF 0x45
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static int amilo_a1655_rfkill_set_block(void *data, bool blocked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) u8 param = blocked ? A1655_WIFI_OFF : A1655_WIFI_ON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) i8042_lock_chip();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) rc = i8042_command(¶m, A1655_WIFI_COMMAND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) i8042_unlock_chip();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static const struct rfkill_ops amilo_a1655_rfkill_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) .set_block = amilo_a1655_rfkill_set_block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * These values were obtained from disassembling the PM.exe program
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * installed in the Fujitsu-Siemens AMILO M 7440
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define M7440_PORT1 0x118f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define M7440_PORT2 0x118e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define M7440_RADIO_ON1 0x12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define M7440_RADIO_ON2 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define M7440_RADIO_OFF1 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define M7440_RADIO_OFF2 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static int amilo_m7440_rfkill_set_block(void *data, bool blocked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) u8 val1 = blocked ? M7440_RADIO_OFF1 : M7440_RADIO_ON1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) u8 val2 = blocked ? M7440_RADIO_OFF2 : M7440_RADIO_ON2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) outb(val1, M7440_PORT1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) outb(val2, M7440_PORT2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /* Check whether the state has changed correctly */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) if (inb(M7440_PORT1) != val1 || inb(M7440_PORT2) != val2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static const struct rfkill_ops amilo_m7440_rfkill_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) .set_block = amilo_m7440_rfkill_set_block
^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 const struct dmi_system_id amilo_rfkill_id_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) DMI_MATCH(DMI_BOARD_NAME, "AMILO A1655"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) .driver_data = (void *)&amilo_a1655_rfkill_ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) DMI_MATCH(DMI_BOARD_NAME, "AMILO L1310"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) .driver_data = (void *)&amilo_a1655_rfkill_ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) DMI_MATCH(DMI_BOARD_NAME, "AMILO M7440"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) .driver_data = (void *)&amilo_m7440_rfkill_ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) static struct platform_device *amilo_rfkill_pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) static struct rfkill *amilo_rfkill_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static int amilo_rfkill_probe(struct platform_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) const struct dmi_system_id *system_id =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) dmi_first_match(amilo_rfkill_id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (!system_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) amilo_rfkill_dev = rfkill_alloc(KBUILD_MODNAME, &device->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) RFKILL_TYPE_WLAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) system_id->driver_data, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (!amilo_rfkill_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) rc = rfkill_register(amilo_rfkill_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) rfkill_destroy(amilo_rfkill_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static int amilo_rfkill_remove(struct platform_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) rfkill_unregister(amilo_rfkill_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) rfkill_destroy(amilo_rfkill_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static struct platform_driver amilo_rfkill_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) .name = KBUILD_MODNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) .probe = amilo_rfkill_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) .remove = amilo_rfkill_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static int __init amilo_rfkill_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (dmi_first_match(amilo_rfkill_id_table) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) rc = platform_driver_register(&amilo_rfkill_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) amilo_rfkill_pdev = platform_device_register_simple(KBUILD_MODNAME, -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (IS_ERR(amilo_rfkill_pdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) rc = PTR_ERR(amilo_rfkill_pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) platform_driver_unregister(&amilo_rfkill_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static void __exit amilo_rfkill_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) platform_device_unregister(amilo_rfkill_pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) platform_driver_unregister(&amilo_rfkill_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) MODULE_AUTHOR("Ben Hutchings <ben@decadent.org.uk>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) MODULE_DEVICE_TABLE(dmi, amilo_rfkill_id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) module_init(amilo_rfkill_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) module_exit(amilo_rfkill_exit);