Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Copyright 2008 Openmoko, Inc.
0004  * Copyright 2008 Simtec Electronics
0005  *  http://armlinux.simtec.co.uk/
0006  *  Ben Dooks <ben@simtec.co.uk>
0007  *
0008  * S3C Platform - GPIO pin configuration
0009  */
0010 
0011 /* This file contains the necessary definitions to get the basic gpio
0012  * pin configuration done such as setting a pin to input or output or
0013  * changing the pull-{up,down} configurations.
0014  */
0015 
0016 /* Note, this interface is being added to the s3c64xx arch first and will
0017  * be added to the s3c24xx systems later.
0018  */
0019 
0020 #ifndef __PLAT_GPIO_CFG_H
0021 #define __PLAT_GPIO_CFG_H __FILE__
0022 
0023 #include <linux/types.h>
0024 
0025 typedef unsigned int __bitwise samsung_gpio_pull_t;
0026 
0027 /* forward declaration if gpio-core.h hasn't been included */
0028 struct samsung_gpio_chip;
0029 
0030 /**
0031  * struct samsung_gpio_cfg GPIO configuration
0032  * @cfg_eint: Configuration setting when used for external interrupt source
0033  * @get_pull: Read the current pull configuration for the GPIO
0034  * @set_pull: Set the current pull configuration for the GPIO
0035  * @set_config: Set the current configuration for the GPIO
0036  * @get_config: Read the current configuration for the GPIO
0037  *
0038  * Each chip can have more than one type of GPIO bank available and some
0039  * have different capabilites even when they have the same control register
0040  * layouts. Provide an point to vector control routine and provide any
0041  * per-bank configuration information that other systems such as the
0042  * external interrupt code will need.
0043  *
0044  * @sa samsung_gpio_cfgpin
0045  * @sa s3c_gpio_getcfg
0046  * @sa s3c_gpio_setpull
0047  * @sa s3c_gpio_getpull
0048  */
0049 struct samsung_gpio_cfg {
0050     unsigned int    cfg_eint;
0051 
0052     samsung_gpio_pull_t (*get_pull)(struct samsung_gpio_chip *chip, unsigned offs);
0053     int     (*set_pull)(struct samsung_gpio_chip *chip, unsigned offs,
0054                     samsung_gpio_pull_t pull);
0055 
0056     unsigned (*get_config)(struct samsung_gpio_chip *chip, unsigned offs);
0057     int  (*set_config)(struct samsung_gpio_chip *chip, unsigned offs,
0058                    unsigned config);
0059 };
0060 
0061 #define S3C_GPIO_SPECIAL_MARK   (0xfffffff0)
0062 #define S3C_GPIO_SPECIAL(x) (S3C_GPIO_SPECIAL_MARK | (x))
0063 
0064 /* Defines for generic pin configurations */
0065 #define S3C_GPIO_INPUT  (S3C_GPIO_SPECIAL(0))
0066 #define S3C_GPIO_OUTPUT (S3C_GPIO_SPECIAL(1))
0067 #define S3C_GPIO_SFN(x) (S3C_GPIO_SPECIAL(x))
0068 
0069 #define samsung_gpio_is_cfg_special(_cfg) \
0070     (((_cfg) & S3C_GPIO_SPECIAL_MARK) == S3C_GPIO_SPECIAL_MARK)
0071 
0072 /**
0073  * s3c_gpio_cfgpin() - Change the GPIO function of a pin.
0074  * @pin pin The pin number to configure.
0075  * @to to The configuration for the pin's function.
0076  *
0077  * Configure which function is actually connected to the external
0078  * pin, such as an gpio input, output or some form of special function
0079  * connected to an internal peripheral block.
0080  *
0081  * The @to parameter can be one of the generic S3C_GPIO_INPUT, S3C_GPIO_OUTPUT
0082  * or S3C_GPIO_SFN() to indicate one of the possible values that the helper
0083  * will then generate the correct bit mask and shift for the configuration.
0084  *
0085  * If a bank of GPIOs all needs to be set to special-function 2, then
0086  * the following code will work:
0087  *
0088  *  for (gpio = start; gpio < end; gpio++)
0089  *      s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(2));
0090  *
0091  * The @to parameter can also be a specific value already shifted to the
0092  * correct position in the control register, although these are discouraged
0093  * in newer kernels and are only being kept for compatibility.
0094  */
0095 extern int s3c_gpio_cfgpin(unsigned int pin, unsigned int to);
0096 
0097 /**
0098  * s3c_gpio_getcfg - Read the current function for a GPIO pin
0099  * @pin: The pin to read the configuration value for.
0100  *
0101  * Read the configuration state of the given @pin, returning a value that
0102  * could be passed back to s3c_gpio_cfgpin().
0103  *
0104  * @sa s3c_gpio_cfgpin
0105  */
0106 extern unsigned s3c_gpio_getcfg(unsigned int pin);
0107 
0108 /**
0109  * s3c_gpio_cfgpin_range() - Change the GPIO function for configuring pin range
0110  * @start: The pin number to start at
0111  * @nr: The number of pins to configure from @start.
0112  * @cfg: The configuration for the pin's function
0113  *
0114  * Call s3c_gpio_cfgpin() for the @nr pins starting at @start.
0115  *
0116  * @sa s3c_gpio_cfgpin.
0117  */
0118 extern int s3c_gpio_cfgpin_range(unsigned int start, unsigned int nr,
0119                  unsigned int cfg);
0120 
0121 /* Define values for the pull-{up,down} available for each gpio pin.
0122  *
0123  * These values control the state of the weak pull-{up,down} resistors
0124  * available on most pins on the S3C series. Not all chips support both
0125  * up or down settings, and it may be dependent on the chip that is being
0126  * used to whether the particular mode is available.
0127  */
0128 #define S3C_GPIO_PULL_NONE  ((__force samsung_gpio_pull_t)0x00)
0129 #define S3C_GPIO_PULL_DOWN  ((__force samsung_gpio_pull_t)0x01)
0130 #define S3C_GPIO_PULL_UP    ((__force samsung_gpio_pull_t)0x02)
0131 
0132 /**
0133  * s3c_gpio_setpull() - set the state of a gpio pin pull resistor
0134  * @pin: The pin number to configure the pull resistor.
0135  * @pull: The configuration for the pull resistor.
0136  *
0137  * This function sets the state of the pull-{up,down} resistor for the
0138  * specified pin. It will return 0 if successful, or a negative error
0139  * code if the pin cannot support the requested pull setting.
0140  *
0141  * @pull is one of S3C_GPIO_PULL_NONE, S3C_GPIO_PULL_DOWN or S3C_GPIO_PULL_UP.
0142 */
0143 extern int s3c_gpio_setpull(unsigned int pin, samsung_gpio_pull_t pull);
0144 
0145 /**
0146  * s3c_gpio_getpull() - get the pull resistor state of a gpio pin
0147  * @pin: The pin number to get the settings for
0148  *
0149  * Read the pull resistor value for the specified pin.
0150 */
0151 extern samsung_gpio_pull_t s3c_gpio_getpull(unsigned int pin);
0152 
0153 /* configure `all` aspects of an gpio */
0154 
0155 /**
0156  * s3c_gpio_cfgall_range() - configure range of gpio functtion and pull.
0157  * @start: The gpio number to start at.
0158  * @nr: The number of gpio to configure from @start.
0159  * @cfg: The configuration to use
0160  * @pull: The pull setting to use.
0161  *
0162  * Run s3c_gpio_cfgpin() and s3c_gpio_setpull() over the gpio range starting
0163  * @gpio and running for @size.
0164  *
0165  * @sa s3c_gpio_cfgpin
0166  * @sa s3c_gpio_setpull
0167  * @sa s3c_gpio_cfgpin_range
0168  */
0169 extern int s3c_gpio_cfgall_range(unsigned int start, unsigned int nr,
0170                  unsigned int cfg, samsung_gpio_pull_t pull);
0171 
0172 static inline int s3c_gpio_cfgrange_nopull(unsigned int pin, unsigned int size,
0173                        unsigned int cfg)
0174 {
0175     return s3c_gpio_cfgall_range(pin, size, cfg, S3C_GPIO_PULL_NONE);
0176 }
0177 
0178 #endif /* __PLAT_GPIO_CFG_H */