class.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  1. /*
  2. * class.c - basic device class management
  3. *
  4. * Copyright (c) 2002-3 Patrick Mochel
  5. * Copyright (c) 2002-3 Open Source Development Labs
  6. * Copyright (c) 2003-2004 Greg Kroah-Hartman
  7. * Copyright (c) 2003-2004 IBM Corp.
  8. *
  9. * This file is released under the GPLv2
  10. *
  11. */
  12. #include <linux/config.h>
  13. #include <linux/device.h>
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/string.h>
  17. #include <linux/kdev_t.h>
  18. #include <linux/err.h>
  19. #include "base.h"
  20. #define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr)
  21. #define to_class(obj) container_of(obj, struct class, subsys.kset.kobj)
  22. static ssize_t
  23. class_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
  24. {
  25. struct class_attribute * class_attr = to_class_attr(attr);
  26. struct class * dc = to_class(kobj);
  27. ssize_t ret = -EIO;
  28. if (class_attr->show)
  29. ret = class_attr->show(dc, buf);
  30. return ret;
  31. }
  32. static ssize_t
  33. class_attr_store(struct kobject * kobj, struct attribute * attr,
  34. const char * buf, size_t count)
  35. {
  36. struct class_attribute * class_attr = to_class_attr(attr);
  37. struct class * dc = to_class(kobj);
  38. ssize_t ret = -EIO;
  39. if (class_attr->store)
  40. ret = class_attr->store(dc, buf, count);
  41. return ret;
  42. }
  43. static void class_release(struct kobject * kobj)
  44. {
  45. struct class *class = to_class(kobj);
  46. pr_debug("class '%s': release.\n", class->name);
  47. if (class->class_release)
  48. class->class_release(class);
  49. else
  50. pr_debug("class '%s' does not have a release() function, "
  51. "be careful\n", class->name);
  52. }
  53. static struct sysfs_ops class_sysfs_ops = {
  54. .show = class_attr_show,
  55. .store = class_attr_store,
  56. };
  57. static struct kobj_type ktype_class = {
  58. .sysfs_ops = &class_sysfs_ops,
  59. .release = class_release,
  60. };
  61. /* Hotplug events for classes go to the class_obj subsys */
  62. static decl_subsys(class, &ktype_class, NULL);
  63. int class_create_file(struct class * cls, const struct class_attribute * attr)
  64. {
  65. int error;
  66. if (cls) {
  67. error = sysfs_create_file(&cls->subsys.kset.kobj, &attr->attr);
  68. } else
  69. error = -EINVAL;
  70. return error;
  71. }
  72. void class_remove_file(struct class * cls, const struct class_attribute * attr)
  73. {
  74. if (cls)
  75. sysfs_remove_file(&cls->subsys.kset.kobj, &attr->attr);
  76. }
  77. struct class * class_get(struct class * cls)
  78. {
  79. if (cls)
  80. return container_of(subsys_get(&cls->subsys), struct class, subsys);
  81. return NULL;
  82. }
  83. void class_put(struct class * cls)
  84. {
  85. subsys_put(&cls->subsys);
  86. }
  87. static int add_class_attrs(struct class * cls)
  88. {
  89. int i;
  90. int error = 0;
  91. if (cls->class_attrs) {
  92. for (i = 0; attr_name(cls->class_attrs[i]); i++) {
  93. error = class_create_file(cls,&cls->class_attrs[i]);
  94. if (error)
  95. goto Err;
  96. }
  97. }
  98. Done:
  99. return error;
  100. Err:
  101. while (--i >= 0)
  102. class_remove_file(cls,&cls->class_attrs[i]);
  103. goto Done;
  104. }
  105. static void remove_class_attrs(struct class * cls)
  106. {
  107. int i;
  108. if (cls->class_attrs) {
  109. for (i = 0; attr_name(cls->class_attrs[i]); i++)
  110. class_remove_file(cls,&cls->class_attrs[i]);
  111. }
  112. }
  113. int class_register(struct class * cls)
  114. {
  115. int error;
  116. pr_debug("device class '%s': registering\n", cls->name);
  117. INIT_LIST_HEAD(&cls->children);
  118. INIT_LIST_HEAD(&cls->interfaces);
  119. init_MUTEX(&cls->sem);
  120. error = kobject_set_name(&cls->subsys.kset.kobj, "%s", cls->name);
  121. if (error)
  122. return error;
  123. subsys_set_kset(cls, class_subsys);
  124. error = subsystem_register(&cls->subsys);
  125. if (!error) {
  126. error = add_class_attrs(class_get(cls));
  127. class_put(cls);
  128. }
  129. return error;
  130. }
  131. void class_unregister(struct class * cls)
  132. {
  133. pr_debug("device class '%s': unregistering\n", cls->name);
  134. remove_class_attrs(cls);
  135. subsystem_unregister(&cls->subsys);
  136. }
  137. static void class_create_release(struct class *cls)
  138. {
  139. kfree(cls);
  140. }
  141. static void class_device_create_release(struct class_device *class_dev)
  142. {
  143. kfree(class_dev);
  144. }
  145. /**
  146. * class_create - create a struct class structure
  147. * @owner: pointer to the module that is to "own" this struct class
  148. * @name: pointer to a string for the name of this class.
  149. *
  150. * This is used to create a struct class pointer that can then be used
  151. * in calls to class_device_create().
  152. *
  153. * Note, the pointer created here is to be destroyed when finished by
  154. * making a call to class_destroy().
  155. */
  156. struct class *class_create(struct module *owner, char *name)
  157. {
  158. struct class *cls;
  159. int retval;
  160. cls = kzalloc(sizeof(*cls), GFP_KERNEL);
  161. if (!cls) {
  162. retval = -ENOMEM;
  163. goto error;
  164. }
  165. cls->name = name;
  166. cls->owner = owner;
  167. cls->class_release = class_create_release;
  168. cls->release = class_device_create_release;
  169. retval = class_register(cls);
  170. if (retval)
  171. goto error;
  172. return cls;
  173. error:
  174. kfree(cls);
  175. return ERR_PTR(retval);
  176. }
  177. /**
  178. * class_destroy - destroys a struct class structure
  179. * @cs: pointer to the struct class that is to be destroyed
  180. *
  181. * Note, the pointer to be destroyed must have been created with a call
  182. * to class_create().
  183. */
  184. void class_destroy(struct class *cls)
  185. {
  186. if ((cls == NULL) || (IS_ERR(cls)))
  187. return;
  188. class_unregister(cls);
  189. }
  190. /* Class Device Stuff */
  191. int class_device_create_file(struct class_device * class_dev,
  192. const struct class_device_attribute * attr)
  193. {
  194. int error = -EINVAL;
  195. if (class_dev)
  196. error = sysfs_create_file(&class_dev->kobj, &attr->attr);
  197. return error;
  198. }
  199. void class_device_remove_file(struct class_device * class_dev,
  200. const struct class_device_attribute * attr)
  201. {
  202. if (class_dev)
  203. sysfs_remove_file(&class_dev->kobj, &attr->attr);
  204. }
  205. int class_device_create_bin_file(struct class_device *class_dev,
  206. struct bin_attribute *attr)
  207. {
  208. int error = -EINVAL;
  209. if (class_dev)
  210. error = sysfs_create_bin_file(&class_dev->kobj, attr);
  211. return error;
  212. }
  213. void class_device_remove_bin_file(struct class_device *class_dev,
  214. struct bin_attribute *attr)
  215. {
  216. if (class_dev)
  217. sysfs_remove_bin_file(&class_dev->kobj, attr);
  218. }
  219. static ssize_t
  220. class_device_attr_show(struct kobject * kobj, struct attribute * attr,
  221. char * buf)
  222. {
  223. struct class_device_attribute * class_dev_attr = to_class_dev_attr(attr);
  224. struct class_device * cd = to_class_dev(kobj);
  225. ssize_t ret = 0;
  226. if (class_dev_attr->show)
  227. ret = class_dev_attr->show(cd, buf);
  228. return ret;
  229. }
  230. static ssize_t
  231. class_device_attr_store(struct kobject * kobj, struct attribute * attr,
  232. const char * buf, size_t count)
  233. {
  234. struct class_device_attribute * class_dev_attr = to_class_dev_attr(attr);
  235. struct class_device * cd = to_class_dev(kobj);
  236. ssize_t ret = 0;
  237. if (class_dev_attr->store)
  238. ret = class_dev_attr->store(cd, buf, count);
  239. return ret;
  240. }
  241. static struct sysfs_ops class_dev_sysfs_ops = {
  242. .show = class_device_attr_show,
  243. .store = class_device_attr_store,
  244. };
  245. static void class_dev_release(struct kobject * kobj)
  246. {
  247. struct class_device *cd = to_class_dev(kobj);
  248. struct class * cls = cd->class;
  249. pr_debug("device class '%s': release.\n", cd->class_id);
  250. kfree(cd->devt_attr);
  251. cd->devt_attr = NULL;
  252. if (cls->release)
  253. cls->release(cd);
  254. else {
  255. printk(KERN_ERR "Device class '%s' does not have a release() function, "
  256. "it is broken and must be fixed.\n",
  257. cd->class_id);
  258. WARN_ON(1);
  259. }
  260. }
  261. static struct kobj_type ktype_class_device = {
  262. .sysfs_ops = &class_dev_sysfs_ops,
  263. .release = class_dev_release,
  264. };
  265. static int class_hotplug_filter(struct kset *kset, struct kobject *kobj)
  266. {
  267. struct kobj_type *ktype = get_ktype(kobj);
  268. if (ktype == &ktype_class_device) {
  269. struct class_device *class_dev = to_class_dev(kobj);
  270. if (class_dev->class)
  271. return 1;
  272. }
  273. return 0;
  274. }
  275. static const char *class_hotplug_name(struct kset *kset, struct kobject *kobj)
  276. {
  277. struct class_device *class_dev = to_class_dev(kobj);
  278. return class_dev->class->name;
  279. }
  280. static int class_hotplug(struct kset *kset, struct kobject *kobj, char **envp,
  281. int num_envp, char *buffer, int buffer_size)
  282. {
  283. struct class_device *class_dev = to_class_dev(kobj);
  284. int i = 0;
  285. int length = 0;
  286. int retval = 0;
  287. pr_debug("%s - name = %s\n", __FUNCTION__, class_dev->class_id);
  288. if (class_dev->dev) {
  289. /* add physical device, backing this device */
  290. struct device *dev = class_dev->dev;
  291. char *path = kobject_get_path(&dev->kobj, GFP_KERNEL);
  292. add_hotplug_env_var(envp, num_envp, &i, buffer, buffer_size,
  293. &length, "PHYSDEVPATH=%s", path);
  294. kfree(path);
  295. if (dev->bus)
  296. add_hotplug_env_var(envp, num_envp, &i,
  297. buffer, buffer_size, &length,
  298. "PHYSDEVBUS=%s", dev->bus->name);
  299. if (dev->driver)
  300. add_hotplug_env_var(envp, num_envp, &i,
  301. buffer, buffer_size, &length,
  302. "PHYSDEVDRIVER=%s", dev->driver->name);
  303. }
  304. if (MAJOR(class_dev->devt)) {
  305. add_hotplug_env_var(envp, num_envp, &i,
  306. buffer, buffer_size, &length,
  307. "MAJOR=%u", MAJOR(class_dev->devt));
  308. add_hotplug_env_var(envp, num_envp, &i,
  309. buffer, buffer_size, &length,
  310. "MINOR=%u", MINOR(class_dev->devt));
  311. }
  312. /* terminate, set to next free slot, shrink available space */
  313. envp[i] = NULL;
  314. envp = &envp[i];
  315. num_envp -= i;
  316. buffer = &buffer[length];
  317. buffer_size -= length;
  318. if (class_dev->class->hotplug) {
  319. /* have the bus specific function add its stuff */
  320. retval = class_dev->class->hotplug (class_dev, envp, num_envp,
  321. buffer, buffer_size);
  322. if (retval) {
  323. pr_debug ("%s - hotplug() returned %d\n",
  324. __FUNCTION__, retval);
  325. }
  326. }
  327. return retval;
  328. }
  329. static struct kset_hotplug_ops class_hotplug_ops = {
  330. .filter = class_hotplug_filter,
  331. .name = class_hotplug_name,
  332. .hotplug = class_hotplug,
  333. };
  334. static decl_subsys(class_obj, &ktype_class_device, &class_hotplug_ops);
  335. static int class_device_add_attrs(struct class_device * cd)
  336. {
  337. int i;
  338. int error = 0;
  339. struct class * cls = cd->class;
  340. if (cls->class_dev_attrs) {
  341. for (i = 0; attr_name(cls->class_dev_attrs[i]); i++) {
  342. error = class_device_create_file(cd,
  343. &cls->class_dev_attrs[i]);
  344. if (error)
  345. goto Err;
  346. }
  347. }
  348. Done:
  349. return error;
  350. Err:
  351. while (--i >= 0)
  352. class_device_remove_file(cd,&cls->class_dev_attrs[i]);
  353. goto Done;
  354. }
  355. static void class_device_remove_attrs(struct class_device * cd)
  356. {
  357. int i;
  358. struct class * cls = cd->class;
  359. if (cls->class_dev_attrs) {
  360. for (i = 0; attr_name(cls->class_dev_attrs[i]); i++)
  361. class_device_remove_file(cd,&cls->class_dev_attrs[i]);
  362. }
  363. }
  364. static ssize_t show_dev(struct class_device *class_dev, char *buf)
  365. {
  366. return print_dev_t(buf, class_dev->devt);
  367. }
  368. void class_device_initialize(struct class_device *class_dev)
  369. {
  370. kobj_set_kset_s(class_dev, class_obj_subsys);
  371. kobject_init(&class_dev->kobj);
  372. INIT_LIST_HEAD(&class_dev->node);
  373. }
  374. static char *make_class_name(struct class_device *class_dev)
  375. {
  376. char *name;
  377. int size;
  378. size = strlen(class_dev->class->name) +
  379. strlen(kobject_name(&class_dev->kobj)) + 2;
  380. name = kmalloc(size, GFP_KERNEL);
  381. if (!name)
  382. return ERR_PTR(-ENOMEM);
  383. strcpy(name, class_dev->class->name);
  384. strcat(name, ":");
  385. strcat(name, kobject_name(&class_dev->kobj));
  386. return name;
  387. }
  388. int class_device_add(struct class_device *class_dev)
  389. {
  390. struct class * parent = NULL;
  391. struct class_interface * class_intf;
  392. char *class_name = NULL;
  393. int error;
  394. class_dev = class_device_get(class_dev);
  395. if (!class_dev)
  396. return -EINVAL;
  397. if (!strlen(class_dev->class_id)) {
  398. error = -EINVAL;
  399. goto register_done;
  400. }
  401. parent = class_get(class_dev->class);
  402. pr_debug("CLASS: registering class device: ID = '%s'\n",
  403. class_dev->class_id);
  404. /* first, register with generic layer. */
  405. kobject_set_name(&class_dev->kobj, "%s", class_dev->class_id);
  406. if (parent)
  407. class_dev->kobj.parent = &parent->subsys.kset.kobj;
  408. if ((error = kobject_add(&class_dev->kobj)))
  409. goto register_done;
  410. /* add the needed attributes to this device */
  411. if (MAJOR(class_dev->devt)) {
  412. struct class_device_attribute *attr;
  413. attr = kzalloc(sizeof(*attr), GFP_KERNEL);
  414. if (!attr) {
  415. error = -ENOMEM;
  416. kobject_del(&class_dev->kobj);
  417. goto register_done;
  418. }
  419. attr->attr.name = "dev";
  420. attr->attr.mode = S_IRUGO;
  421. attr->attr.owner = parent->owner;
  422. attr->show = show_dev;
  423. attr->store = NULL;
  424. class_device_create_file(class_dev, attr);
  425. class_dev->devt_attr = attr;
  426. }
  427. class_device_add_attrs(class_dev);
  428. if (class_dev->dev) {
  429. class_name = make_class_name(class_dev);
  430. sysfs_create_link(&class_dev->kobj,
  431. &class_dev->dev->kobj, "device");
  432. sysfs_create_link(&class_dev->dev->kobj, &class_dev->kobj,
  433. class_name);
  434. }
  435. /* notify any interfaces this device is now here */
  436. if (parent) {
  437. down(&parent->sem);
  438. list_add_tail(&class_dev->node, &parent->children);
  439. list_for_each_entry(class_intf, &parent->interfaces, node)
  440. if (class_intf->add)
  441. class_intf->add(class_dev);
  442. up(&parent->sem);
  443. }
  444. kobject_hotplug(&class_dev->kobj, KOBJ_ADD);
  445. register_done:
  446. if (error && parent)
  447. class_put(parent);
  448. class_device_put(class_dev);
  449. kfree(class_name);
  450. return error;
  451. }
  452. int class_device_register(struct class_device *class_dev)
  453. {
  454. class_device_initialize(class_dev);
  455. return class_device_add(class_dev);
  456. }
  457. /**
  458. * class_device_create - creates a class device and registers it with sysfs
  459. * @cs: pointer to the struct class that this device should be registered to.
  460. * @dev: the dev_t for the char device to be added.
  461. * @device: a pointer to a struct device that is assiociated with this class device.
  462. * @fmt: string for the class device's name
  463. *
  464. * This function can be used by char device classes. A struct
  465. * class_device will be created in sysfs, registered to the specified
  466. * class. A "dev" file will be created, showing the dev_t for the
  467. * device. The pointer to the struct class_device will be returned from
  468. * the call. Any further sysfs files that might be required can be
  469. * created using this pointer.
  470. *
  471. * Note: the struct class passed to this function must have previously
  472. * been created with a call to class_create().
  473. */
  474. struct class_device *class_device_create(struct class *cls, dev_t devt,
  475. struct device *device, char *fmt, ...)
  476. {
  477. va_list args;
  478. struct class_device *class_dev = NULL;
  479. int retval = -ENODEV;
  480. if (cls == NULL || IS_ERR(cls))
  481. goto error;
  482. class_dev = kzalloc(sizeof(*class_dev), GFP_KERNEL);
  483. if (!class_dev) {
  484. retval = -ENOMEM;
  485. goto error;
  486. }
  487. class_dev->devt = devt;
  488. class_dev->dev = device;
  489. class_dev->class = cls;
  490. va_start(args, fmt);
  491. vsnprintf(class_dev->class_id, BUS_ID_SIZE, fmt, args);
  492. va_end(args);
  493. retval = class_device_register(class_dev);
  494. if (retval)
  495. goto error;
  496. return class_dev;
  497. error:
  498. kfree(class_dev);
  499. return ERR_PTR(retval);
  500. }
  501. void class_device_del(struct class_device *class_dev)
  502. {
  503. struct class * parent = class_dev->class;
  504. struct class_interface * class_intf;
  505. char *class_name = NULL;
  506. if (parent) {
  507. down(&parent->sem);
  508. list_del_init(&class_dev->node);
  509. list_for_each_entry(class_intf, &parent->interfaces, node)
  510. if (class_intf->remove)
  511. class_intf->remove(class_dev);
  512. up(&parent->sem);
  513. }
  514. if (class_dev->dev) {
  515. class_name = make_class_name(class_dev);
  516. sysfs_remove_link(&class_dev->kobj, "device");
  517. sysfs_remove_link(&class_dev->dev->kobj, class_name);
  518. }
  519. if (class_dev->devt_attr)
  520. class_device_remove_file(class_dev, class_dev->devt_attr);
  521. class_device_remove_attrs(class_dev);
  522. kobject_hotplug(&class_dev->kobj, KOBJ_REMOVE);
  523. kobject_del(&class_dev->kobj);
  524. if (parent)
  525. class_put(parent);
  526. kfree(class_name);
  527. }
  528. void class_device_unregister(struct class_device *class_dev)
  529. {
  530. pr_debug("CLASS: Unregistering class device. ID = '%s'\n",
  531. class_dev->class_id);
  532. class_device_del(class_dev);
  533. class_device_put(class_dev);
  534. }
  535. /**
  536. * class_device_destroy - removes a class device that was created with class_device_create()
  537. * @cls: the pointer to the struct class that this device was registered * with.
  538. * @dev: the dev_t of the device that was previously registered.
  539. *
  540. * This call unregisters and cleans up a class device that was created with a
  541. * call to class_device_create()
  542. */
  543. void class_device_destroy(struct class *cls, dev_t devt)
  544. {
  545. struct class_device *class_dev = NULL;
  546. struct class_device *class_dev_tmp;
  547. down(&cls->sem);
  548. list_for_each_entry(class_dev_tmp, &cls->children, node) {
  549. if (class_dev_tmp->devt == devt) {
  550. class_dev = class_dev_tmp;
  551. break;
  552. }
  553. }
  554. up(&cls->sem);
  555. if (class_dev)
  556. class_device_unregister(class_dev);
  557. }
  558. int class_device_rename(struct class_device *class_dev, char *new_name)
  559. {
  560. int error = 0;
  561. class_dev = class_device_get(class_dev);
  562. if (!class_dev)
  563. return -EINVAL;
  564. pr_debug("CLASS: renaming '%s' to '%s'\n", class_dev->class_id,
  565. new_name);
  566. strlcpy(class_dev->class_id, new_name, KOBJ_NAME_LEN);
  567. error = kobject_rename(&class_dev->kobj, new_name);
  568. class_device_put(class_dev);
  569. return error;
  570. }
  571. struct class_device * class_device_get(struct class_device *class_dev)
  572. {
  573. if (class_dev)
  574. return to_class_dev(kobject_get(&class_dev->kobj));
  575. return NULL;
  576. }
  577. void class_device_put(struct class_device *class_dev)
  578. {
  579. kobject_put(&class_dev->kobj);
  580. }
  581. int class_interface_register(struct class_interface *class_intf)
  582. {
  583. struct class *parent;
  584. struct class_device *class_dev;
  585. if (!class_intf || !class_intf->class)
  586. return -ENODEV;
  587. parent = class_get(class_intf->class);
  588. if (!parent)
  589. return -EINVAL;
  590. down(&parent->sem);
  591. list_add_tail(&class_intf->node, &parent->interfaces);
  592. if (class_intf->add) {
  593. list_for_each_entry(class_dev, &parent->children, node)
  594. class_intf->add(class_dev);
  595. }
  596. up(&parent->sem);
  597. return 0;
  598. }
  599. void class_interface_unregister(struct class_interface *class_intf)
  600. {
  601. struct class * parent = class_intf->class;
  602. struct class_device *class_dev;
  603. if (!parent)
  604. return;
  605. down(&parent->sem);
  606. list_del_init(&class_intf->node);
  607. if (class_intf->remove) {
  608. list_for_each_entry(class_dev, &parent->children, node)
  609. class_intf->remove(class_dev);
  610. }
  611. up(&parent->sem);
  612. class_put(parent);
  613. }
  614. int __init classes_init(void)
  615. {
  616. int retval;
  617. retval = subsystem_register(&class_subsys);
  618. if (retval)
  619. return retval;
  620. /* ick, this is ugly, the things we go through to keep from showing up
  621. * in sysfs... */
  622. subsystem_init(&class_obj_subsys);
  623. if (!class_obj_subsys.kset.subsys)
  624. class_obj_subsys.kset.subsys = &class_obj_subsys;
  625. return 0;
  626. }
  627. EXPORT_SYMBOL_GPL(class_create_file);
  628. EXPORT_SYMBOL_GPL(class_remove_file);
  629. EXPORT_SYMBOL_GPL(class_register);
  630. EXPORT_SYMBOL_GPL(class_unregister);
  631. EXPORT_SYMBOL_GPL(class_get);
  632. EXPORT_SYMBOL_GPL(class_put);
  633. EXPORT_SYMBOL_GPL(class_create);
  634. EXPORT_SYMBOL_GPL(class_destroy);
  635. EXPORT_SYMBOL_GPL(class_device_register);
  636. EXPORT_SYMBOL_GPL(class_device_unregister);
  637. EXPORT_SYMBOL_GPL(class_device_initialize);
  638. EXPORT_SYMBOL_GPL(class_device_add);
  639. EXPORT_SYMBOL_GPL(class_device_del);
  640. EXPORT_SYMBOL_GPL(class_device_get);
  641. EXPORT_SYMBOL_GPL(class_device_put);
  642. EXPORT_SYMBOL_GPL(class_device_create);
  643. EXPORT_SYMBOL_GPL(class_device_destroy);
  644. EXPORT_SYMBOL_GPL(class_device_create_file);
  645. EXPORT_SYMBOL_GPL(class_device_remove_file);
  646. EXPORT_SYMBOL_GPL(class_device_create_bin_file);
  647. EXPORT_SYMBOL_GPL(class_device_remove_bin_file);
  648. EXPORT_SYMBOL_GPL(class_interface_register);
  649. EXPORT_SYMBOL_GPL(class_interface_unregister);