platform_profile.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /* Platform profile sysfs interface */
  3. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  4. #include <linux/acpi.h>
  5. #include <linux/bits.h>
  6. #include <linux/cleanup.h>
  7. #include <linux/init.h>
  8. #include <linux/mutex.h>
  9. #include <linux/platform_profile.h>
  10. #include <linux/sysfs.h>
  11. #define to_pprof_handler(d) (container_of(d, struct platform_profile_handler, dev))
  12. static DEFINE_MUTEX(profile_lock);
  13. struct platform_profile_handler {
  14. const char *name;
  15. struct device dev;
  16. int minor;
  17. unsigned long choices[BITS_TO_LONGS(PLATFORM_PROFILE_LAST)];
  18. unsigned long hidden_choices[BITS_TO_LONGS(PLATFORM_PROFILE_LAST)];
  19. const struct platform_profile_ops *ops;
  20. };
  21. struct aggregate_choices_data {
  22. unsigned long aggregate[BITS_TO_LONGS(PLATFORM_PROFILE_LAST)];
  23. int count;
  24. };
  25. static const char * const profile_names[] = {
  26. [PLATFORM_PROFILE_LOW_POWER] = "low-power",
  27. [PLATFORM_PROFILE_COOL] = "cool",
  28. [PLATFORM_PROFILE_QUIET] = "quiet",
  29. [PLATFORM_PROFILE_BALANCED] = "balanced",
  30. [PLATFORM_PROFILE_BALANCED_PERFORMANCE] = "balanced-performance",
  31. [PLATFORM_PROFILE_PERFORMANCE] = "performance",
  32. [PLATFORM_PROFILE_MAX_POWER] = "max-power",
  33. [PLATFORM_PROFILE_CUSTOM] = "custom",
  34. };
  35. static_assert(ARRAY_SIZE(profile_names) == PLATFORM_PROFILE_LAST);
  36. static DEFINE_IDA(platform_profile_ida);
  37. /**
  38. * _commmon_choices_show - Show the available profile choices
  39. * @choices: The available profile choices
  40. * @buf: The buffer to write to
  41. *
  42. * Return: The number of bytes written
  43. */
  44. static ssize_t _commmon_choices_show(unsigned long *choices, char *buf)
  45. {
  46. int i, len = 0;
  47. for_each_set_bit(i, choices, PLATFORM_PROFILE_LAST) {
  48. if (len == 0)
  49. len += sysfs_emit_at(buf, len, "%s", profile_names[i]);
  50. else
  51. len += sysfs_emit_at(buf, len, " %s", profile_names[i]);
  52. }
  53. len += sysfs_emit_at(buf, len, "\n");
  54. return len;
  55. }
  56. /**
  57. * _store_class_profile - Set the profile for a class device
  58. * @dev: The class device
  59. * @data: The profile to set
  60. *
  61. * Return: 0 on success, -errno on failure
  62. */
  63. static int _store_class_profile(struct device *dev, void *data)
  64. {
  65. struct platform_profile_handler *handler;
  66. int *bit = (int *)data;
  67. lockdep_assert_held(&profile_lock);
  68. handler = to_pprof_handler(dev);
  69. if (!test_bit(*bit, handler->choices) && !test_bit(*bit, handler->hidden_choices))
  70. return -EOPNOTSUPP;
  71. return handler->ops->profile_set(dev, *bit);
  72. }
  73. /**
  74. * _notify_class_profile - Notify the class device of a profile change
  75. * @dev: The class device
  76. * @data: Unused
  77. *
  78. * Return: 0 on success, -errno on failure
  79. */
  80. static int _notify_class_profile(struct device *dev, void *data)
  81. {
  82. struct platform_profile_handler *handler = to_pprof_handler(dev);
  83. lockdep_assert_held(&profile_lock);
  84. sysfs_notify(&handler->dev.kobj, NULL, "profile");
  85. kobject_uevent(&handler->dev.kobj, KOBJ_CHANGE);
  86. return 0;
  87. }
  88. /**
  89. * get_class_profile - Show the current profile for a class device
  90. * @dev: The class device
  91. * @profile: The profile to return
  92. *
  93. * Return: 0 on success, -errno on failure
  94. */
  95. static int get_class_profile(struct device *dev,
  96. enum platform_profile_option *profile)
  97. {
  98. struct platform_profile_handler *handler;
  99. enum platform_profile_option val;
  100. int err;
  101. lockdep_assert_held(&profile_lock);
  102. handler = to_pprof_handler(dev);
  103. err = handler->ops->profile_get(dev, &val);
  104. if (err) {
  105. pr_err("Failed to get profile for handler %s\n", handler->name);
  106. return err;
  107. }
  108. if (WARN_ON(val >= PLATFORM_PROFILE_LAST))
  109. return -EINVAL;
  110. *profile = val;
  111. return 0;
  112. }
  113. /**
  114. * name_show - Show the name of the profile handler
  115. * @dev: The device
  116. * @attr: The attribute
  117. * @buf: The buffer to write to
  118. *
  119. * Return: The number of bytes written
  120. */
  121. static ssize_t name_show(struct device *dev, struct device_attribute *attr, char *buf)
  122. {
  123. struct platform_profile_handler *handler = to_pprof_handler(dev);
  124. return sysfs_emit(buf, "%s\n", handler->name);
  125. }
  126. static DEVICE_ATTR_RO(name);
  127. /**
  128. * choices_show - Show the available profile choices
  129. * @dev: The device
  130. * @attr: The attribute
  131. * @buf: The buffer to write to
  132. *
  133. * Return: The number of bytes written
  134. */
  135. static ssize_t choices_show(struct device *dev,
  136. struct device_attribute *attr,
  137. char *buf)
  138. {
  139. struct platform_profile_handler *handler = to_pprof_handler(dev);
  140. return _commmon_choices_show(handler->choices, buf);
  141. }
  142. static DEVICE_ATTR_RO(choices);
  143. /**
  144. * profile_show - Show the current profile for a class device
  145. * @dev: The device
  146. * @attr: The attribute
  147. * @buf: The buffer to write to
  148. *
  149. * Return: The number of bytes written
  150. */
  151. static ssize_t profile_show(struct device *dev,
  152. struct device_attribute *attr,
  153. char *buf)
  154. {
  155. enum platform_profile_option profile = PLATFORM_PROFILE_LAST;
  156. int err;
  157. scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) {
  158. err = get_class_profile(dev, &profile);
  159. if (err)
  160. return err;
  161. }
  162. return sysfs_emit(buf, "%s\n", profile_names[profile]);
  163. }
  164. /**
  165. * profile_store - Set the profile for a class device
  166. * @dev: The device
  167. * @attr: The attribute
  168. * @buf: The buffer to read from
  169. * @count: The number of bytes to read
  170. *
  171. * Return: The number of bytes read
  172. */
  173. static ssize_t profile_store(struct device *dev,
  174. struct device_attribute *attr,
  175. const char *buf, size_t count)
  176. {
  177. int index, ret;
  178. index = sysfs_match_string(profile_names, buf);
  179. if (index < 0)
  180. return -EINVAL;
  181. scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) {
  182. ret = _store_class_profile(dev, &index);
  183. if (ret)
  184. return ret;
  185. }
  186. sysfs_notify(acpi_kobj, NULL, "platform_profile");
  187. return count;
  188. }
  189. static DEVICE_ATTR_RW(profile);
  190. static struct attribute *profile_attrs[] = {
  191. &dev_attr_name.attr,
  192. &dev_attr_choices.attr,
  193. &dev_attr_profile.attr,
  194. NULL
  195. };
  196. ATTRIBUTE_GROUPS(profile);
  197. static void pprof_device_release(struct device *dev)
  198. {
  199. struct platform_profile_handler *pprof = to_pprof_handler(dev);
  200. kfree(pprof);
  201. }
  202. static const struct class platform_profile_class = {
  203. .name = "platform-profile",
  204. .dev_groups = profile_groups,
  205. .dev_release = pprof_device_release,
  206. };
  207. /**
  208. * _aggregate_choices - Aggregate the available profile choices
  209. * @dev: The device
  210. * @arg: struct aggregate_choices_data, with it's aggregate member bitmap
  211. * initially filled with ones
  212. *
  213. * Return: 0 on success, -errno on failure
  214. */
  215. static int _aggregate_choices(struct device *dev, void *arg)
  216. {
  217. unsigned long tmp[BITS_TO_LONGS(PLATFORM_PROFILE_LAST)];
  218. struct aggregate_choices_data *data = arg;
  219. struct platform_profile_handler *handler;
  220. lockdep_assert_held(&profile_lock);
  221. handler = to_pprof_handler(dev);
  222. bitmap_or(tmp, handler->choices, handler->hidden_choices, PLATFORM_PROFILE_LAST);
  223. bitmap_and(data->aggregate, tmp, data->aggregate, PLATFORM_PROFILE_LAST);
  224. data->count++;
  225. return 0;
  226. }
  227. /**
  228. * _remove_hidden_choices - Remove hidden choices from aggregate data
  229. * @dev: The device
  230. * @arg: struct aggregate_choices_data
  231. *
  232. * Return: 0 on success, -errno on failure
  233. */
  234. static int _remove_hidden_choices(struct device *dev, void *arg)
  235. {
  236. struct aggregate_choices_data *data = arg;
  237. struct platform_profile_handler *handler;
  238. lockdep_assert_held(&profile_lock);
  239. handler = to_pprof_handler(dev);
  240. bitmap_andnot(data->aggregate, handler->choices,
  241. handler->hidden_choices, PLATFORM_PROFILE_LAST);
  242. return 0;
  243. }
  244. /**
  245. * platform_profile_choices_show - Show the available profile choices for legacy sysfs interface
  246. * @kobj: The kobject
  247. * @attr: The attribute
  248. * @buf: The buffer to write to
  249. *
  250. * Return: The number of bytes written
  251. */
  252. static ssize_t platform_profile_choices_show(struct kobject *kobj,
  253. struct kobj_attribute *attr,
  254. char *buf)
  255. {
  256. struct aggregate_choices_data data = {
  257. .aggregate = { [0 ... BITS_TO_LONGS(PLATFORM_PROFILE_LAST) - 1] = ~0UL },
  258. .count = 0,
  259. };
  260. int err;
  261. scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) {
  262. err = class_for_each_device(&platform_profile_class, NULL,
  263. &data, _aggregate_choices);
  264. if (err)
  265. return err;
  266. if (data.count == 1) {
  267. err = class_for_each_device(&platform_profile_class, NULL,
  268. &data, _remove_hidden_choices);
  269. if (err)
  270. return err;
  271. }
  272. }
  273. /* no profile handler registered any more */
  274. if (bitmap_empty(data.aggregate, PLATFORM_PROFILE_LAST))
  275. return -EINVAL;
  276. return _commmon_choices_show(data.aggregate, buf);
  277. }
  278. /**
  279. * _aggregate_profiles - Aggregate the profiles for legacy sysfs interface
  280. * @dev: The device
  281. * @data: The profile to return
  282. *
  283. * Return: 0 on success, -errno on failure
  284. */
  285. static int _aggregate_profiles(struct device *dev, void *data)
  286. {
  287. enum platform_profile_option *profile = data;
  288. enum platform_profile_option val;
  289. int err;
  290. err = get_class_profile(dev, &val);
  291. if (err)
  292. return err;
  293. if (*profile != PLATFORM_PROFILE_LAST && *profile != val)
  294. *profile = PLATFORM_PROFILE_CUSTOM;
  295. else
  296. *profile = val;
  297. return 0;
  298. }
  299. /**
  300. * _store_and_notify - Store and notify a class from legacy sysfs interface
  301. * @dev: The device
  302. * @data: The profile to return
  303. *
  304. * Return: 0 on success, -errno on failure
  305. */
  306. static int _store_and_notify(struct device *dev, void *data)
  307. {
  308. enum platform_profile_option *profile = data;
  309. int err;
  310. err = _store_class_profile(dev, profile);
  311. if (err)
  312. return err;
  313. return _notify_class_profile(dev, NULL);
  314. }
  315. /**
  316. * platform_profile_show - Show the current profile for legacy sysfs interface
  317. * @kobj: The kobject
  318. * @attr: The attribute
  319. * @buf: The buffer to write to
  320. *
  321. * Return: The number of bytes written
  322. */
  323. static ssize_t platform_profile_show(struct kobject *kobj,
  324. struct kobj_attribute *attr,
  325. char *buf)
  326. {
  327. enum platform_profile_option profile = PLATFORM_PROFILE_LAST;
  328. int err;
  329. scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) {
  330. err = class_for_each_device(&platform_profile_class, NULL,
  331. &profile, _aggregate_profiles);
  332. if (err)
  333. return err;
  334. }
  335. /* no profile handler registered any more */
  336. if (profile == PLATFORM_PROFILE_LAST)
  337. return -EINVAL;
  338. return sysfs_emit(buf, "%s\n", profile_names[profile]);
  339. }
  340. /**
  341. * platform_profile_store - Set the profile for legacy sysfs interface
  342. * @kobj: The kobject
  343. * @attr: The attribute
  344. * @buf: The buffer to read from
  345. * @count: The number of bytes to read
  346. *
  347. * Return: The number of bytes read
  348. */
  349. static ssize_t platform_profile_store(struct kobject *kobj,
  350. struct kobj_attribute *attr,
  351. const char *buf, size_t count)
  352. {
  353. struct aggregate_choices_data data = {
  354. .aggregate = { [0 ... BITS_TO_LONGS(PLATFORM_PROFILE_LAST) - 1] = ~0UL },
  355. .count = 0,
  356. };
  357. int ret;
  358. int i;
  359. /* Scan for a matching profile */
  360. i = sysfs_match_string(profile_names, buf);
  361. if (i < 0 || i == PLATFORM_PROFILE_CUSTOM)
  362. return -EINVAL;
  363. scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) {
  364. ret = class_for_each_device(&platform_profile_class, NULL,
  365. &data, _aggregate_choices);
  366. if (ret)
  367. return ret;
  368. if (!test_bit(i, data.aggregate))
  369. return -EOPNOTSUPP;
  370. ret = class_for_each_device(&platform_profile_class, NULL, &i,
  371. _store_and_notify);
  372. if (ret)
  373. return ret;
  374. }
  375. sysfs_notify(acpi_kobj, NULL, "platform_profile");
  376. return count;
  377. }
  378. static struct kobj_attribute attr_platform_profile_choices = __ATTR_RO(platform_profile_choices);
  379. static struct kobj_attribute attr_platform_profile = __ATTR_RW(platform_profile);
  380. static struct attribute *platform_profile_attrs[] = {
  381. &attr_platform_profile_choices.attr,
  382. &attr_platform_profile.attr,
  383. NULL
  384. };
  385. static int profile_class_registered(struct device *dev, const void *data)
  386. {
  387. return 1;
  388. }
  389. static umode_t profile_class_is_visible(struct kobject *kobj, struct attribute *attr, int idx)
  390. {
  391. struct device *dev;
  392. dev = class_find_device(&platform_profile_class, NULL, NULL, profile_class_registered);
  393. if (!dev)
  394. return 0;
  395. put_device(dev);
  396. return attr->mode;
  397. }
  398. static const struct attribute_group platform_profile_group = {
  399. .attrs = platform_profile_attrs,
  400. .is_visible = profile_class_is_visible,
  401. };
  402. /**
  403. * platform_profile_notify - Notify class device and legacy sysfs interface
  404. * @dev: The class device
  405. */
  406. void platform_profile_notify(struct device *dev)
  407. {
  408. scoped_cond_guard(mutex_intr, return, &profile_lock) {
  409. _notify_class_profile(dev, NULL);
  410. }
  411. sysfs_notify(acpi_kobj, NULL, "platform_profile");
  412. }
  413. EXPORT_SYMBOL_GPL(platform_profile_notify);
  414. /**
  415. * platform_profile_cycle - Cycles profiles available on all registered class devices
  416. *
  417. * Return: 0 on success, -errno on failure
  418. */
  419. int platform_profile_cycle(void)
  420. {
  421. struct aggregate_choices_data data = {
  422. .aggregate = { [0 ... BITS_TO_LONGS(PLATFORM_PROFILE_LAST) - 1] = ~0UL },
  423. .count = 0,
  424. };
  425. enum platform_profile_option next = PLATFORM_PROFILE_LAST;
  426. enum platform_profile_option profile = PLATFORM_PROFILE_LAST;
  427. int err;
  428. scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) {
  429. err = class_for_each_device(&platform_profile_class, NULL,
  430. &profile, _aggregate_profiles);
  431. if (err)
  432. return err;
  433. if (profile == PLATFORM_PROFILE_MAX_POWER ||
  434. profile == PLATFORM_PROFILE_CUSTOM ||
  435. profile == PLATFORM_PROFILE_LAST)
  436. return -EINVAL;
  437. err = class_for_each_device(&platform_profile_class, NULL,
  438. &data, _aggregate_choices);
  439. if (err)
  440. return err;
  441. /* never iterate into a custom or max power if all drivers supported it */
  442. clear_bit(PLATFORM_PROFILE_MAX_POWER, data.aggregate);
  443. clear_bit(PLATFORM_PROFILE_CUSTOM, data.aggregate);
  444. next = find_next_bit_wrap(data.aggregate,
  445. PLATFORM_PROFILE_LAST,
  446. profile + 1);
  447. err = class_for_each_device(&platform_profile_class, NULL, &next,
  448. _store_and_notify);
  449. if (err)
  450. return err;
  451. }
  452. sysfs_notify(acpi_kobj, NULL, "platform_profile");
  453. return 0;
  454. }
  455. EXPORT_SYMBOL_GPL(platform_profile_cycle);
  456. /**
  457. * platform_profile_register - Creates and registers a platform profile class device
  458. * @dev: Parent device
  459. * @name: Name of the class device
  460. * @drvdata: Driver data that will be attached to the class device
  461. * @ops: Platform profile's mandatory operations
  462. *
  463. * Return: pointer to the new class device on success, ERR_PTR on failure
  464. */
  465. struct device *platform_profile_register(struct device *dev, const char *name,
  466. void *drvdata,
  467. const struct platform_profile_ops *ops)
  468. {
  469. struct device *ppdev;
  470. int minor;
  471. int err;
  472. /* Sanity check */
  473. if (WARN_ON_ONCE(!dev || !name || !ops || !ops->profile_get ||
  474. !ops->profile_set || !ops->probe))
  475. return ERR_PTR(-EINVAL);
  476. struct platform_profile_handler *pprof __free(kfree) = kzalloc_obj(*pprof);
  477. if (!pprof)
  478. return ERR_PTR(-ENOMEM);
  479. err = ops->probe(drvdata, pprof->choices);
  480. if (err) {
  481. dev_err(dev, "platform_profile probe failed\n");
  482. return ERR_PTR(err);
  483. }
  484. if (bitmap_empty(pprof->choices, PLATFORM_PROFILE_LAST)) {
  485. dev_err(dev, "Failed to register platform_profile class device with empty choices\n");
  486. return ERR_PTR(-EINVAL);
  487. }
  488. if (ops->hidden_choices) {
  489. err = ops->hidden_choices(drvdata, pprof->hidden_choices);
  490. if (err) {
  491. dev_err(dev, "platform_profile hidden_choices failed\n");
  492. return ERR_PTR(err);
  493. }
  494. }
  495. guard(mutex)(&profile_lock);
  496. /* create class interface for individual handler */
  497. minor = ida_alloc(&platform_profile_ida, GFP_KERNEL);
  498. if (minor < 0)
  499. return ERR_PTR(minor);
  500. pprof->name = name;
  501. pprof->ops = ops;
  502. pprof->minor = minor;
  503. pprof->dev.class = &platform_profile_class;
  504. pprof->dev.parent = dev;
  505. dev_set_drvdata(&pprof->dev, drvdata);
  506. dev_set_name(&pprof->dev, "platform-profile-%d", pprof->minor);
  507. /* device_register() takes ownership of pprof/ppdev */
  508. ppdev = &no_free_ptr(pprof)->dev;
  509. err = device_register(ppdev);
  510. if (err) {
  511. put_device(ppdev);
  512. goto cleanup_ida;
  513. }
  514. sysfs_notify(acpi_kobj, NULL, "platform_profile");
  515. err = sysfs_update_group(acpi_kobj, &platform_profile_group);
  516. if (err)
  517. goto cleanup_cur;
  518. return ppdev;
  519. cleanup_cur:
  520. device_unregister(ppdev);
  521. cleanup_ida:
  522. ida_free(&platform_profile_ida, minor);
  523. return ERR_PTR(err);
  524. }
  525. EXPORT_SYMBOL_GPL(platform_profile_register);
  526. /**
  527. * platform_profile_remove - Unregisters a platform profile class device
  528. * @dev: Class device
  529. */
  530. void platform_profile_remove(struct device *dev)
  531. {
  532. struct platform_profile_handler *pprof;
  533. if (IS_ERR_OR_NULL(dev))
  534. return;
  535. pprof = to_pprof_handler(dev);
  536. guard(mutex)(&profile_lock);
  537. ida_free(&platform_profile_ida, pprof->minor);
  538. device_unregister(&pprof->dev);
  539. sysfs_notify(acpi_kobj, NULL, "platform_profile");
  540. sysfs_update_group(acpi_kobj, &platform_profile_group);
  541. }
  542. EXPORT_SYMBOL_GPL(platform_profile_remove);
  543. static void devm_platform_profile_release(struct device *dev, void *res)
  544. {
  545. struct device **ppdev = res;
  546. platform_profile_remove(*ppdev);
  547. }
  548. /**
  549. * devm_platform_profile_register - Device managed version of platform_profile_register
  550. * @dev: Parent device
  551. * @name: Name of the class device
  552. * @drvdata: Driver data that will be attached to the class device
  553. * @ops: Platform profile's mandatory operations
  554. *
  555. * Return: pointer to the new class device on success, ERR_PTR on failure
  556. */
  557. struct device *devm_platform_profile_register(struct device *dev, const char *name,
  558. void *drvdata,
  559. const struct platform_profile_ops *ops)
  560. {
  561. struct device *ppdev;
  562. struct device **dr;
  563. dr = devres_alloc(devm_platform_profile_release, sizeof(*dr), GFP_KERNEL);
  564. if (!dr)
  565. return ERR_PTR(-ENOMEM);
  566. ppdev = platform_profile_register(dev, name, drvdata, ops);
  567. if (IS_ERR(ppdev)) {
  568. devres_free(dr);
  569. return ppdev;
  570. }
  571. *dr = ppdev;
  572. devres_add(dev, dr);
  573. return ppdev;
  574. }
  575. EXPORT_SYMBOL_GPL(devm_platform_profile_register);
  576. static int __init platform_profile_init(void)
  577. {
  578. int err;
  579. if (acpi_disabled)
  580. return -EOPNOTSUPP;
  581. err = class_register(&platform_profile_class);
  582. if (err)
  583. return err;
  584. err = sysfs_create_group(acpi_kobj, &platform_profile_group);
  585. if (err)
  586. class_unregister(&platform_profile_class);
  587. return err;
  588. }
  589. static void __exit platform_profile_exit(void)
  590. {
  591. sysfs_remove_group(acpi_kobj, &platform_profile_group);
  592. class_unregister(&platform_profile_class);
  593. }
  594. module_init(platform_profile_init);
  595. module_exit(platform_profile_exit);
  596. MODULE_AUTHOR("Mark Pearson <markpearson@lenovo.com>");
  597. MODULE_DESCRIPTION("ACPI platform profile sysfs interface");
  598. MODULE_LICENSE("GPL");