Merge patch series "mpi3mr: Few Enhancements and minor fixes"
[linux-2.6-block.git] / arch / arm / mach-s3c / gpio-core.h
CommitLineData
4490e3c6
KK
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
7db6c82a
BD
3 * Copyright 2008 Simtec Electronics
4 * http://armlinux.simtec.co.uk/
5 * Ben Dooks <ben@simtec.co.uk>
6 *
7 * S3C Platform - GPIO core
4490e3c6 8 */
7db6c82a 9
d5c1b541
MS
10#ifndef __PLAT_SAMSUNG_GPIO_CORE_H
11#define __PLAT_SAMSUNG_GPIO_CORE_H
12
2fd48f94 13/* Bring in machine-local definitions, especially S3C_GPIO_END */
c6ff132d 14#include "gpio-samsung.h"
b552addc 15#include <linux/gpio/driver.h>
2fd48f94 16
1f323cfd
KK
17#define GPIOCON_OFF (0x00)
18#define GPIODAT_OFF (0x04)
19
20#define con_4bit_shift(__off) ((__off) * 4)
21
7db6c82a
BD
22/* Define the core gpiolib support functions that the s3c platforms may
23 * need to extend or change depending on the hardware and the s3c chip
24 * selected at build or found at run time.
25 *
26 * These definitions are not intended for driver inclusion, there is
27 * nothing here that should not live outside the platform and core
28 * specific code.
29*/
30
782d8a3c 31struct samsung_gpio_chip;
d87964c4
BD
32
33/**
782d8a3c 34 * struct samsung_gpio_pm - power management (suspend/resume) information
d87964c4
BD
35 * @save: Routine to save the state of the GPIO block
36 * @resume: Routine to resume the GPIO block.
37 */
782d8a3c
KK
38struct samsung_gpio_pm {
39 void (*save)(struct samsung_gpio_chip *chip);
40 void (*resume)(struct samsung_gpio_chip *chip);
d87964c4
BD
41};
42
782d8a3c 43struct samsung_gpio_cfg;
21b23664 44
7db6c82a 45/**
782d8a3c 46 * struct samsung_gpio_chip - wrapper for specific implementation of gpio
7db6c82a
BD
47 * @chip: The chip structure to be exported via gpiolib.
48 * @base: The base pointer to the gpio configuration registers.
170a4617
MS
49 * @group: The group register number for gpio interrupt support.
50 * @irq_base: The base irq number.
21b23664 51 * @config: special function and pull-resistor control information.
fcef85c0 52 * @lock: Lock for exclusive access to this gpio bank.
d87964c4 53 * @pm_save: Save information for suspend/resume support.
453e2dd7 54 * @bitmap_gpio_int: Bitmap for representing GPIO interrupt or not.
7db6c82a
BD
55 *
56 * This wrapper provides the necessary information for the Samsung
57 * specific gpios being registered with gpiolib.
fcef85c0
BD
58 *
59 * The lock protects each gpio bank from multiple access of the shared
60 * configuration registers, or from reading of data whilst another thread
61 * is writing to the register set.
62 *
63 * Each chip has its own lock to avoid any contention between different
64 * CPU cores trying to get one lock for different GPIO banks, where each
65 * bank of GPIO has its own register space and configuration registers.
7db6c82a 66 */
782d8a3c 67struct samsung_gpio_chip {
7db6c82a 68 struct gpio_chip chip;
782d8a3c
KK
69 struct samsung_gpio_cfg *config;
70 struct samsung_gpio_pm *pm;
7db6c82a 71 void __iomem *base;
170a4617
MS
72 int irq_base;
73 int group;
fcef85c0 74 spinlock_t lock;
d87964c4
BD
75#ifdef CONFIG_PM
76 u32 pm_save[4];
77#endif
453e2dd7 78 u32 bitmap_gpio_int;
7db6c82a
BD
79};
80
782d8a3c 81static inline struct samsung_gpio_chip *to_samsung_gpio(struct gpio_chip *gpc)
7db6c82a 82{
782d8a3c 83 return container_of(gpc, struct samsung_gpio_chip, chip);
7db6c82a
BD
84}
85
8ce14a22
JS
86/**
87 * samsung_gpiolib_to_irq - convert gpio pin to irq number
88 * @chip: The gpio chip that the pin belongs to.
89 * @offset: The offset of the pin in the chip.
90 *
91 * This helper returns the irq number calculated from the chip->irq_base and
92 * the provided offset.
93 */
94extern int samsung_gpiolib_to_irq(struct gpio_chip *chip, unsigned int offset);
95
8a53bdb9 96#ifdef CONFIG_S3C_GPIO_TRACK
782d8a3c 97extern struct samsung_gpio_chip *s3c_gpios[S3C_GPIO_END];
8a53bdb9 98
782d8a3c 99static inline struct samsung_gpio_chip *samsung_gpiolib_getchip(unsigned int chip)
8a53bdb9 100{
21b23664 101 return (chip < S3C_GPIO_END) ? s3c_gpios[chip] : NULL;
8a53bdb9
BD
102}
103#else
782d8a3c 104/* machine specific code should provide samsung_gpiolib_getchip */
21b23664 105
0a2691da
KK
106extern struct samsung_gpio_chip s3c24xx_gpios[];
107
108static inline struct samsung_gpio_chip *samsung_gpiolib_getchip(unsigned int pin)
109{
110 struct samsung_gpio_chip *chip;
111
112 if (pin > S3C_GPIO_END)
113 return NULL;
114
115 chip = &s3c24xx_gpios[pin/32];
116 return ((pin - chip->chip.base) < chip->chip.ngpio) ? chip : NULL;
117}
e856bb1f 118
782d8a3c 119static inline void s3c_gpiolib_track(struct samsung_gpio_chip *chip) { }
8a53bdb9 120#endif
d87964c4
BD
121
122#ifdef CONFIG_PM
782d8a3c
KK
123extern struct samsung_gpio_pm samsung_gpio_pm_1bit;
124extern struct samsung_gpio_pm samsung_gpio_pm_2bit;
125extern struct samsung_gpio_pm samsung_gpio_pm_4bit;
d87964c4
BD
126#define __gpio_pm(x) x
127#else
782d8a3c
KK
128#define samsung_gpio_pm_1bit NULL
129#define samsung_gpio_pm_2bit NULL
130#define samsung_gpio_pm_4bit NULL
d87964c4
BD
131#define __gpio_pm(x) NULL
132
133#endif /* CONFIG_PM */
fcef85c0
BD
134
135/* locking wrappers to deal with multiple access to the same gpio bank */
782d8a3c
KK
136#define samsung_gpio_lock(_oc, _fl) spin_lock_irqsave(&(_oc)->lock, _fl)
137#define samsung_gpio_unlock(_oc, _fl) spin_unlock_irqrestore(&(_oc)->lock, _fl)
d5c1b541
MS
138
139#endif /* __PLAT_SAMSUNG_GPIO_CORE_H */