mirror of
https://github.com/hardkernel/kernel_common_drivers.git
synced 2026-06-25 12:03:48 +09:00
gpio: porting gpiolib function [1/1]
PD#SWPL-65870 Problem: add function gpiod_set_pull Solution: add function gpiod_set_pull Verify: s4d Signed-off-by: wanwei.jiang <wanwei.jiang@amlogic.com> Change-Id: Id027b5b1abfb675445ff01fc8faaa207147a8954
This commit is contained in:
@@ -47,3 +47,6 @@ CONFIG_AMLOGIC_CPU_INFO=m
|
||||
# amlogic-pm.ko
|
||||
CONFIG_AMLOGIC_GX_SUSPEND=m
|
||||
CONFIG_AMLOGIC_LEGACY_EARLY_SUSPEND=y
|
||||
|
||||
# amlogic-gpiolib.ko
|
||||
CONFIG_AMLOGIC_GPIOLIB=m
|
||||
|
||||
@@ -10,4 +10,6 @@ source "../common_drivers/drivers/secmon/Kconfig"
|
||||
source "../common_drivers/drivers/power/Kconfig"
|
||||
source "../common_drivers/drivers/cpu_info/Kconfig"
|
||||
source "../common_drivers/drivers/pm/Kconfig"
|
||||
source "../common_drivers/drivers/gpio/Kconfig"
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -8,6 +8,7 @@ obj-y += secmon/
|
||||
obj-y += power/
|
||||
obj-y += cpu_info/
|
||||
obj-y += pm/
|
||||
obj-y += gpio/
|
||||
|
||||
KBUILD_CFLAGS_MODULE += $(GKI_EXT_MODULE_PREDEFINE)
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
# SPDX-License-Identifier: (GPL-2.0+ OR MIT)
|
||||
|
||||
config AMLOGIC_GPIOLIB
|
||||
tristate "Amlogic gpiolib expand"
|
||||
depends on GPIOLIB
|
||||
default n
|
||||
help
|
||||
Say Y here if you want to use the
|
||||
amlogic gpiolib expand.
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
# SPDX-License-Identifier: (GPL-2.0+ OR MIT)
|
||||
|
||||
ccflags-y += -I$(srctree)/drivers/gpio
|
||||
|
||||
MODULE_NAME = amlogic-gpiolib
|
||||
obj-$(CONFIG_AMLOGIC_GPIOLIB) = $(MODULE_NAME).o
|
||||
$(MODULE_NAME)-y += gpiolib.o
|
||||
@@ -0,0 +1,98 @@
|
||||
// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/gpio.h>
|
||||
#include <linux/gpio/driver.h>
|
||||
#include <linux/gpio/machine.h>
|
||||
#include <linux/pinctrl/consumer.h>
|
||||
#include <linux/amlogic/gpiolib.h>
|
||||
#include <gpiolib.h>
|
||||
|
||||
/*
|
||||
* This descriptor validation needs to be inserted verbatim into each
|
||||
* function taking a descriptor, so we need to use a preprocessor
|
||||
* macro to avoid endless duplication. If the desc is NULL it is an
|
||||
* optional GPIO and calls should just bail out.
|
||||
*/
|
||||
static int validate_desc(const struct gpio_desc *desc, const char *func)
|
||||
{
|
||||
if (!desc)
|
||||
return 0;
|
||||
if (IS_ERR(desc)) {
|
||||
pr_warn("%s: invalid GPIO (errorpointer)\n", func);
|
||||
return PTR_ERR(desc);
|
||||
}
|
||||
if (!desc->gdev) {
|
||||
pr_warn("%s: invalid GPIO (no device)\n", func);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (!desc->gdev->chip) {
|
||||
dev_warn(&desc->gdev->dev,
|
||||
"%s: backing chip is gone\n", func);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define VALIDATE_DESC(desc) do { \
|
||||
int __valid = validate_desc(desc, __func__); \
|
||||
if (__valid <= 0) \
|
||||
return __valid; \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* gpiod_set_pull - enable pull-down/up for the gpio, or disable.
|
||||
* @desc: descriptor of the GPIO for which to set pull
|
||||
* @value: value to set
|
||||
*
|
||||
* Returns:
|
||||
* 0 on success, %-ENOTSUPP if the controller doesn't support setting the
|
||||
* pull.
|
||||
*/
|
||||
int gpiod_set_pull(struct gpio_desc *desc, unsigned int value)
|
||||
{
|
||||
struct gpio_chip *chip;
|
||||
unsigned long config;
|
||||
enum pin_config_param mode;
|
||||
|
||||
VALIDATE_DESC(desc);
|
||||
chip = desc->gdev->chip;
|
||||
if (!chip || !chip->set_config) {
|
||||
gpiod_dbg(desc,
|
||||
"%s: missing set() or set_config() operations\n",
|
||||
__func__);
|
||||
return -ENOTSUPP;
|
||||
}
|
||||
|
||||
switch (value) {
|
||||
case GPIOD_PULL_DIS:
|
||||
mode = PIN_CONFIG_BIAS_DISABLE;
|
||||
break;
|
||||
case GPIOD_PULL_DOWN:
|
||||
mode = PIN_CONFIG_BIAS_PULL_DOWN;
|
||||
break;
|
||||
case GPIOD_PULL_UP:
|
||||
mode = PIN_CONFIG_BIAS_PULL_UP;
|
||||
break;
|
||||
default:
|
||||
return -ENOTSUPP;
|
||||
}
|
||||
config = PIN_CONF_PACKED(mode, 0);
|
||||
|
||||
return chip->set_config(chip, gpio_chip_hwgpio(desc), config);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(gpiod_set_pull);
|
||||
|
||||
static int __init pinctrl_module_init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __exit pinctrl_module_exit(void)
|
||||
{
|
||||
}
|
||||
|
||||
module_init(pinctrl_module_init);
|
||||
module_exit(pinctrl_module_exit);
|
||||
|
||||
MODULE_LICENSE("GPL v2");
|
||||
@@ -0,0 +1,31 @@
|
||||
// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
|
||||
|
||||
/*
|
||||
* Copyright (c) 2019 Amlogic, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef __AML_GPIO_H__
|
||||
#define __AML_GPIO_H__
|
||||
|
||||
#include <linux/bug.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/kernel.h>
|
||||
|
||||
enum gpiod_pull_type {
|
||||
GPIOD_PULL_DIS = 0,
|
||||
GPIOD_PULL_DOWN = 1,
|
||||
GPIOD_PULL_UP = 2,
|
||||
};
|
||||
|
||||
#ifdef CONFIG_GPIOLIB
|
||||
int gpiod_set_pull(struct gpio_desc *desc, unsigned int value);
|
||||
#else /* CONFIG_GPIOLIB */
|
||||
static inline int gpiod_set_pull(struct gpio_desc *desc, unsigned int value)
|
||||
{
|
||||
/* GPIO can never have been requested */
|
||||
WARN_ON(1);
|
||||
return -EINVAL;
|
||||
}
|
||||
#endif /* CONFIG_GPIOLIB */
|
||||
|
||||
#endif //__AML_GPIO_H__
|
||||
Reference in New Issue
Block a user