switch.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Switch class driver
  3. *
  4. * Copyright (C) 2008 Google, Inc.
  5. * Author: Mike Lockwood <[email protected]>
  6. *
  7. * This software is licensed under the terms of the GNU General Public
  8. * License version 2, as published by the Free Software Foundation, and
  9. * may be copied, distributed, and modified under those terms.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. */
  17. #ifndef __LINUX_SWITCH_H__
  18. #define __LINUX_SWITCH_H__
  19. struct switch_dev {
  20. const char *name;
  21. struct device *dev;
  22. int index;
  23. int state;
  24. ssize_t (*print_name)(struct switch_dev *sdev, char *buf);
  25. ssize_t (*print_state)(struct switch_dev *sdev, char *buf);
  26. };
  27. struct gpio_switch_platform_data {
  28. const char *name;
  29. unsigned int gpio;
  30. /* if NULL, switch_dev.name will be printed */
  31. const char *name_on;
  32. const char *name_off;
  33. /* if NULL, "0" or "1" will be printed */
  34. const char *state_on;
  35. const char *state_off;
  36. };
  37. extern int switch_dev_register(struct switch_dev *sdev);
  38. extern void switch_dev_unregister(struct switch_dev *sdev);
  39. static inline int switch_get_state(struct switch_dev *sdev)
  40. {
  41. return sdev->state;
  42. }
  43. extern void switch_set_state(struct switch_dev *sdev, int state);
  44. #endif /* __LINUX_SWITCH_H__ */