Skip to content

Commit 1490839

Browse files
anisseMatthew Garrett
authored andcommitted
asus-laptop: Add rfkill support for Pegatron Lucid tablet
Add three new rfkill switches in this driver that are specific to Pegatron Lucid tablet. Please note that you might not need all three switches. For example if you don't have a 3G module inside your tablet. Also, on my device, the gpio for the wifi/bt module is connected to the bluetooth line. Therefore to activate your wireless lan interface, you need to use the "pega-bt" rfkill switch. Finally, the rfkill switch only works before the wireless module is loaded the first time. Unloading ath9k doesn't help, a reboot is necessary. Signed-off-by: Anisse Astier <anisse@astier.eu> Signed-off-by: Corentin Chary <corentincj@iksaif.net> Signed-off-by: Matthew Garrett <mjg@redhat.com>
1 parent b93f828 commit 1490839

1 file changed

Lines changed: 103 additions & 0 deletions

File tree

‎drivers/platform/x86/asus-laptop.c‎

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ MODULE_PARM_DESC(als_status, "Set the ALS status on boot "
186186

187187
#define METHOD_PEGA_ENABLE "ENPR"
188188
#define METHOD_PEGA_DISABLE "DAPR"
189+
#define PEGA_WLAN 0x00
190+
#define PEGA_BLUETOOTH 0x01
191+
#define PEGA_WWAN 0x02
189192
#define PEGA_ALS 0x04
190193
#define PEGA_ALS_POWER 0x05
191194

@@ -212,6 +215,15 @@ struct asus_led {
212215
const char *method;
213216
};
214217

218+
/*
219+
* Same thing for rfkill
220+
*/
221+
struct asus_pega_rfkill {
222+
int control_id; /* type of control. Maps to PEGA_* values */
223+
struct rfkill *rfkill;
224+
struct asus_laptop *asus;
225+
};
226+
215227
/*
216228
* This is the main structure, we can use it to store anything interesting
217229
* about the hotk device
@@ -246,6 +258,10 @@ struct asus_laptop {
246258

247259
struct rfkill *gps_rfkill;
248260

261+
struct asus_pega_rfkill wlanrfk;
262+
struct asus_pega_rfkill btrfk;
263+
struct asus_pega_rfkill wwanrfk;
264+
249265
acpi_handle handle; /* the handle of the hotk device */
250266
u32 ledd_status; /* status of the LED display */
251267
u8 light_level; /* light sensor level */
@@ -1263,6 +1279,86 @@ static int asus_rfkill_init(struct asus_laptop *asus)
12631279
return result;
12641280
}
12651281

1282+
static int pega_rfkill_set(void *data, bool blocked)
1283+
{
1284+
struct asus_pega_rfkill *pega_rfk = data;
1285+
1286+
int ret = asus_pega_lucid_set(pega_rfk->asus, pega_rfk->control_id, !blocked);
1287+
pr_warn("Setting rfkill %d, to %d; returned %d\n", pega_rfk->control_id, !blocked, ret);
1288+
1289+
return ret;
1290+
}
1291+
1292+
static const struct rfkill_ops pega_rfkill_ops = {
1293+
.set_block = pega_rfkill_set,
1294+
};
1295+
1296+
static void pega_rfkill_terminate(struct asus_pega_rfkill *pega_rfk)
1297+
{
1298+
pr_warn("Terminating %d\n", pega_rfk->control_id);
1299+
if (pega_rfk->rfkill) {
1300+
rfkill_unregister(pega_rfk->rfkill);
1301+
rfkill_destroy(pega_rfk->rfkill);
1302+
pega_rfk->rfkill = NULL;
1303+
}
1304+
}
1305+
1306+
static void pega_rfkill_exit(struct asus_laptop *asus)
1307+
{
1308+
pega_rfkill_terminate(&asus->wwanrfk);
1309+
pega_rfkill_terminate(&asus->btrfk);
1310+
pega_rfkill_terminate(&asus->wlanrfk);
1311+
}
1312+
1313+
static int pega_rfkill_setup(struct asus_laptop *asus, struct asus_pega_rfkill *pega_rfk,
1314+
const char *name, int controlid, int rfkill_type)
1315+
{
1316+
int result;
1317+
1318+
pr_warn("Setting up rfk %s, control %d, type %d\n", name, controlid, rfkill_type);
1319+
pega_rfk->control_id = controlid;
1320+
pega_rfk->asus = asus;
1321+
pega_rfk->rfkill = rfkill_alloc(name, &asus->platform_device->dev,
1322+
rfkill_type, &pega_rfkill_ops, pega_rfk);
1323+
if (!pega_rfk->rfkill)
1324+
return -EINVAL;
1325+
1326+
result = rfkill_register(pega_rfk->rfkill);
1327+
if (result) {
1328+
rfkill_destroy(pega_rfk->rfkill);
1329+
pega_rfk->rfkill = NULL;
1330+
}
1331+
1332+
return result;
1333+
}
1334+
1335+
static int pega_rfkill_init(struct asus_laptop *asus)
1336+
{
1337+
int ret = 0;
1338+
1339+
if(!asus->is_pega_lucid)
1340+
return -ENODEV;
1341+
1342+
ret = pega_rfkill_setup(asus, &asus->wlanrfk, "pega-wlan", PEGA_WLAN, RFKILL_TYPE_WLAN);
1343+
if(ret)
1344+
return ret;
1345+
ret = pega_rfkill_setup(asus, &asus->btrfk, "pega-bt", PEGA_BLUETOOTH, RFKILL_TYPE_BLUETOOTH);
1346+
if(ret)
1347+
goto err_btrfk;
1348+
ret = pega_rfkill_setup(asus, &asus->wwanrfk, "pega-wwan", PEGA_WWAN, RFKILL_TYPE_WWAN);
1349+
if(ret)
1350+
goto err_wwanrfk;
1351+
1352+
pr_warn("Pega rfkill init succeeded\n");
1353+
return 0;
1354+
err_wwanrfk:
1355+
pega_rfkill_terminate(&asus->btrfk);
1356+
err_btrfk:
1357+
pega_rfkill_terminate(&asus->wlanrfk);
1358+
1359+
return ret;
1360+
}
1361+
12661362
/*
12671363
* Input device (i.e. hotkeys)
12681364
*/
@@ -1697,9 +1793,15 @@ static int __devinit asus_acpi_add(struct acpi_device *device)
16971793
if (result && result != -ENODEV)
16981794
goto fail_pega_accel;
16991795

1796+
result = pega_rfkill_init(asus);
1797+
if (result && result != -ENODEV)
1798+
goto fail_pega_rfkill;
1799+
17001800
asus_device_present = true;
17011801
return 0;
17021802

1803+
fail_pega_rfkill:
1804+
pega_accel_exit(asus);
17031805
fail_pega_accel:
17041806
asus_rfkill_exit(asus);
17051807
fail_rfkill:
@@ -1726,6 +1828,7 @@ static int asus_acpi_remove(struct acpi_device *device, int type)
17261828
asus_led_exit(asus);
17271829
asus_input_exit(asus);
17281830
pega_accel_exit(asus);
1831+
pega_rfkill_exit(asus);
17291832
asus_platform_exit(asus);
17301833

17311834
kfree(asus->name);

0 commit comments

Comments
 (0)