aboutsummaryrefslogtreecommitdiff
path: root/hal/hardware/peripheral_io.h
blob: dd55b8fd6a9db3343f157977d2f9a745361b7f6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_PERIPHERAL_IO_INTERFACE_H
#define ANDROID_PERIPHERAL_IO_INTERFACE_H

#include <stdint.h>
#include <sys/cdefs.h>
#include <sys/types.h>

#include <hardware/hardware.h>

__BEGIN_DECLS

/**
 * Id of this module.
 */
#define PERIPHERAL_IO_HARDWARE_MODULE_ID "peripheral_io"

/**
 * Possible GPIO direction configuration.
 */
typedef enum {
  GPIO_DIRECTION_IN,
  GPIO_DIRECTION_OUT_LOW,
  GPIO_DIRECTION_OUT_HIGH
} gpio_direction_t;

typedef int (*pin_mux_cb)(const char* pin, const char* source);
typedef int (*pin_mux_directon_cb)(const char* pin, int dir);

typedef struct pin_mux_callbacks {
  pin_mux_cb mux_cb;
  pin_mux_directon_cb direction_cb;
} pin_mux_callbacks;

typedef struct peripheral_registration_cb_t {
  // TODO(leecam): Fix up the comments.

  // Pin Mux functions.
  int (*register_pin)(const char* name, int gpio, pin_mux_callbacks callbacks);
  int (*register_pin_group)(const char* name, char** pins, size_t nr_pins);
  int (*register_source)(const char* name, char** groups, size_t nr_groups);
  int (*register_simple_source)(const char* name, const char** pins, size_t nr_pins);

  // Gpio functions.
  int (*register_gpio_sysfs)(const char* name, uint32_t index);
  int (*set_gpio_pin_mux)(const char* name, const char* source);

  // Spi functions.
  int (*register_spi_dev_bus)(const char* name, uint32_t bus, uint32_t cs);
  int (*set_spi_pin_mux)(const char* name, const char* source);

  // Led functions
  int (*register_led_sysfs)(const char* name, const char* sysfs_name);

  // I2c functions.
  int (*register_i2c_dev_bus)(const char* name, uint32_t bus);
  int (*set_i2c_pin_mux)(const char* name, const char* source);

} peripheral_registration_cb_t;

typedef struct peripheral_io_module_t peripheral_io_module_t;

struct peripheral_io_module_t {
    struct hw_module_t common;

    /**
     * Register all available devices with the peripheral manager.
     *
     * Arguments:
     *    dev: Pointer to the peripheral_io module.
     *    callbacks: Callbacks into peripheral manager to add specific devices.
     *
     * Returns:
     *    0 on success, errno on error.
     */
    int (*register_devices)(const peripheral_io_module_t* dev,
                            const peripheral_registration_cb_t* callbacks);
};

__END_DECLS

#endif  // ANDROID_PERIPHERAL_IO_INTERFACE_H