blob: 688b63b082c636d0e14ceaea43c6d9522f87b874 [file] [log] [blame]
Philippe Reynes30d66db2020-07-24 18:19:45 +02001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Copyright (C) 2020 Philippe Reynes <philippe.reynes@softathome.com>
4 */
5
6#ifndef __BUTTON_H
7#define __BUTTON_H
8
9/**
10 * struct button_uc_plat - Platform data the uclass stores about each device
11 *
12 * @label: Button label
13 */
14struct button_uc_plat {
15 const char *label;
16};
17
18/**
19 * enum button_state_t - State used for button
20 * - BUTTON_OFF - Button is not pressed
21 * - BUTTON_ON - Button is pressed
22 * - BUTTON_COUNT - Number of button state
23 */
24enum button_state_t {
25 BUTTON_OFF = 0,
26 BUTTON_ON = 1,
27 BUTTON_COUNT,
28};
29
30struct button_ops {
31 /**
32 * get_state() - get the state of a button
33 *
34 * @dev: button device to change
35 * @return button state button_state_t, or -ve on error
36 */
37 enum button_state_t (*get_state)(struct udevice *dev);
38};
39
40#define button_get_ops(dev) ((struct button_ops *)(dev)->driver->ops)
41
42/**
43 * button_get_by_label() - Find a button device by label
44 *
45 * @label: button label to look up
46 * @devp: Returns the associated device, if found
47 * @return 0 if found, -ENODEV if not found, other -ve on error
48 */
49int button_get_by_label(const char *label, struct udevice **devp);
50
51/**
52 * button_get_state() - get the state of a button
53 *
54 * @dev: button device to change
55 * @return button state button_state_t, or -ve on error
56 */
57enum button_state_t button_get_state(struct udevice *dev);
58
59#endif