gpio-core.h 4.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/* linux/arch/arm/plat-s3c/include/plat/gpio-core.h
 *
 * Copyright 2008 Simtec Electronics
 *	http://armlinux.simtec.co.uk/
 *	Ben Dooks <ben@simtec.co.uk>
 *
 * S3C Platform - GPIO core
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
*/

14 15 16
#ifndef __PLAT_SAMSUNG_GPIO_CORE_H
#define __PLAT_SAMSUNG_GPIO_CORE_H

17 18 19 20 21
#define GPIOCON_OFF	(0x00)
#define GPIODAT_OFF	(0x04)

#define con_4bit_shift(__off) ((__off) * 4)

22 23 24 25 26 27 28 29 30
/* Define the core gpiolib support functions that the s3c platforms may
 * need to extend or change depending on the hardware and the s3c chip
 * selected at build or found at run time.
 *
 * These definitions are not intended for driver inclusion, there is
 * nothing here that should not live outside the platform and core
 * specific code.
*/

31
struct samsung_gpio_chip;
32 33

/**
34
 * struct samsung_gpio_pm - power management (suspend/resume) information
35 36 37
 * @save: Routine to save the state of the GPIO block
 * @resume: Routine to resume the GPIO block.
 */
38 39 40
struct samsung_gpio_pm {
	void (*save)(struct samsung_gpio_chip *chip);
	void (*resume)(struct samsung_gpio_chip *chip);
41 42
};

43
struct samsung_gpio_cfg;
44

45
/**
46
 * struct samsung_gpio_chip - wrapper for specific implementation of gpio
47 48
 * @chip: The chip structure to be exported via gpiolib.
 * @base: The base pointer to the gpio configuration registers.
49 50
 * @group: The group register number for gpio interrupt support.
 * @irq_base: The base irq number.
51
 * @config: special function and pull-resistor control information.
52
 * @lock: Lock for exclusive access to this gpio bank.
53
 * @pm_save: Save information for suspend/resume support.
54
 * @bitmap_gpio_int: Bitmap for representing GPIO interrupt or not.
55 56 57
 *
 * This wrapper provides the necessary information for the Samsung
 * specific gpios being registered with gpiolib.
58 59 60 61 62 63 64 65
 *
 * The lock protects each gpio bank from multiple access of the shared
 * configuration registers, or from reading of data whilst another thread
 * is writing to the register set.
 *
 * Each chip has its own lock to avoid any  contention between different
 * CPU cores trying to get one lock for different GPIO banks, where each
 * bank of GPIO has its own register space and configuration registers.
66
 */
67
struct samsung_gpio_chip {
68
	struct gpio_chip	chip;
69 70
	struct samsung_gpio_cfg	*config;
	struct samsung_gpio_pm	*pm;
71
	void __iomem		*base;
72 73
	int			irq_base;
	int			group;
74
	spinlock_t		 lock;
75 76 77
#ifdef CONFIG_PM
	u32			pm_save[4];
#endif
78
	u32			bitmap_gpio_int;
79 80
};

81
static inline struct samsung_gpio_chip *to_samsung_gpio(struct gpio_chip *gpc)
82
{
83
	return container_of(gpc, struct samsung_gpio_chip, chip);
84 85
}

86 87 88 89 90 91 92 93 94 95
/**
 * samsung_gpiolib_to_irq - convert gpio pin to irq number
 * @chip: The gpio chip that the pin belongs to.
 * @offset: The offset of the pin in the chip.
 *
 * This helper returns the irq number calculated from the chip->irq_base and
 * the provided offset.
 */
extern int samsung_gpiolib_to_irq(struct gpio_chip *chip, unsigned int offset);

96
/* exported for core SoC support to change */
97
extern struct samsung_gpio_cfg s3c24xx_gpiocfg_default;
98

B
Ben Dooks 已提交
99
#ifdef CONFIG_S3C_GPIO_TRACK
100
extern struct samsung_gpio_chip *s3c_gpios[S3C_GPIO_END];
B
Ben Dooks 已提交
101

102
static inline struct samsung_gpio_chip *samsung_gpiolib_getchip(unsigned int chip)
B
Ben Dooks 已提交
103
{
104
	return (chip < S3C_GPIO_END) ? s3c_gpios[chip] : NULL;
B
Ben Dooks 已提交
105 106
}
#else
107
/* machine specific code should provide samsung_gpiolib_getchip */
108

109 110
#include <mach/gpio-track.h>

111
static inline void s3c_gpiolib_track(struct samsung_gpio_chip *chip) { }
B
Ben Dooks 已提交
112
#endif
113 114

#ifdef CONFIG_PM
115 116 117
extern struct samsung_gpio_pm samsung_gpio_pm_1bit;
extern struct samsung_gpio_pm samsung_gpio_pm_2bit;
extern struct samsung_gpio_pm samsung_gpio_pm_4bit;
118 119
#define __gpio_pm(x) x
#else
120 121 122
#define samsung_gpio_pm_1bit NULL
#define samsung_gpio_pm_2bit NULL
#define samsung_gpio_pm_4bit NULL
123 124 125
#define __gpio_pm(x) NULL

#endif /* CONFIG_PM */
126 127

/* locking wrappers to deal with multiple access to the same gpio bank */
128 129
#define samsung_gpio_lock(_oc, _fl) spin_lock_irqsave(&(_oc)->lock, _fl)
#define samsung_gpio_unlock(_oc, _fl) spin_unlock_irqrestore(&(_oc)->lock, _fl)
130 131

#endif /* __PLAT_SAMSUNG_GPIO_CORE_H */