blob: ba4b8ade1f74c19e044b6445deaeb796aec2d1dd [file] [log] [blame]
Kuiying Wanga9d39e32018-08-14 13:47:32 +08001/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#pragma once
Patrick Venture0d9377d2018-11-01 19:34:59 -070017
18#include <sdbusplus/bus.hpp>
Naveen Mosesdd5495c2021-12-03 22:40:46 +053019#include <string>
20#include <vector>
Patrick Venture0d9377d2018-11-01 19:34:59 -070021
Naveen Mosesdd5495c2021-12-03 22:40:46 +053022// this struct has the gpio config for single gpio
23struct gpioInfo
Matt Spinler8605bdf2018-11-05 14:55:46 -060024{
Naveen Mosesdd5495c2021-12-03 22:40:46 +053025 int fd; // io fd mapped with the gpio
26 uint32_t number;
27 std::string direction;
28};
29
30// this struct represents button interface
31struct buttonConfig
32{
33 std::string formFactorName; // name of the button interface
34 std::vector<gpioInfo> gpios; // holds single or group gpio config
35 // corresponding to button interface
36};
37
38/**
39 * @brief iterates over the list of gpios and configures gpios them
40 * config which is set from gpio defs json file.
41 * The fd of the configured gpio is stored in buttonConfig.gpios container
42 * @return int returns 0 on successful config of all gpios
43 */
44
45int configGroupGpio(sdbusplus::bus::bus& bus, buttonConfig& buttonCfg);
46
47/**
48 * @brief configures and initializes the single gpio
49 * @return int returns 0 on successful config of all gpios
50 */
51
52int configGpio(sdbusplus::bus::bus& bus, gpioInfo& gpioConfig);
53
54uint32_t getGpioNum(const std::string& gpioPin);
55void closeGpio(int fd);