aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/platform/x86/asus-laptop.c
diff options
context:
space:
mode:
authorCorentin Chary <corentincj@iksaif.net>2011-12-15 02:27:33 -0500
committerMatthew Garrett <mjg@redhat.com>2012-03-20 12:02:16 -0400
commit40969c7dd6298718820e0818b5b5acef7b24923d (patch)
treea6ad43d54e7dca2f0691338a10300dd1a78f1f02 /drivers/platform/x86/asus-laptop.c
parentce6c468fd8f7f027953f9df97434423b8197009c (diff)
asus-laptop: cleanup rfkill code
Signed-off-by: Corentin Chary <corentincj@iksaif.net> Signed-off-by: Matthew Garrett <mjg@redhat.com>
Diffstat (limited to 'drivers/platform/x86/asus-laptop.c')
-rw-r--r--drivers/platform/x86/asus-laptop.c117
1 files changed, 52 insertions, 65 deletions
diff --git a/drivers/platform/x86/asus-laptop.c b/drivers/platform/x86/asus-laptop.c
index 3976cfac5ffe..db32d0337a7c 100644
--- a/drivers/platform/x86/asus-laptop.c
+++ b/drivers/platform/x86/asus-laptop.c
@@ -218,7 +218,7 @@ struct asus_led {
218/* 218/*
219 * Same thing for rfkill 219 * Same thing for rfkill
220 */ 220 */
221struct asus_pega_rfkill { 221struct asus_rfkill {
222 int control_id; /* type of control. Maps to PEGA_* values */ 222 int control_id; /* type of control. Maps to PEGA_* values */
223 struct rfkill *rfkill; 223 struct rfkill *rfkill;
224 struct asus_laptop *asus; 224 struct asus_laptop *asus;
@@ -256,11 +256,10 @@ struct asus_laptop {
256 int pega_acc_y; 256 int pega_acc_y;
257 int pega_acc_z; 257 int pega_acc_z;
258 258
259 struct rfkill *gps_rfkill; 259 struct asus_rfkill wlan;
260 260 struct asus_rfkill bluetooth;
261 struct asus_pega_rfkill wlanrfk; 261 struct asus_rfkill wwan;
262 struct asus_pega_rfkill btrfk; 262 struct asus_rfkill gps;
263 struct asus_pega_rfkill wwanrfk;
264 263
265 acpi_handle handle; /* the handle of the hotk device */ 264 acpi_handle handle; /* the handle of the hotk device */
266 u32 ledd_status; /* status of the LED display */ 265 u32 ledd_status; /* status of the LED display */
@@ -1228,7 +1227,7 @@ static ssize_t store_gps(struct device *dev, struct device_attribute *attr,
1228 ret = asus_gps_switch(asus, !!value); 1227 ret = asus_gps_switch(asus, !!value);
1229 if (ret) 1228 if (ret)
1230 return ret; 1229 return ret;
1231 rfkill_set_sw_state(asus->gps_rfkill, !value); 1230 rfkill_set_sw_state(asus->gps.rfkill, !value);
1232 return rv; 1231 return rv;
1233} 1232}
1234 1233
@@ -1246,13 +1245,22 @@ static const struct rfkill_ops asus_gps_rfkill_ops = {
1246 .set_block = asus_gps_rfkill_set, 1245 .set_block = asus_gps_rfkill_set,
1247}; 1246};
1248 1247
1248static void asus_rfkill_terminate(struct asus_rfkill *rfk)
1249{
1250 if (!rfk->rfkill)
1251 return ;
1252
1253 rfkill_unregister(rfk->rfkill);
1254 rfkill_destroy(rfk->rfkill);
1255 rfk->rfkill = NULL;
1256}
1257
1249static void asus_rfkill_exit(struct asus_laptop *asus) 1258static void asus_rfkill_exit(struct asus_laptop *asus)
1250{ 1259{
1251 if (asus->gps_rfkill) { 1260 asus_rfkill_terminate(&asus->wwan);
1252 rfkill_unregister(asus->gps_rfkill); 1261 asus_rfkill_terminate(&asus->bluetooth);
1253 rfkill_destroy(asus->gps_rfkill); 1262 asus_rfkill_terminate(&asus->wlan);
1254 asus->gps_rfkill = NULL; 1263 asus_rfkill_terminate(&asus->gps);
1255 }
1256} 1264}
1257 1265
1258static int asus_rfkill_init(struct asus_laptop *asus) 1266static int asus_rfkill_init(struct asus_laptop *asus)
@@ -1264,16 +1272,16 @@ static int asus_rfkill_init(struct asus_laptop *asus)
1264 acpi_check_handle(asus->handle, METHOD_GPS_STATUS, NULL)) 1272 acpi_check_handle(asus->handle, METHOD_GPS_STATUS, NULL))
1265 return 0; 1273 return 0;
1266 1274
1267 asus->gps_rfkill = rfkill_alloc("asus-gps", &asus->platform_device->dev, 1275 asus->gps.rfkill = rfkill_alloc("asus-gps", &asus->platform_device->dev,
1268 RFKILL_TYPE_GPS, 1276 RFKILL_TYPE_GPS,
1269 &asus_gps_rfkill_ops, asus); 1277 &asus_gps_rfkill_ops, asus);
1270 if (!asus->gps_rfkill) 1278 if (!asus->gps.rfkill)
1271 return -EINVAL; 1279 return -EINVAL;
1272 1280
1273 result = rfkill_register(asus->gps_rfkill); 1281 result = rfkill_register(asus->gps.rfkill);
1274 if (result) { 1282 if (result) {
1275 rfkill_destroy(asus->gps_rfkill); 1283 rfkill_destroy(asus->gps.rfkill);
1276 asus->gps_rfkill = NULL; 1284 asus->gps.rfkill = NULL;
1277 } 1285 }
1278 1286
1279 return result; 1287 return result;
@@ -1281,11 +1289,9 @@ static int asus_rfkill_init(struct asus_laptop *asus)
1281 1289
1282static int pega_rfkill_set(void *data, bool blocked) 1290static int pega_rfkill_set(void *data, bool blocked)
1283{ 1291{
1284 struct asus_pega_rfkill *pega_rfk = data; 1292 struct asus_rfkill *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 1293
1294 int ret = asus_pega_lucid_set(rfk->asus, rfk->control_id, !blocked);
1289 return ret; 1295 return ret;
1290} 1296}
1291 1297
@@ -1293,40 +1299,22 @@ static const struct rfkill_ops pega_rfkill_ops = {
1293 .set_block = pega_rfkill_set, 1299 .set_block = pega_rfkill_set,
1294}; 1300};
1295 1301
1296static void pega_rfkill_terminate(struct asus_pega_rfkill *pega_rfk) 1302static int pega_rfkill_setup(struct asus_laptop *asus, struct asus_rfkill *rfk,
1297{ 1303 const char *name, int controlid, int rfkill_type)
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
1306static 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
1313static int pega_rfkill_setup(struct asus_laptop *asus, struct asus_pega_rfkill *pega_rfk,
1314 const char *name, int controlid, int rfkill_type)
1315{ 1304{
1316 int result; 1305 int result;
1317 1306
1318 pr_warn("Setting up rfk %s, control %d, type %d\n", name, controlid, rfkill_type); 1307 rfk->control_id = controlid;
1319 pega_rfk->control_id = controlid; 1308 rfk->asus = asus;
1320 pega_rfk->asus = asus; 1309 rfk->rfkill = rfkill_alloc(name, &asus->platform_device->dev,
1321 pega_rfk->rfkill = rfkill_alloc(name, &asus->platform_device->dev, 1310 rfkill_type, &pega_rfkill_ops, rfk);
1322 rfkill_type, &pega_rfkill_ops, pega_rfk); 1311 if (!rfk->rfkill)
1323 if (!pega_rfk->rfkill)
1324 return -EINVAL; 1312 return -EINVAL;
1325 1313
1326 result = rfkill_register(pega_rfk->rfkill); 1314 result = rfkill_register(rfk->rfkill);
1327 if (result) { 1315 if (result) {
1328 rfkill_destroy(pega_rfk->rfkill); 1316 rfkill_destroy(rfk->rfkill);
1329 pega_rfk->rfkill = NULL; 1317 rfk->rfkill = NULL;
1330 } 1318 }
1331 1319
1332 return result; 1320 return result;
@@ -1339,22 +1327,22 @@ static int pega_rfkill_init(struct asus_laptop *asus)
1339 if(!asus->is_pega_lucid) 1327 if(!asus->is_pega_lucid)
1340 return -ENODEV; 1328 return -ENODEV;
1341 1329
1342 ret = pega_rfkill_setup(asus, &asus->wlanrfk, "pega-wlan", PEGA_WLAN, RFKILL_TYPE_WLAN); 1330 ret = pega_rfkill_setup(asus, &asus->wlan, "pega-wlan",
1331 PEGA_WLAN, RFKILL_TYPE_WLAN);
1343 if(ret) 1332 if(ret)
1344 return ret; 1333 goto exit;
1345 ret = pega_rfkill_setup(asus, &asus->btrfk, "pega-bt", PEGA_BLUETOOTH, RFKILL_TYPE_BLUETOOTH); 1334
1346 if(ret) 1335 ret = pega_rfkill_setup(asus, &asus->bluetooth, "pega-bt",
1347 goto err_btrfk; 1336 PEGA_BLUETOOTH, RFKILL_TYPE_BLUETOOTH);
1348 ret = pega_rfkill_setup(asus, &asus->wwanrfk, "pega-wwan", PEGA_WWAN, RFKILL_TYPE_WWAN);
1349 if(ret) 1337 if(ret)
1350 goto err_wwanrfk; 1338 goto exit;
1351 1339
1352 pr_warn("Pega rfkill init succeeded\n"); 1340 ret = pega_rfkill_setup(asus, &asus->wwan, "pega-wwan",
1353 return 0; 1341 PEGA_WWAN, RFKILL_TYPE_WWAN);
1354err_wwanrfk: 1342
1355 pega_rfkill_terminate(&asus->btrfk); 1343exit:
1356err_btrfk: 1344 if (ret)
1357 pega_rfkill_terminate(&asus->wlanrfk); 1345 asus_rfkill_exit(asus);
1358 1346
1359 return ret; 1347 return ret;
1360} 1348}
@@ -1377,7 +1365,7 @@ static int asus_input_init(struct asus_laptop *asus)
1377 1365
1378 input = input_allocate_device(); 1366 input = input_allocate_device();
1379 if (!input) { 1367 if (!input) {
1380 pr_info("Unable to allocate input device\n"); 1368 pr_warn("Unable to allocate input device\n");
1381 return -ENOMEM; 1369 return -ENOMEM;
1382 } 1370 }
1383 input->name = "Asus Laptop extra buttons"; 1371 input->name = "Asus Laptop extra buttons";
@@ -1392,7 +1380,7 @@ static int asus_input_init(struct asus_laptop *asus)
1392 } 1380 }
1393 error = input_register_device(input); 1381 error = input_register_device(input);
1394 if (error) { 1382 if (error) {
1395 pr_info("Unable to register input device\n"); 1383 pr_warn("Unable to register input device\n");
1396 goto err_free_keymap; 1384 goto err_free_keymap;
1397 } 1385 }
1398 1386
@@ -1830,7 +1818,6 @@ static int asus_acpi_remove(struct acpi_device *device, int type)
1830 asus_led_exit(asus); 1818 asus_led_exit(asus);
1831 asus_input_exit(asus); 1819 asus_input_exit(asus);
1832 pega_accel_exit(asus); 1820 pega_accel_exit(asus);
1833 pega_rfkill_exit(asus);
1834 asus_platform_exit(asus); 1821 asus_platform_exit(asus);
1835 1822
1836 kfree(asus->name); 1823 kfree(asus->name);