aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/platform
diff options
context:
space:
mode:
authorCorentin Chary <corentincj@iksaif.net>2010-01-26 15:02:23 -0500
committerCorentin Chary <corentincj@iksaif.net>2010-02-28 13:35:13 -0500
commit2a1fd64cb70a42563d2313eb70c6495d2c88b36d (patch)
treeca14add9bc99d6afa5d77d648f4a521d12013750 /drivers/platform
parentaee0afb8cb52178164accfec9cfc58bc27b597b3 (diff)
asus-laptop: use device_create_file() instead of platform_group
There is two reason to do that: - we don't want a "gps" file if the model doesn't have a gps - we don't want to use global variables anymore Signed-off-by: Corentin Chary <corentincj@iksaif.net>
Diffstat (limited to 'drivers/platform')
-rw-r--r--drivers/platform/x86/asus-laptop.c166
1 files changed, 84 insertions, 82 deletions
diff --git a/drivers/platform/x86/asus-laptop.c b/drivers/platform/x86/asus-laptop.c
index ae5302646c4e..d0d117b0cf79 100644
--- a/drivers/platform/x86/asus-laptop.c
+++ b/drivers/platform/x86/asus-laptop.c
@@ -918,6 +918,8 @@ static ssize_t show_disp(struct device *dev,
918{ 918{
919 struct asus_laptop *asus = dev_get_drvdata(dev); 919 struct asus_laptop *asus = dev_get_drvdata(dev);
920 920
921 if (!display_get_handle)
922 return -ENODEV;
921 return sprintf(buf, "%d\n", read_display(asus)); 923 return sprintf(buf, "%d\n", read_display(asus));
922} 924}
923 925
@@ -1191,77 +1193,113 @@ static void asus_acpi_notify(struct acpi_device *device, u32 event)
1191 asus_input_notify(asus, event); 1193 asus_input_notify(asus, event);
1192} 1194}
1193 1195
1194#define ASUS_CREATE_DEVICE_ATTR(_name) \ 1196static DEVICE_ATTR(infos, S_IRUGO, show_infos, NULL);
1195 struct device_attribute dev_attr_##_name = { \ 1197static DEVICE_ATTR(wlan, S_IRUGO | S_IWUSR, show_wlan, store_wlan);
1196 .attr = { \ 1198static DEVICE_ATTR(bluetooth, S_IRUGO | S_IWUSR, show_bluetooth,
1197 .name = __stringify(_name), \ 1199 store_bluetooth);
1198 .mode = 0 }, \ 1200static DEVICE_ATTR(display, S_IRUGO | S_IWUSR, show_disp, store_disp);
1199 .show = NULL, \ 1201static DEVICE_ATTR(ledd, S_IRUGO | S_IWUSR, show_ledd, store_ledd);
1200 .store = NULL, \ 1202static DEVICE_ATTR(ls_level, S_IRUGO | S_IWUSR, show_lslvl, store_lslvl);
1203static DEVICE_ATTR(ls_switch, S_IRUGO | S_IWUSR, show_lssw, store_lssw);
1204static DEVICE_ATTR(gps, S_IRUGO | S_IWUSR, show_gps, store_gps);
1205
1206static void asus_sysfs_exit(struct asus_laptop *asus)
1207{
1208 struct platform_device *device = asus->platform_device;
1209
1210 device_remove_file(&device->dev, &dev_attr_infos);
1211 device_remove_file(&device->dev, &dev_attr_wlan);
1212 device_remove_file(&device->dev, &dev_attr_bluetooth);
1213 device_remove_file(&device->dev, &dev_attr_display);
1214 device_remove_file(&device->dev, &dev_attr_ledd);
1215 device_remove_file(&device->dev, &dev_attr_ls_switch);
1216 device_remove_file(&device->dev, &dev_attr_ls_level);
1217 device_remove_file(&device->dev, &dev_attr_gps);
1218}
1219
1220static int asus_sysfs_init(struct asus_laptop *asus)
1221{
1222 struct platform_device *device = asus->platform_device;
1223 int err;
1224
1225 err = device_create_file(&device->dev, &dev_attr_infos);
1226 if (err)
1227 return err;
1228
1229 if (!acpi_check_handle(asus->handle, METHOD_WLAN, NULL)) {
1230 err = device_create_file(&device->dev, &dev_attr_wlan);
1231 if (err)
1232 return err;
1201 } 1233 }
1202 1234
1203#define ASUS_SET_DEVICE_ATTR(_name, _mode, _show, _store) \ 1235 if (!acpi_check_handle(asus->handle, METHOD_BLUETOOTH, NULL)) {
1204 do { \ 1236 err = device_create_file(&device->dev, &dev_attr_bluetooth);
1205 dev_attr_##_name.attr.mode = _mode; \ 1237 if (err)
1206 dev_attr_##_name.show = _show; \ 1238 return err;
1207 dev_attr_##_name.store = _store; \ 1239 }
1208 } while(0)
1209
1210static ASUS_CREATE_DEVICE_ATTR(infos);
1211static ASUS_CREATE_DEVICE_ATTR(wlan);
1212static ASUS_CREATE_DEVICE_ATTR(bluetooth);
1213static ASUS_CREATE_DEVICE_ATTR(display);
1214static ASUS_CREATE_DEVICE_ATTR(ledd);
1215static ASUS_CREATE_DEVICE_ATTR(ls_switch);
1216static ASUS_CREATE_DEVICE_ATTR(ls_level);
1217static ASUS_CREATE_DEVICE_ATTR(gps);
1218
1219static struct attribute *asuspf_attributes[] = {
1220 &dev_attr_infos.attr,
1221 &dev_attr_wlan.attr,
1222 &dev_attr_bluetooth.attr,
1223 &dev_attr_display.attr,
1224 &dev_attr_ledd.attr,
1225 &dev_attr_ls_switch.attr,
1226 &dev_attr_ls_level.attr,
1227 &dev_attr_gps.attr,
1228 NULL
1229};
1230 1240
1231static struct attribute_group platform_attribute_group = { 1241 if (!acpi_check_handle(asus->handle, METHOD_SWITCH_DISPLAY, NULL)) {
1232 .attrs = asuspf_attributes 1242 err = device_create_file(&device->dev, &dev_attr_display);
1233}; 1243 if (err)
1244 return err;
1245 }
1246
1247 if (!acpi_check_handle(asus->handle, METHOD_LEDD, NULL)) {
1248 err = device_create_file(&device->dev, &dev_attr_ledd);
1249 if (err)
1250 return err;
1251 }
1252
1253 if (!acpi_check_handle(asus->handle, METHOD_ALS_CONTROL, NULL) &&
1254 !acpi_check_handle(asus->handle, METHOD_ALS_LEVEL, NULL)) {
1255 err = device_create_file(&device->dev, &dev_attr_ls_switch);
1256 if (err)
1257 return err;
1258 err = device_create_file(&device->dev, &dev_attr_ls_level);
1259 if (err)
1260 return err;
1261 }
1262
1263 if (!acpi_check_handle(asus->handle, METHOD_GPS_ON, NULL) &&
1264 !acpi_check_handle(asus->handle, METHOD_GPS_OFF, NULL) &&
1265 !acpi_check_handle(asus->handle, METHOD_GPS_STATUS, NULL)) {
1266 err = device_create_file(&device->dev, &dev_attr_gps);
1267 if (err)
1268 return err;
1269 }
1270
1271 return err;
1272}
1234 1273
1235static int asus_platform_init(struct asus_laptop *asus) 1274static int asus_platform_init(struct asus_laptop *asus)
1236{ 1275{
1237 int result; 1276 int err;
1238 1277
1239 asus->platform_device = platform_device_alloc(ASUS_LAPTOP_FILE, -1); 1278 asus->platform_device = platform_device_alloc(ASUS_LAPTOP_FILE, -1);
1240 if (!asus->platform_device) 1279 if (!asus->platform_device)
1241 return -ENOMEM; 1280 return -ENOMEM;
1242 platform_set_drvdata(asus->platform_device, asus); 1281 platform_set_drvdata(asus->platform_device, asus);
1243 1282
1244 result = platform_device_add(asus->platform_device); 1283 err = platform_device_add(asus->platform_device);
1245 if (result) 1284 if (err)
1246 goto fail_platform_device; 1285 goto fail_platform_device;
1247 1286
1248 result = sysfs_create_group(&asus->platform_device->dev.kobj, 1287 err = asus_sysfs_init(asus);
1249 &platform_attribute_group); 1288 if (err)
1250 if (result)
1251 goto fail_sysfs; 1289 goto fail_sysfs;
1252 return 0; 1290 return 0;
1253 1291
1254fail_sysfs: 1292fail_sysfs:
1293 asus_sysfs_exit(asus);
1255 platform_device_del(asus->platform_device); 1294 platform_device_del(asus->platform_device);
1256fail_platform_device: 1295fail_platform_device:
1257 platform_device_put(asus->platform_device); 1296 platform_device_put(asus->platform_device);
1258 return result; 1297 return err;
1259} 1298}
1260 1299
1261static void asus_platform_exit(struct asus_laptop *asus) 1300static void asus_platform_exit(struct asus_laptop *asus)
1262{ 1301{
1263 sysfs_remove_group(&asus->platform_device->dev.kobj, 1302 asus_sysfs_exit(asus);
1264 &platform_attribute_group);
1265 platform_device_unregister(asus->platform_device); 1303 platform_device_unregister(asus->platform_device);
1266} 1304}
1267 1305
@@ -1272,40 +1310,6 @@ static struct platform_driver platform_driver = {
1272 } 1310 }
1273}; 1311};
1274 1312
1275static void asus_laptop_add_fs(struct asus_laptop *asus)
1276{
1277 ASUS_SET_DEVICE_ATTR(infos, 0444, show_infos, NULL);
1278
1279 if (!acpi_check_handle(asus->handle, METHOD_WLAN, NULL))
1280 ASUS_SET_DEVICE_ATTR(wlan, 0644, show_wlan, store_wlan);
1281
1282 if (!acpi_check_handle(asus->handle, METHOD_BLUETOOTH, NULL))
1283 ASUS_SET_DEVICE_ATTR(bluetooth, 0644,
1284 show_bluetooth, store_bluetooth);
1285
1286 if (!acpi_check_handle(asus->handle, METHOD_SWITCH_DISPLAY, NULL)) {
1287 if (display_get_handle)
1288 ASUS_SET_DEVICE_ATTR(display, 0644, show_disp,
1289 store_disp);
1290 else
1291 ASUS_SET_DEVICE_ATTR(display, 0200, NULL, store_disp);
1292 }
1293
1294 if (!acpi_check_handle(asus->handle, METHOD_LEDD, NULL))
1295 ASUS_SET_DEVICE_ATTR(ledd, 0644, show_ledd, store_ledd);
1296
1297 if (!acpi_check_handle(asus->handle, METHOD_ALS_CONTROL, NULL) &&
1298 !acpi_check_handle(asus->handle, METHOD_ALS_LEVEL, NULL)) {
1299 ASUS_SET_DEVICE_ATTR(ls_level, 0644, show_lslvl, store_lslvl);
1300 ASUS_SET_DEVICE_ATTR(ls_switch, 0644, show_lssw, store_lssw);
1301 }
1302
1303 if (!acpi_check_handle(asus->handle, METHOD_GPS_ON, NULL) &&
1304 !acpi_check_handle(asus->handle, METHOD_GPS_OFF, NULL) &&
1305 !acpi_check_handle(asus->handle, METHOD_GPS_STATUS, NULL))
1306 ASUS_SET_DEVICE_ATTR(gps, 0644, show_gps, store_gps);
1307}
1308
1309static int asus_handle_init(char *name, acpi_handle * handle, 1313static int asus_handle_init(char *name, acpi_handle * handle,
1310 char **paths, int num_paths) 1314 char **paths, int num_paths)
1311{ 1315{
@@ -1435,8 +1439,6 @@ static int __devinit asus_acpi_init(struct asus_laptop *asus)
1435 if (result) 1439 if (result)
1436 return result; 1440 return result;
1437 1441
1438 asus_laptop_add_fs(asus);
1439
1440 /* WLED and BLED are on by default */ 1442 /* WLED and BLED are on by default */
1441 if (bluetooth_status >= 0) 1443 if (bluetooth_status >= 0)
1442 asus_bluetooth_set(asus, !!bluetooth_status); 1444 asus_bluetooth_set(asus, !!bluetooth_status);