Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * Support for rfkill on some Fujitsu-Siemens Amilo laptops.
0004  * Copyright 2011 Ben Hutchings.
0005  *
0006  * Based in part on the fsam7440 driver, which is:
0007  * Copyright 2005 Alejandro Vidal Mata & Javier Vidal Mata.
0008  * and on the fsaa1655g driver, which is:
0009  * Copyright 2006 Martin Večeřa.
0010  */
0011 
0012 #include <linux/module.h>
0013 #include <linux/dmi.h>
0014 #include <linux/i8042.h>
0015 #include <linux/io.h>
0016 #include <linux/moduleparam.h>
0017 #include <linux/platform_device.h>
0018 #include <linux/rfkill.h>
0019 
0020 /*
0021  * These values were obtained from disassembling and debugging the
0022  * PM.exe program installed in the Fujitsu-Siemens AMILO A1655G
0023  */
0024 #define A1655_WIFI_COMMAND  0x10C5
0025 #define A1655_WIFI_ON       0x25
0026 #define A1655_WIFI_OFF      0x45
0027 
0028 static int amilo_a1655_rfkill_set_block(void *data, bool blocked)
0029 {
0030     u8 param = blocked ? A1655_WIFI_OFF : A1655_WIFI_ON;
0031     int rc;
0032 
0033     i8042_lock_chip();
0034     rc = i8042_command(&param, A1655_WIFI_COMMAND);
0035     i8042_unlock_chip();
0036     return rc;
0037 }
0038 
0039 static const struct rfkill_ops amilo_a1655_rfkill_ops = {
0040     .set_block = amilo_a1655_rfkill_set_block
0041 };
0042 
0043 /*
0044  * These values were obtained from disassembling the PM.exe program
0045  * installed in the Fujitsu-Siemens AMILO M 7440
0046  */
0047 #define M7440_PORT1     0x118f
0048 #define M7440_PORT2     0x118e
0049 #define M7440_RADIO_ON1     0x12
0050 #define M7440_RADIO_ON2     0x80
0051 #define M7440_RADIO_OFF1    0x10
0052 #define M7440_RADIO_OFF2    0x00
0053 
0054 static int amilo_m7440_rfkill_set_block(void *data, bool blocked)
0055 {
0056     u8 val1 = blocked ? M7440_RADIO_OFF1 : M7440_RADIO_ON1;
0057     u8 val2 = blocked ? M7440_RADIO_OFF2 : M7440_RADIO_ON2;
0058 
0059     outb(val1, M7440_PORT1);
0060     outb(val2, M7440_PORT2);
0061 
0062     /* Check whether the state has changed correctly */
0063     if (inb(M7440_PORT1) != val1 || inb(M7440_PORT2) != val2)
0064         return -EIO;
0065 
0066     return 0;
0067 }
0068 
0069 static const struct rfkill_ops amilo_m7440_rfkill_ops = {
0070     .set_block = amilo_m7440_rfkill_set_block
0071 };
0072 
0073 static const struct dmi_system_id amilo_rfkill_id_table[] = {
0074     {
0075         .matches = {
0076             DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
0077             DMI_MATCH(DMI_BOARD_NAME, "AMILO A1655"),
0078         },
0079         .driver_data = (void *)&amilo_a1655_rfkill_ops
0080     },
0081     {
0082         .matches = {
0083             DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
0084             DMI_MATCH(DMI_BOARD_NAME, "AMILO L1310"),
0085         },
0086         .driver_data = (void *)&amilo_a1655_rfkill_ops
0087     },
0088     {
0089         .matches = {
0090             DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
0091             DMI_MATCH(DMI_BOARD_NAME, "AMILO M7440"),
0092         },
0093         .driver_data = (void *)&amilo_m7440_rfkill_ops
0094     },
0095     {}
0096 };
0097 
0098 static struct platform_device *amilo_rfkill_pdev;
0099 static struct rfkill *amilo_rfkill_dev;
0100 
0101 static int amilo_rfkill_probe(struct platform_device *device)
0102 {
0103     int rc;
0104     const struct dmi_system_id *system_id =
0105         dmi_first_match(amilo_rfkill_id_table);
0106 
0107     if (!system_id)
0108         return -ENXIO;
0109 
0110     amilo_rfkill_dev = rfkill_alloc(KBUILD_MODNAME, &device->dev,
0111                     RFKILL_TYPE_WLAN,
0112                     system_id->driver_data, NULL);
0113     if (!amilo_rfkill_dev)
0114         return -ENOMEM;
0115 
0116     rc = rfkill_register(amilo_rfkill_dev);
0117     if (rc)
0118         goto fail;
0119 
0120     return 0;
0121 
0122 fail:
0123     rfkill_destroy(amilo_rfkill_dev);
0124     return rc;
0125 }
0126 
0127 static int amilo_rfkill_remove(struct platform_device *device)
0128 {
0129     rfkill_unregister(amilo_rfkill_dev);
0130     rfkill_destroy(amilo_rfkill_dev);
0131     return 0;
0132 }
0133 
0134 static struct platform_driver amilo_rfkill_driver = {
0135     .driver = {
0136         .name   = KBUILD_MODNAME,
0137     },
0138     .probe  = amilo_rfkill_probe,
0139     .remove = amilo_rfkill_remove,
0140 };
0141 
0142 static int __init amilo_rfkill_init(void)
0143 {
0144     int rc;
0145 
0146     if (dmi_first_match(amilo_rfkill_id_table) == NULL)
0147         return -ENODEV;
0148 
0149     rc = platform_driver_register(&amilo_rfkill_driver);
0150     if (rc)
0151         return rc;
0152 
0153     amilo_rfkill_pdev = platform_device_register_simple(KBUILD_MODNAME, -1,
0154                                 NULL, 0);
0155     if (IS_ERR(amilo_rfkill_pdev)) {
0156         rc = PTR_ERR(amilo_rfkill_pdev);
0157         goto fail;
0158     }
0159 
0160     return 0;
0161 
0162 fail:
0163     platform_driver_unregister(&amilo_rfkill_driver);
0164     return rc;
0165 }
0166 
0167 static void __exit amilo_rfkill_exit(void)
0168 {
0169     platform_device_unregister(amilo_rfkill_pdev);
0170     platform_driver_unregister(&amilo_rfkill_driver);
0171 }
0172 
0173 MODULE_AUTHOR("Ben Hutchings <ben@decadent.org.uk>");
0174 MODULE_LICENSE("GPL");
0175 MODULE_DEVICE_TABLE(dmi, amilo_rfkill_id_table);
0176 
0177 module_init(amilo_rfkill_init);
0178 module_exit(amilo_rfkill_exit);