2010-07-02 15:22:09 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) ST-Ericsson SA 2010
|
|
|
|
*
|
|
|
|
* License Terms: GNU General Public License, version 2
|
|
|
|
* Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/gpio.h>
|
|
|
|
#include <linux/irq.h>
|
2012-12-10 14:07:54 +04:00
|
|
|
#include <linux/irqdomain.h>
|
2010-07-02 15:22:09 +04:00
|
|
|
#include <linux/interrupt.h>
|
2012-11-26 15:36:51 +04:00
|
|
|
#include <linux/of.h>
|
2010-07-02 15:22:09 +04:00
|
|
|
#include <linux/mfd/stmpe.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These registers are modified under the irq bus lock and cached to avoid
|
|
|
|
* unnecessary writes in bus_sync_unlock.
|
|
|
|
*/
|
|
|
|
enum { REG_RE, REG_FE, REG_IE };
|
|
|
|
|
|
|
|
#define CACHE_NR_REGS 3
|
|
|
|
#define CACHE_NR_BANKS (STMPE_NR_GPIOS / 8)
|
|
|
|
|
|
|
|
struct stmpe_gpio {
|
|
|
|
struct gpio_chip chip;
|
|
|
|
struct stmpe *stmpe;
|
|
|
|
struct device *dev;
|
|
|
|
struct mutex irq_lock;
|
2012-12-10 14:07:54 +04:00
|
|
|
struct irq_domain *domain;
|
2010-07-02 15:22:09 +04:00
|
|
|
|
|
|
|
int irq_base;
|
2010-08-16 19:14:44 +04:00
|
|
|
unsigned norequest_mask;
|
2010-07-02 15:22:09 +04:00
|
|
|
|
|
|
|
/* Caches of interrupt control registers for bus_lock */
|
|
|
|
u8 regs[CACHE_NR_REGS][CACHE_NR_BANKS];
|
|
|
|
u8 oldregs[CACHE_NR_REGS][CACHE_NR_BANKS];
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct stmpe_gpio *to_stmpe_gpio(struct gpio_chip *chip)
|
|
|
|
{
|
|
|
|
return container_of(chip, struct stmpe_gpio, chip);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stmpe_gpio_get(struct gpio_chip *chip, unsigned offset)
|
|
|
|
{
|
|
|
|
struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip);
|
|
|
|
struct stmpe *stmpe = stmpe_gpio->stmpe;
|
|
|
|
u8 reg = stmpe->regs[STMPE_IDX_GPMR_LSB] - (offset / 8);
|
|
|
|
u8 mask = 1 << (offset % 8);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = stmpe_reg_read(stmpe, reg);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2012-02-27 09:49:43 +04:00
|
|
|
return !!(ret & mask);
|
2010-07-02 15:22:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void stmpe_gpio_set(struct gpio_chip *chip, unsigned offset, int val)
|
|
|
|
{
|
|
|
|
struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip);
|
|
|
|
struct stmpe *stmpe = stmpe_gpio->stmpe;
|
|
|
|
int which = val ? STMPE_IDX_GPSR_LSB : STMPE_IDX_GPCR_LSB;
|
|
|
|
u8 reg = stmpe->regs[which] - (offset / 8);
|
|
|
|
u8 mask = 1 << (offset % 8);
|
|
|
|
|
2011-12-14 07:58:27 +04:00
|
|
|
/*
|
|
|
|
* Some variants have single register for gpio set/clear functionality.
|
|
|
|
* For them we need to write 0 to clear and 1 to set.
|
|
|
|
*/
|
|
|
|
if (stmpe->regs[STMPE_IDX_GPSR_LSB] == stmpe->regs[STMPE_IDX_GPCR_LSB])
|
|
|
|
stmpe_set_bits(stmpe, reg, mask, val ? mask : 0);
|
|
|
|
else
|
|
|
|
stmpe_reg_write(stmpe, reg, mask);
|
2010-07-02 15:22:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int stmpe_gpio_direction_output(struct gpio_chip *chip,
|
|
|
|
unsigned offset, int val)
|
|
|
|
{
|
|
|
|
struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip);
|
|
|
|
struct stmpe *stmpe = stmpe_gpio->stmpe;
|
|
|
|
u8 reg = stmpe->regs[STMPE_IDX_GPDR_LSB] - (offset / 8);
|
|
|
|
u8 mask = 1 << (offset % 8);
|
|
|
|
|
|
|
|
stmpe_gpio_set(chip, offset, val);
|
|
|
|
|
|
|
|
return stmpe_set_bits(stmpe, reg, mask, mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stmpe_gpio_direction_input(struct gpio_chip *chip,
|
|
|
|
unsigned offset)
|
|
|
|
{
|
|
|
|
struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip);
|
|
|
|
struct stmpe *stmpe = stmpe_gpio->stmpe;
|
|
|
|
u8 reg = stmpe->regs[STMPE_IDX_GPDR_LSB] - (offset / 8);
|
|
|
|
u8 mask = 1 << (offset % 8);
|
|
|
|
|
|
|
|
return stmpe_set_bits(stmpe, reg, mask, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stmpe_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
|
|
|
|
{
|
|
|
|
struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip);
|
|
|
|
|
2012-12-10 14:07:54 +04:00
|
|
|
return irq_create_mapping(stmpe_gpio->domain, offset);
|
2010-07-02 15:22:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int stmpe_gpio_request(struct gpio_chip *chip, unsigned offset)
|
|
|
|
{
|
|
|
|
struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip);
|
|
|
|
struct stmpe *stmpe = stmpe_gpio->stmpe;
|
|
|
|
|
2010-08-16 19:14:44 +04:00
|
|
|
if (stmpe_gpio->norequest_mask & (1 << offset))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2010-07-02 15:22:09 +04:00
|
|
|
return stmpe_set_altfunc(stmpe, 1 << offset, STMPE_BLOCK_GPIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct gpio_chip template_chip = {
|
|
|
|
.label = "stmpe",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.direction_input = stmpe_gpio_direction_input,
|
|
|
|
.get = stmpe_gpio_get,
|
|
|
|
.direction_output = stmpe_gpio_direction_output,
|
|
|
|
.set = stmpe_gpio_set,
|
|
|
|
.to_irq = stmpe_gpio_to_irq,
|
|
|
|
.request = stmpe_gpio_request,
|
|
|
|
.can_sleep = 1,
|
|
|
|
};
|
|
|
|
|
2011-01-13 04:00:17 +03:00
|
|
|
static int stmpe_gpio_irq_set_type(struct irq_data *d, unsigned int type)
|
2010-07-02 15:22:09 +04:00
|
|
|
{
|
2011-01-13 04:00:17 +03:00
|
|
|
struct stmpe_gpio *stmpe_gpio = irq_data_get_irq_chip_data(d);
|
2012-12-10 14:07:54 +04:00
|
|
|
int offset = d->hwirq;
|
2010-07-02 15:22:09 +04:00
|
|
|
int regoffset = offset / 8;
|
|
|
|
int mask = 1 << (offset % 8);
|
|
|
|
|
|
|
|
if (type == IRQ_TYPE_LEVEL_LOW || type == IRQ_TYPE_LEVEL_HIGH)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2011-12-14 07:58:27 +04:00
|
|
|
/* STMPE801 doesn't have RE and FE registers */
|
|
|
|
if (stmpe_gpio->stmpe->partnum == STMPE801)
|
|
|
|
return 0;
|
|
|
|
|
2010-07-02 15:22:09 +04:00
|
|
|
if (type == IRQ_TYPE_EDGE_RISING)
|
|
|
|
stmpe_gpio->regs[REG_RE][regoffset] |= mask;
|
|
|
|
else
|
|
|
|
stmpe_gpio->regs[REG_RE][regoffset] &= ~mask;
|
|
|
|
|
|
|
|
if (type == IRQ_TYPE_EDGE_FALLING)
|
|
|
|
stmpe_gpio->regs[REG_FE][regoffset] |= mask;
|
|
|
|
else
|
|
|
|
stmpe_gpio->regs[REG_FE][regoffset] &= ~mask;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-13 04:00:17 +03:00
|
|
|
static void stmpe_gpio_irq_lock(struct irq_data *d)
|
2010-07-02 15:22:09 +04:00
|
|
|
{
|
2011-01-13 04:00:17 +03:00
|
|
|
struct stmpe_gpio *stmpe_gpio = irq_data_get_irq_chip_data(d);
|
2010-07-02 15:22:09 +04:00
|
|
|
|
|
|
|
mutex_lock(&stmpe_gpio->irq_lock);
|
|
|
|
}
|
|
|
|
|
2011-01-13 04:00:17 +03:00
|
|
|
static void stmpe_gpio_irq_sync_unlock(struct irq_data *d)
|
2010-07-02 15:22:09 +04:00
|
|
|
{
|
2011-01-13 04:00:17 +03:00
|
|
|
struct stmpe_gpio *stmpe_gpio = irq_data_get_irq_chip_data(d);
|
2010-07-02 15:22:09 +04:00
|
|
|
struct stmpe *stmpe = stmpe_gpio->stmpe;
|
|
|
|
int num_banks = DIV_ROUND_UP(stmpe->num_gpios, 8);
|
|
|
|
static const u8 regmap[] = {
|
|
|
|
[REG_RE] = STMPE_IDX_GPRER_LSB,
|
|
|
|
[REG_FE] = STMPE_IDX_GPFER_LSB,
|
|
|
|
[REG_IE] = STMPE_IDX_IEGPIOR_LSB,
|
|
|
|
};
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < CACHE_NR_REGS; i++) {
|
2011-12-14 07:58:27 +04:00
|
|
|
/* STMPE801 doesn't have RE and FE registers */
|
|
|
|
if ((stmpe->partnum == STMPE801) &&
|
|
|
|
(i != REG_IE))
|
|
|
|
continue;
|
|
|
|
|
2010-07-02 15:22:09 +04:00
|
|
|
for (j = 0; j < num_banks; j++) {
|
|
|
|
u8 old = stmpe_gpio->oldregs[i][j];
|
|
|
|
u8 new = stmpe_gpio->regs[i][j];
|
|
|
|
|
|
|
|
if (new == old)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
stmpe_gpio->oldregs[i][j] = new;
|
|
|
|
stmpe_reg_write(stmpe, stmpe->regs[regmap[i]] - j, new);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&stmpe_gpio->irq_lock);
|
|
|
|
}
|
|
|
|
|
2011-01-13 04:00:17 +03:00
|
|
|
static void stmpe_gpio_irq_mask(struct irq_data *d)
|
2010-07-02 15:22:09 +04:00
|
|
|
{
|
2011-01-13 04:00:17 +03:00
|
|
|
struct stmpe_gpio *stmpe_gpio = irq_data_get_irq_chip_data(d);
|
2012-12-10 14:07:54 +04:00
|
|
|
int offset = d->hwirq;
|
2010-07-02 15:22:09 +04:00
|
|
|
int regoffset = offset / 8;
|
|
|
|
int mask = 1 << (offset % 8);
|
|
|
|
|
|
|
|
stmpe_gpio->regs[REG_IE][regoffset] &= ~mask;
|
|
|
|
}
|
|
|
|
|
2011-01-13 04:00:17 +03:00
|
|
|
static void stmpe_gpio_irq_unmask(struct irq_data *d)
|
2010-07-02 15:22:09 +04:00
|
|
|
{
|
2011-01-13 04:00:17 +03:00
|
|
|
struct stmpe_gpio *stmpe_gpio = irq_data_get_irq_chip_data(d);
|
2012-12-10 14:07:54 +04:00
|
|
|
int offset = d->hwirq;
|
2010-07-02 15:22:09 +04:00
|
|
|
int regoffset = offset / 8;
|
|
|
|
int mask = 1 << (offset % 8);
|
|
|
|
|
|
|
|
stmpe_gpio->regs[REG_IE][regoffset] |= mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct irq_chip stmpe_gpio_irq_chip = {
|
|
|
|
.name = "stmpe-gpio",
|
2011-01-13 04:00:17 +03:00
|
|
|
.irq_bus_lock = stmpe_gpio_irq_lock,
|
|
|
|
.irq_bus_sync_unlock = stmpe_gpio_irq_sync_unlock,
|
|
|
|
.irq_mask = stmpe_gpio_irq_mask,
|
|
|
|
.irq_unmask = stmpe_gpio_irq_unmask,
|
|
|
|
.irq_set_type = stmpe_gpio_irq_set_type,
|
2010-07-02 15:22:09 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static irqreturn_t stmpe_gpio_irq(int irq, void *dev)
|
|
|
|
{
|
|
|
|
struct stmpe_gpio *stmpe_gpio = dev;
|
|
|
|
struct stmpe *stmpe = stmpe_gpio->stmpe;
|
|
|
|
u8 statmsbreg = stmpe->regs[STMPE_IDX_ISGPIOR_MSB];
|
|
|
|
int num_banks = DIV_ROUND_UP(stmpe->num_gpios, 8);
|
|
|
|
u8 status[num_banks];
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ret = stmpe_block_read(stmpe, statmsbreg, num_banks, status);
|
|
|
|
if (ret < 0)
|
|
|
|
return IRQ_NONE;
|
|
|
|
|
|
|
|
for (i = 0; i < num_banks; i++) {
|
|
|
|
int bank = num_banks - i - 1;
|
|
|
|
unsigned int enabled = stmpe_gpio->regs[REG_IE][bank];
|
|
|
|
unsigned int stat = status[i];
|
|
|
|
|
|
|
|
stat &= enabled;
|
|
|
|
if (!stat)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
while (stat) {
|
|
|
|
int bit = __ffs(stat);
|
|
|
|
int line = bank * 8 + bit;
|
2012-12-10 14:07:54 +04:00
|
|
|
int virq = irq_find_mapping(stmpe_gpio->domain, line);
|
2010-07-02 15:22:09 +04:00
|
|
|
|
2012-12-10 14:07:54 +04:00
|
|
|
handle_nested_irq(virq);
|
2010-07-02 15:22:09 +04:00
|
|
|
stat &= ~(1 << bit);
|
|
|
|
}
|
|
|
|
|
|
|
|
stmpe_reg_write(stmpe, statmsbreg + i, status[i]);
|
2011-12-14 07:58:27 +04:00
|
|
|
|
|
|
|
/* Edge detect register is not present on 801 */
|
|
|
|
if (stmpe->partnum != STMPE801)
|
|
|
|
stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_GPEDR_MSB]
|
|
|
|
+ i, status[i]);
|
2010-07-02 15:22:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2012-12-10 14:07:54 +04:00
|
|
|
int stmpe_gpio_irq_map(struct irq_domain *d, unsigned int virq,
|
|
|
|
irq_hw_number_t hwirq)
|
2010-07-02 15:22:09 +04:00
|
|
|
{
|
2012-12-10 14:07:54 +04:00
|
|
|
struct stmpe_gpio *stmpe_gpio = d->host_data;
|
|
|
|
|
|
|
|
if (!stmpe_gpio)
|
|
|
|
return -EINVAL;
|
2010-07-02 15:22:09 +04:00
|
|
|
|
2012-12-10 14:07:54 +04:00
|
|
|
irq_set_chip_data(hwirq, stmpe_gpio);
|
|
|
|
irq_set_chip_and_handler(hwirq, &stmpe_gpio_irq_chip,
|
|
|
|
handle_simple_irq);
|
|
|
|
irq_set_nested_thread(hwirq, 1);
|
2010-07-02 15:22:09 +04:00
|
|
|
#ifdef CONFIG_ARM
|
2012-12-10 14:07:54 +04:00
|
|
|
set_irq_flags(hwirq, IRQF_VALID);
|
2010-07-02 15:22:09 +04:00
|
|
|
#else
|
2012-12-10 14:07:54 +04:00
|
|
|
irq_set_noprobe(hwirq);
|
2010-07-02 15:22:09 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-10 14:07:54 +04:00
|
|
|
void stmpe_gpio_irq_unmap(struct irq_domain *d, unsigned int virq)
|
2010-07-02 15:22:09 +04:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_ARM
|
2012-12-10 14:07:54 +04:00
|
|
|
set_irq_flags(virq, 0);
|
2010-07-02 15:22:09 +04:00
|
|
|
#endif
|
2012-12-10 14:07:54 +04:00
|
|
|
irq_set_chip_and_handler(virq, NULL, NULL);
|
|
|
|
irq_set_chip_data(virq, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct irq_domain_ops stmpe_gpio_irq_simple_ops = {
|
|
|
|
.unmap = stmpe_gpio_irq_unmap,
|
|
|
|
.map = stmpe_gpio_irq_map,
|
|
|
|
.xlate = irq_domain_xlate_twocell,
|
|
|
|
};
|
|
|
|
|
Driver core updates for 3.8-rc1
Here's the large driver core updates for 3.8-rc1.
The biggest thing here is the various __dev* marking removals. This is
going to be a pain for the merge with different subsystem trees, I know,
but all of the patches included here have been ACKed by their various
subsystem maintainers, as they wanted them to go through here.
If this is too much of a pain, I can pull all of them out of this tree
and just send you one with the other fixes/updates and then, after
3.8-rc1 is out, do the rest of the removals to ensure we catch them all,
it's up to you. The merges should all be trivial, and Stephen has been
doing them all in linux-next for a few weeks now quite easily.
Other than the __dev* marking removals, there's nothing major here, some
firmware loading updates and other minor things in the driver core.
All of these have (much to Stephen's annoyance), been in linux-next for
a while.
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (GNU/Linux)
iEYEABECAAYFAlDHkPkACgkQMUfUDdst+ykaWgCfW7AM30cv0nzoVO08ax6KjlG1
KVYAn3z/KYazvp4B6LMvrW9y0G34Wmad
=yvVr
-----END PGP SIGNATURE-----
Merge tag 'driver-core-3.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core
Pull driver core updates from Greg Kroah-Hartman:
"Here's the large driver core updates for 3.8-rc1.
The biggest thing here is the various __dev* marking removals. This
is going to be a pain for the merge with different subsystem trees, I
know, but all of the patches included here have been ACKed by their
various subsystem maintainers, as they wanted them to go through here.
If this is too much of a pain, I can pull all of them out of this tree
and just send you one with the other fixes/updates and then, after
3.8-rc1 is out, do the rest of the removals to ensure we catch them
all, it's up to you. The merges should all be trivial, and Stephen
has been doing them all in linux-next for a few weeks now quite
easily.
Other than the __dev* marking removals, there's nothing major here,
some firmware loading updates and other minor things in the driver
core.
All of these have (much to Stephen's annoyance), been in linux-next
for a while.
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>"
Fixed up trivial conflicts in drivers/gpio/gpio-{em,stmpe}.c due to gpio
update.
* tag 'driver-core-3.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: (93 commits)
modpost.c: Stop checking __dev* section mismatches
init.h: Remove __dev* sections from the kernel
acpi: remove use of __devinit
PCI: Remove __dev* markings
PCI: Always build setup-bus when PCI is enabled
PCI: Move pci_uevent into pci-driver.c
PCI: Remove CONFIG_HOTPLUG ifdefs
unicore32/PCI: Remove CONFIG_HOTPLUG ifdefs
sh/PCI: Remove CONFIG_HOTPLUG ifdefs
powerpc/PCI: Remove CONFIG_HOTPLUG ifdefs
mips/PCI: Remove CONFIG_HOTPLUG ifdefs
microblaze/PCI: Remove CONFIG_HOTPLUG ifdefs
dma: remove use of __devinit
dma: remove use of __devexit_p
firewire: remove use of __devinitdata
firewire: remove use of __devinit
leds: remove use of __devexit
leds: remove use of __devinit
leds: remove use of __devexit_p
mmc: remove use of __devexit
...
2012-12-12 01:13:55 +04:00
|
|
|
static int stmpe_gpio_irq_init(struct stmpe_gpio *stmpe_gpio)
|
2012-12-10 14:07:54 +04:00
|
|
|
{
|
|
|
|
int base = stmpe_gpio->irq_base;
|
|
|
|
|
|
|
|
stmpe_gpio->domain = irq_domain_add_simple(NULL,
|
|
|
|
stmpe_gpio->chip.ngpio, base,
|
|
|
|
&stmpe_gpio_irq_simple_ops, stmpe_gpio);
|
|
|
|
if (!stmpe_gpio->domain) {
|
|
|
|
dev_err(stmpe_gpio->dev, "failed to create irqdomain\n");
|
|
|
|
return -ENOSYS;
|
2010-07-02 15:22:09 +04:00
|
|
|
}
|
2012-12-10 14:07:54 +04:00
|
|
|
|
|
|
|
return 0;
|
2010-07-02 15:22:09 +04:00
|
|
|
}
|
|
|
|
|
2012-11-19 22:22:34 +04:00
|
|
|
static int stmpe_gpio_probe(struct platform_device *pdev)
|
2010-07-02 15:22:09 +04:00
|
|
|
{
|
|
|
|
struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent);
|
2012-11-26 15:36:51 +04:00
|
|
|
struct device_node *np = pdev->dev.of_node;
|
2010-07-02 15:22:09 +04:00
|
|
|
struct stmpe_gpio_platform_data *pdata;
|
|
|
|
struct stmpe_gpio *stmpe_gpio;
|
|
|
|
int ret;
|
2012-01-27 01:17:15 +04:00
|
|
|
int irq = 0;
|
2010-07-02 15:22:09 +04:00
|
|
|
|
|
|
|
pdata = stmpe->pdata->gpio;
|
|
|
|
|
|
|
|
irq = platform_get_irq(pdev, 0);
|
|
|
|
|
|
|
|
stmpe_gpio = kzalloc(sizeof(struct stmpe_gpio), GFP_KERNEL);
|
|
|
|
if (!stmpe_gpio)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
mutex_init(&stmpe_gpio->irq_lock);
|
|
|
|
|
|
|
|
stmpe_gpio->dev = &pdev->dev;
|
|
|
|
stmpe_gpio->stmpe = stmpe;
|
|
|
|
stmpe_gpio->chip = template_chip;
|
|
|
|
stmpe_gpio->chip.ngpio = stmpe->num_gpios;
|
|
|
|
stmpe_gpio->chip.dev = &pdev->dev;
|
|
|
|
stmpe_gpio->chip.base = pdata ? pdata->gpio_base : -1;
|
|
|
|
|
2012-11-26 15:36:51 +04:00
|
|
|
if (pdata)
|
|
|
|
stmpe_gpio->norequest_mask = pdata->norequest_mask;
|
|
|
|
else if (np)
|
|
|
|
of_property_read_u32(np, "st,norequest-mask",
|
|
|
|
&stmpe_gpio->norequest_mask);
|
|
|
|
|
2012-01-27 01:17:15 +04:00
|
|
|
if (irq >= 0)
|
|
|
|
stmpe_gpio->irq_base = stmpe->irq_base + STMPE_INT_GPIO(0);
|
|
|
|
else
|
|
|
|
dev_info(&pdev->dev,
|
|
|
|
"device configured in no-irq mode; "
|
|
|
|
"irqs are not available\n");
|
2010-07-02 15:22:09 +04:00
|
|
|
|
|
|
|
ret = stmpe_enable(stmpe, STMPE_BLOCK_GPIO);
|
|
|
|
if (ret)
|
2010-09-12 22:57:19 +04:00
|
|
|
goto out_free;
|
2010-07-02 15:22:09 +04:00
|
|
|
|
2012-01-27 01:17:15 +04:00
|
|
|
if (irq >= 0) {
|
|
|
|
ret = stmpe_gpio_irq_init(stmpe_gpio);
|
|
|
|
if (ret)
|
|
|
|
goto out_disable;
|
2010-07-02 15:22:09 +04:00
|
|
|
|
2012-01-27 01:17:15 +04:00
|
|
|
ret = request_threaded_irq(irq, NULL, stmpe_gpio_irq,
|
|
|
|
IRQF_ONESHOT, "stmpe-gpio", stmpe_gpio);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "unable to get irq: %d\n", ret);
|
2012-12-10 14:07:54 +04:00
|
|
|
goto out_disable;
|
2012-01-27 01:17:15 +04:00
|
|
|
}
|
2010-07-02 15:22:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = gpiochip_add(&stmpe_gpio->chip);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret);
|
|
|
|
goto out_freeirq;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pdata && pdata->setup)
|
|
|
|
pdata->setup(stmpe, stmpe_gpio->chip.base);
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, stmpe_gpio);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_freeirq:
|
2012-01-27 01:17:15 +04:00
|
|
|
if (irq >= 0)
|
|
|
|
free_irq(irq, stmpe_gpio);
|
2010-09-12 22:57:19 +04:00
|
|
|
out_disable:
|
|
|
|
stmpe_disable(stmpe, STMPE_BLOCK_GPIO);
|
2010-07-02 15:22:09 +04:00
|
|
|
out_free:
|
|
|
|
kfree(stmpe_gpio);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-19 22:25:50 +04:00
|
|
|
static int stmpe_gpio_remove(struct platform_device *pdev)
|
2010-07-02 15:22:09 +04:00
|
|
|
{
|
|
|
|
struct stmpe_gpio *stmpe_gpio = platform_get_drvdata(pdev);
|
|
|
|
struct stmpe *stmpe = stmpe_gpio->stmpe;
|
|
|
|
struct stmpe_gpio_platform_data *pdata = stmpe->pdata->gpio;
|
|
|
|
int irq = platform_get_irq(pdev, 0);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (pdata && pdata->remove)
|
|
|
|
pdata->remove(stmpe, stmpe_gpio->chip.base);
|
|
|
|
|
|
|
|
ret = gpiochip_remove(&stmpe_gpio->chip);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(stmpe_gpio->dev,
|
|
|
|
"unable to remove gpiochip: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
stmpe_disable(stmpe, STMPE_BLOCK_GPIO);
|
|
|
|
|
2012-12-10 14:07:54 +04:00
|
|
|
if (irq >= 0)
|
2012-01-27 01:17:15 +04:00
|
|
|
free_irq(irq, stmpe_gpio);
|
2012-12-10 14:07:54 +04:00
|
|
|
|
2010-07-02 15:22:09 +04:00
|
|
|
platform_set_drvdata(pdev, NULL);
|
|
|
|
kfree(stmpe_gpio);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver stmpe_gpio_driver = {
|
|
|
|
.driver.name = "stmpe-gpio",
|
|
|
|
.driver.owner = THIS_MODULE,
|
|
|
|
.probe = stmpe_gpio_probe,
|
2012-11-19 22:20:08 +04:00
|
|
|
.remove = stmpe_gpio_remove,
|
2010-07-02 15:22:09 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init stmpe_gpio_init(void)
|
|
|
|
{
|
|
|
|
return platform_driver_register(&stmpe_gpio_driver);
|
|
|
|
}
|
|
|
|
subsys_initcall(stmpe_gpio_init);
|
|
|
|
|
|
|
|
static void __exit stmpe_gpio_exit(void)
|
|
|
|
{
|
|
|
|
platform_driver_unregister(&stmpe_gpio_driver);
|
|
|
|
}
|
|
|
|
module_exit(stmpe_gpio_exit);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL v2");
|
|
|
|
MODULE_DESCRIPTION("STMPExxxx GPIO driver");
|
|
|
|
MODULE_AUTHOR("Rabin Vincent <rabin.vincent@stericsson.com>");
|