162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright 2008 Openmoko, Inc. 462306a36Sopenharmony_ci * Copyright 2008 Simtec Electronics 562306a36Sopenharmony_ci * http://armlinux.simtec.co.uk/ 662306a36Sopenharmony_ci * Ben Dooks <ben@simtec.co.uk> 762306a36Sopenharmony_ci * 862306a36Sopenharmony_ci * S3C Platform - GPIO pin configuration 962306a36Sopenharmony_ci */ 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci/* This file contains the necessary definitions to get the basic gpio 1262306a36Sopenharmony_ci * pin configuration done such as setting a pin to input or output or 1362306a36Sopenharmony_ci * changing the pull-{up,down} configurations. 1462306a36Sopenharmony_ci */ 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci/* Note, this interface is being added to the s3c64xx arch first and will 1762306a36Sopenharmony_ci * be added to the s3c24xx systems later. 1862306a36Sopenharmony_ci */ 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci#ifndef __PLAT_GPIO_CFG_H 2162306a36Sopenharmony_ci#define __PLAT_GPIO_CFG_H __FILE__ 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci#include <linux/types.h> 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_citypedef unsigned int __bitwise samsung_gpio_pull_t; 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci/* forward declaration if gpio-core.h hasn't been included */ 2862306a36Sopenharmony_cistruct samsung_gpio_chip; 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ci/** 3162306a36Sopenharmony_ci * struct samsung_gpio_cfg GPIO configuration 3262306a36Sopenharmony_ci * @cfg_eint: Configuration setting when used for external interrupt source 3362306a36Sopenharmony_ci * @get_pull: Read the current pull configuration for the GPIO 3462306a36Sopenharmony_ci * @set_pull: Set the current pull configuration for the GPIO 3562306a36Sopenharmony_ci * @set_config: Set the current configuration for the GPIO 3662306a36Sopenharmony_ci * @get_config: Read the current configuration for the GPIO 3762306a36Sopenharmony_ci * 3862306a36Sopenharmony_ci * Each chip can have more than one type of GPIO bank available and some 3962306a36Sopenharmony_ci * have different capabilites even when they have the same control register 4062306a36Sopenharmony_ci * layouts. Provide an point to vector control routine and provide any 4162306a36Sopenharmony_ci * per-bank configuration information that other systems such as the 4262306a36Sopenharmony_ci * external interrupt code will need. 4362306a36Sopenharmony_ci * 4462306a36Sopenharmony_ci * @sa samsung_gpio_cfgpin 4562306a36Sopenharmony_ci * @sa s3c_gpio_getcfg 4662306a36Sopenharmony_ci * @sa s3c_gpio_setpull 4762306a36Sopenharmony_ci * @sa s3c_gpio_getpull 4862306a36Sopenharmony_ci */ 4962306a36Sopenharmony_cistruct samsung_gpio_cfg { 5062306a36Sopenharmony_ci unsigned int cfg_eint; 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci samsung_gpio_pull_t (*get_pull)(struct samsung_gpio_chip *chip, unsigned offs); 5362306a36Sopenharmony_ci int (*set_pull)(struct samsung_gpio_chip *chip, unsigned offs, 5462306a36Sopenharmony_ci samsung_gpio_pull_t pull); 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci unsigned (*get_config)(struct samsung_gpio_chip *chip, unsigned offs); 5762306a36Sopenharmony_ci int (*set_config)(struct samsung_gpio_chip *chip, unsigned offs, 5862306a36Sopenharmony_ci unsigned config); 5962306a36Sopenharmony_ci}; 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ci#define S3C_GPIO_SPECIAL_MARK (0xfffffff0) 6262306a36Sopenharmony_ci#define S3C_GPIO_SPECIAL(x) (S3C_GPIO_SPECIAL_MARK | (x)) 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ci/* Defines for generic pin configurations */ 6562306a36Sopenharmony_ci#define S3C_GPIO_INPUT (S3C_GPIO_SPECIAL(0)) 6662306a36Sopenharmony_ci#define S3C_GPIO_OUTPUT (S3C_GPIO_SPECIAL(1)) 6762306a36Sopenharmony_ci#define S3C_GPIO_SFN(x) (S3C_GPIO_SPECIAL(x)) 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci#define samsung_gpio_is_cfg_special(_cfg) \ 7062306a36Sopenharmony_ci (((_cfg) & S3C_GPIO_SPECIAL_MARK) == S3C_GPIO_SPECIAL_MARK) 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci/** 7362306a36Sopenharmony_ci * s3c_gpio_cfgpin() - Change the GPIO function of a pin. 7462306a36Sopenharmony_ci * @pin pin The pin number to configure. 7562306a36Sopenharmony_ci * @to to The configuration for the pin's function. 7662306a36Sopenharmony_ci * 7762306a36Sopenharmony_ci * Configure which function is actually connected to the external 7862306a36Sopenharmony_ci * pin, such as an gpio input, output or some form of special function 7962306a36Sopenharmony_ci * connected to an internal peripheral block. 8062306a36Sopenharmony_ci * 8162306a36Sopenharmony_ci * The @to parameter can be one of the generic S3C_GPIO_INPUT, S3C_GPIO_OUTPUT 8262306a36Sopenharmony_ci * or S3C_GPIO_SFN() to indicate one of the possible values that the helper 8362306a36Sopenharmony_ci * will then generate the correct bit mask and shift for the configuration. 8462306a36Sopenharmony_ci * 8562306a36Sopenharmony_ci * If a bank of GPIOs all needs to be set to special-function 2, then 8662306a36Sopenharmony_ci * the following code will work: 8762306a36Sopenharmony_ci * 8862306a36Sopenharmony_ci * for (gpio = start; gpio < end; gpio++) 8962306a36Sopenharmony_ci * s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(2)); 9062306a36Sopenharmony_ci * 9162306a36Sopenharmony_ci * The @to parameter can also be a specific value already shifted to the 9262306a36Sopenharmony_ci * correct position in the control register, although these are discouraged 9362306a36Sopenharmony_ci * in newer kernels and are only being kept for compatibility. 9462306a36Sopenharmony_ci */ 9562306a36Sopenharmony_ciextern int s3c_gpio_cfgpin(unsigned int pin, unsigned int to); 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ci/** 9862306a36Sopenharmony_ci * s3c_gpio_cfgpin_range() - Change the GPIO function for configuring pin range 9962306a36Sopenharmony_ci * @start: The pin number to start at 10062306a36Sopenharmony_ci * @nr: The number of pins to configure from @start. 10162306a36Sopenharmony_ci * @cfg: The configuration for the pin's function 10262306a36Sopenharmony_ci * 10362306a36Sopenharmony_ci * Call s3c_gpio_cfgpin() for the @nr pins starting at @start. 10462306a36Sopenharmony_ci * 10562306a36Sopenharmony_ci * @sa s3c_gpio_cfgpin. 10662306a36Sopenharmony_ci */ 10762306a36Sopenharmony_ciextern int s3c_gpio_cfgpin_range(unsigned int start, unsigned int nr, 10862306a36Sopenharmony_ci unsigned int cfg); 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ci/* Define values for the pull-{up,down} available for each gpio pin. 11162306a36Sopenharmony_ci * 11262306a36Sopenharmony_ci * These values control the state of the weak pull-{up,down} resistors 11362306a36Sopenharmony_ci * available on most pins on the S3C series. Not all chips support both 11462306a36Sopenharmony_ci * up or down settings, and it may be dependent on the chip that is being 11562306a36Sopenharmony_ci * used to whether the particular mode is available. 11662306a36Sopenharmony_ci */ 11762306a36Sopenharmony_ci#define S3C_GPIO_PULL_NONE ((__force samsung_gpio_pull_t)0x00) 11862306a36Sopenharmony_ci#define S3C_GPIO_PULL_DOWN ((__force samsung_gpio_pull_t)0x01) 11962306a36Sopenharmony_ci#define S3C_GPIO_PULL_UP ((__force samsung_gpio_pull_t)0x02) 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ci/** 12262306a36Sopenharmony_ci * s3c_gpio_setpull() - set the state of a gpio pin pull resistor 12362306a36Sopenharmony_ci * @pin: The pin number to configure the pull resistor. 12462306a36Sopenharmony_ci * @pull: The configuration for the pull resistor. 12562306a36Sopenharmony_ci * 12662306a36Sopenharmony_ci * This function sets the state of the pull-{up,down} resistor for the 12762306a36Sopenharmony_ci * specified pin. It will return 0 if successful, or a negative error 12862306a36Sopenharmony_ci * code if the pin cannot support the requested pull setting. 12962306a36Sopenharmony_ci * 13062306a36Sopenharmony_ci * @pull is one of S3C_GPIO_PULL_NONE, S3C_GPIO_PULL_DOWN or S3C_GPIO_PULL_UP. 13162306a36Sopenharmony_ci*/ 13262306a36Sopenharmony_ciextern int s3c_gpio_setpull(unsigned int pin, samsung_gpio_pull_t pull); 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci/* configure `all` aspects of an gpio */ 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ci/** 13762306a36Sopenharmony_ci * s3c_gpio_cfgall_range() - configure range of gpio functtion and pull. 13862306a36Sopenharmony_ci * @start: The gpio number to start at. 13962306a36Sopenharmony_ci * @nr: The number of gpio to configure from @start. 14062306a36Sopenharmony_ci * @cfg: The configuration to use 14162306a36Sopenharmony_ci * @pull: The pull setting to use. 14262306a36Sopenharmony_ci * 14362306a36Sopenharmony_ci * Run s3c_gpio_cfgpin() and s3c_gpio_setpull() over the gpio range starting 14462306a36Sopenharmony_ci * @gpio and running for @size. 14562306a36Sopenharmony_ci * 14662306a36Sopenharmony_ci * @sa s3c_gpio_cfgpin 14762306a36Sopenharmony_ci * @sa s3c_gpio_setpull 14862306a36Sopenharmony_ci * @sa s3c_gpio_cfgpin_range 14962306a36Sopenharmony_ci */ 15062306a36Sopenharmony_ciextern int s3c_gpio_cfgall_range(unsigned int start, unsigned int nr, 15162306a36Sopenharmony_ci unsigned int cfg, samsung_gpio_pull_t pull); 15262306a36Sopenharmony_ci 15362306a36Sopenharmony_cistatic inline int s3c_gpio_cfgrange_nopull(unsigned int pin, unsigned int size, 15462306a36Sopenharmony_ci unsigned int cfg) 15562306a36Sopenharmony_ci{ 15662306a36Sopenharmony_ci return s3c_gpio_cfgall_range(pin, size, cfg, S3C_GPIO_PULL_NONE); 15762306a36Sopenharmony_ci} 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_ci#endif /* __PLAT_GPIO_CFG_H */ 160