2019-06-04 08:11:33 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2008-02-07 08:14:49 +00:00
|
|
|
/*
|
|
|
|
* driver/mfd/asic3.c
|
|
|
|
*
|
|
|
|
* Compaq ASIC3 support.
|
|
|
|
*
|
|
|
|
* Copyright 2001 Compaq Computer Corporation.
|
|
|
|
* Copyright 2004-2005 Phil Blundell
|
2008-06-20 09:02:19 +00:00
|
|
|
* Copyright 2007-2008 OpenedHand Ltd.
|
2008-02-07 08:14:49 +00:00
|
|
|
*
|
|
|
|
* Authors: Phil Blundell <pb@handhelds.org>,
|
|
|
|
* Samuel Ortiz <sameo@openedhand.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
2009-06-15 10:10:24 +00:00
|
|
|
#include <linux/delay.h>
|
2008-02-07 08:14:49 +00:00
|
|
|
#include <linux/irq.h>
|
2019-08-14 07:24:03 +00:00
|
|
|
#include <linux/gpio/driver.h>
|
2011-07-10 16:41:10 +00:00
|
|
|
#include <linux/export.h>
|
2008-02-07 08:14:49 +00:00
|
|
|
#include <linux/io.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2008-02-07 08:14:49 +00:00
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
|
|
|
|
#include <linux/mfd/asic3.h>
|
2009-06-15 10:10:24 +00:00
|
|
|
#include <linux/mfd/core.h>
|
|
|
|
#include <linux/mfd/ds1wm.h>
|
2009-06-15 10:10:25 +00:00
|
|
|
#include <linux/mfd/tmio.h>
|
2008-02-07 08:14:49 +00:00
|
|
|
|
2018-05-26 09:31:50 +00:00
|
|
|
#include <linux/mmc/host.h>
|
|
|
|
|
2009-06-05 16:31:02 +00:00
|
|
|
enum {
|
|
|
|
ASIC3_CLOCK_SPI,
|
|
|
|
ASIC3_CLOCK_OWM,
|
|
|
|
ASIC3_CLOCK_PWM0,
|
|
|
|
ASIC3_CLOCK_PWM1,
|
|
|
|
ASIC3_CLOCK_LED0,
|
|
|
|
ASIC3_CLOCK_LED1,
|
|
|
|
ASIC3_CLOCK_LED2,
|
|
|
|
ASIC3_CLOCK_SD_HOST,
|
|
|
|
ASIC3_CLOCK_SD_BUS,
|
|
|
|
ASIC3_CLOCK_SMBUS,
|
|
|
|
ASIC3_CLOCK_EX0,
|
|
|
|
ASIC3_CLOCK_EX1,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct asic3_clk {
|
|
|
|
int enabled;
|
|
|
|
unsigned int cdex;
|
|
|
|
unsigned long rate;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define INIT_CDEX(_name, _rate) \
|
|
|
|
[ASIC3_CLOCK_##_name] = { \
|
|
|
|
.cdex = CLOCK_CDEX_##_name, \
|
|
|
|
.rate = _rate, \
|
|
|
|
}
|
|
|
|
|
2010-12-11 12:59:35 +00:00
|
|
|
static struct asic3_clk asic3_clk_init[] __initdata = {
|
2009-06-05 16:31:02 +00:00
|
|
|
INIT_CDEX(SPI, 0),
|
|
|
|
INIT_CDEX(OWM, 5000000),
|
|
|
|
INIT_CDEX(PWM0, 0),
|
|
|
|
INIT_CDEX(PWM1, 0),
|
|
|
|
INIT_CDEX(LED0, 0),
|
|
|
|
INIT_CDEX(LED1, 0),
|
|
|
|
INIT_CDEX(LED2, 0),
|
|
|
|
INIT_CDEX(SD_HOST, 24576000),
|
|
|
|
INIT_CDEX(SD_BUS, 12288000),
|
|
|
|
INIT_CDEX(SMBUS, 0),
|
|
|
|
INIT_CDEX(EX0, 32768),
|
|
|
|
INIT_CDEX(EX1, 24576000),
|
|
|
|
};
|
|
|
|
|
2008-06-20 09:02:19 +00:00
|
|
|
struct asic3 {
|
|
|
|
void __iomem *mapping;
|
|
|
|
unsigned int bus_shift;
|
|
|
|
unsigned int irq_nr;
|
|
|
|
unsigned int irq_base;
|
2017-03-21 22:43:04 +00:00
|
|
|
raw_spinlock_t lock;
|
2008-06-20 09:02:19 +00:00
|
|
|
u16 irq_bothedge[4];
|
|
|
|
struct gpio_chip gpio;
|
|
|
|
struct device *dev;
|
2010-01-06 12:51:48 +00:00
|
|
|
void __iomem *tmio_cnf;
|
2009-06-05 16:31:02 +00:00
|
|
|
|
|
|
|
struct asic3_clk clocks[ARRAY_SIZE(asic3_clk_init)];
|
2008-06-20 09:02:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int asic3_gpio_get(struct gpio_chip *chip, unsigned offset);
|
|
|
|
|
2011-05-13 18:53:03 +00:00
|
|
|
void asic3_write_register(struct asic3 *asic, unsigned int reg, u32 value)
|
2008-02-07 08:14:49 +00:00
|
|
|
{
|
2008-03-29 03:10:58 +00:00
|
|
|
iowrite16(value, asic->mapping +
|
2008-02-07 08:14:49 +00:00
|
|
|
(reg >> asic->bus_shift));
|
|
|
|
}
|
2011-05-13 18:53:03 +00:00
|
|
|
EXPORT_SYMBOL_GPL(asic3_write_register);
|
2008-02-07 08:14:49 +00:00
|
|
|
|
2011-05-13 18:53:03 +00:00
|
|
|
u32 asic3_read_register(struct asic3 *asic, unsigned int reg)
|
2008-02-07 08:14:49 +00:00
|
|
|
{
|
2008-03-29 03:10:58 +00:00
|
|
|
return ioread16(asic->mapping +
|
2008-02-07 08:14:49 +00:00
|
|
|
(reg >> asic->bus_shift));
|
|
|
|
}
|
2011-05-13 18:53:03 +00:00
|
|
|
EXPORT_SYMBOL_GPL(asic3_read_register);
|
2008-02-07 08:14:49 +00:00
|
|
|
|
2010-12-11 12:59:35 +00:00
|
|
|
static void asic3_set_register(struct asic3 *asic, u32 reg, u32 bits, bool set)
|
2009-06-05 16:31:01 +00:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
u32 val;
|
|
|
|
|
2017-03-21 22:43:04 +00:00
|
|
|
raw_spin_lock_irqsave(&asic->lock, flags);
|
2009-06-05 16:31:01 +00:00
|
|
|
val = asic3_read_register(asic, reg);
|
|
|
|
if (set)
|
|
|
|
val |= bits;
|
|
|
|
else
|
|
|
|
val &= ~bits;
|
|
|
|
asic3_write_register(asic, reg, val);
|
2017-03-21 22:43:04 +00:00
|
|
|
raw_spin_unlock_irqrestore(&asic->lock, flags);
|
2009-06-05 16:31:01 +00:00
|
|
|
}
|
|
|
|
|
2008-02-07 08:14:49 +00:00
|
|
|
/* IRQs */
|
|
|
|
#define MAX_ASIC_ISR_LOOPS 20
|
2008-06-20 09:12:21 +00:00
|
|
|
#define ASIC3_GPIO_BASE_INCR \
|
|
|
|
(ASIC3_GPIO_B_BASE - ASIC3_GPIO_A_BASE)
|
2008-02-07 08:14:49 +00:00
|
|
|
|
|
|
|
static void asic3_irq_flip_edge(struct asic3 *asic,
|
|
|
|
u32 base, int bit)
|
|
|
|
{
|
|
|
|
u16 edge;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2017-03-21 22:43:04 +00:00
|
|
|
raw_spin_lock_irqsave(&asic->lock, flags);
|
2008-02-07 08:14:49 +00:00
|
|
|
edge = asic3_read_register(asic,
|
2008-06-20 09:12:21 +00:00
|
|
|
base + ASIC3_GPIO_EDGE_TRIGGER);
|
2008-02-07 08:14:49 +00:00
|
|
|
edge ^= bit;
|
|
|
|
asic3_write_register(asic,
|
2008-06-20 09:12:21 +00:00
|
|
|
base + ASIC3_GPIO_EDGE_TRIGGER, edge);
|
2017-03-21 22:43:04 +00:00
|
|
|
raw_spin_unlock_irqrestore(&asic->lock, flags);
|
2008-02-07 08:14:49 +00:00
|
|
|
}
|
|
|
|
|
2015-09-14 08:42:37 +00:00
|
|
|
static void asic3_irq_demux(struct irq_desc *desc)
|
2008-02-07 08:14:49 +00:00
|
|
|
{
|
2011-03-25 11:12:26 +00:00
|
|
|
struct asic3 *asic = irq_desc_get_handler_data(desc);
|
|
|
|
struct irq_data *data = irq_desc_get_irq_data(desc);
|
2008-02-07 08:14:49 +00:00
|
|
|
int iter, i;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2011-04-14 14:43:47 +00:00
|
|
|
data->chip->irq_ack(data);
|
2008-02-07 08:14:49 +00:00
|
|
|
|
|
|
|
for (iter = 0 ; iter < MAX_ASIC_ISR_LOOPS; iter++) {
|
|
|
|
u32 status;
|
|
|
|
int bank;
|
|
|
|
|
2017-03-21 22:43:04 +00:00
|
|
|
raw_spin_lock_irqsave(&asic->lock, flags);
|
2008-02-07 08:14:49 +00:00
|
|
|
status = asic3_read_register(asic,
|
2008-06-20 09:12:21 +00:00
|
|
|
ASIC3_OFFSET(INTR, P_INT_STAT));
|
2017-03-21 22:43:04 +00:00
|
|
|
raw_spin_unlock_irqrestore(&asic->lock, flags);
|
2008-02-07 08:14:49 +00:00
|
|
|
|
|
|
|
/* Check all ten register bits */
|
|
|
|
if ((status & 0x3ff) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Handle GPIO IRQs */
|
|
|
|
for (bank = 0; bank < ASIC3_NUM_GPIO_BANKS; bank++) {
|
|
|
|
if (status & (1 << bank)) {
|
|
|
|
unsigned long base, istat;
|
|
|
|
|
2008-06-20 09:12:21 +00:00
|
|
|
base = ASIC3_GPIO_A_BASE
|
|
|
|
+ bank * ASIC3_GPIO_BASE_INCR;
|
2017-03-21 22:43:04 +00:00
|
|
|
raw_spin_lock_irqsave(&asic->lock, flags);
|
2008-02-07 08:14:49 +00:00
|
|
|
istat = asic3_read_register(asic,
|
|
|
|
base +
|
2008-06-20 09:12:21 +00:00
|
|
|
ASIC3_GPIO_INT_STATUS);
|
2008-02-07 08:14:49 +00:00
|
|
|
/* Clearing IntStatus */
|
|
|
|
asic3_write_register(asic,
|
|
|
|
base +
|
2008-06-20 09:12:21 +00:00
|
|
|
ASIC3_GPIO_INT_STATUS, 0);
|
2017-03-21 22:43:04 +00:00
|
|
|
raw_spin_unlock_irqrestore(&asic->lock, flags);
|
2008-02-07 08:14:49 +00:00
|
|
|
|
|
|
|
for (i = 0; i < ASIC3_GPIOS_PER_BANK; i++) {
|
|
|
|
int bit = (1 << i);
|
|
|
|
unsigned int irqnr;
|
|
|
|
|
|
|
|
if (!(istat & bit))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
irqnr = asic->irq_base +
|
|
|
|
(ASIC3_GPIOS_PER_BANK * bank)
|
|
|
|
+ i;
|
2011-03-25 11:12:26 +00:00
|
|
|
generic_handle_irq(irqnr);
|
2008-02-07 08:14:49 +00:00
|
|
|
if (asic->irq_bothedge[bank] & bit)
|
|
|
|
asic3_irq_flip_edge(asic, base,
|
|
|
|
bit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle remaining IRQs in the status register */
|
|
|
|
for (i = ASIC3_NUM_GPIOS; i < ASIC3_NR_IRQS; i++) {
|
|
|
|
/* They start at bit 4 and go up */
|
2011-03-25 11:12:26 +00:00
|
|
|
if (status & (1 << (i - ASIC3_NUM_GPIOS + 4)))
|
|
|
|
generic_handle_irq(asic->irq_base + i);
|
2008-02-07 08:14:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iter >= MAX_ASIC_ISR_LOOPS)
|
2008-06-20 09:11:19 +00:00
|
|
|
dev_err(asic->dev, "interrupt processing overrun\n");
|
2008-02-07 08:14:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int asic3_irq_to_bank(struct asic3 *asic, int irq)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
|
|
|
|
n = (irq - asic->irq_base) >> 4;
|
|
|
|
|
2008-06-20 09:12:21 +00:00
|
|
|
return (n * (ASIC3_GPIO_B_BASE - ASIC3_GPIO_A_BASE));
|
2008-02-07 08:14:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int asic3_irq_to_index(struct asic3 *asic, int irq)
|
|
|
|
{
|
|
|
|
return (irq - asic->irq_base) & 0xf;
|
|
|
|
}
|
|
|
|
|
2010-12-11 13:08:57 +00:00
|
|
|
static void asic3_mask_gpio_irq(struct irq_data *data)
|
2008-02-07 08:14:49 +00:00
|
|
|
{
|
2010-12-11 13:08:57 +00:00
|
|
|
struct asic3 *asic = irq_data_get_irq_chip_data(data);
|
2008-02-07 08:14:49 +00:00
|
|
|
u32 val, bank, index;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2010-12-11 13:08:57 +00:00
|
|
|
bank = asic3_irq_to_bank(asic, data->irq);
|
|
|
|
index = asic3_irq_to_index(asic, data->irq);
|
2008-02-07 08:14:49 +00:00
|
|
|
|
2017-03-21 22:43:04 +00:00
|
|
|
raw_spin_lock_irqsave(&asic->lock, flags);
|
2008-06-20 09:12:21 +00:00
|
|
|
val = asic3_read_register(asic, bank + ASIC3_GPIO_MASK);
|
2008-02-07 08:14:49 +00:00
|
|
|
val |= 1 << index;
|
2008-06-20 09:12:21 +00:00
|
|
|
asic3_write_register(asic, bank + ASIC3_GPIO_MASK, val);
|
2017-03-21 22:43:04 +00:00
|
|
|
raw_spin_unlock_irqrestore(&asic->lock, flags);
|
2008-02-07 08:14:49 +00:00
|
|
|
}
|
|
|
|
|
2010-12-11 13:08:57 +00:00
|
|
|
static void asic3_mask_irq(struct irq_data *data)
|
2008-02-07 08:14:49 +00:00
|
|
|
{
|
2010-12-11 13:08:57 +00:00
|
|
|
struct asic3 *asic = irq_data_get_irq_chip_data(data);
|
2008-02-07 08:14:49 +00:00
|
|
|
int regval;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2017-03-21 22:43:04 +00:00
|
|
|
raw_spin_lock_irqsave(&asic->lock, flags);
|
2008-02-07 08:14:49 +00:00
|
|
|
regval = asic3_read_register(asic,
|
2008-06-20 09:12:21 +00:00
|
|
|
ASIC3_INTR_BASE +
|
|
|
|
ASIC3_INTR_INT_MASK);
|
2008-02-07 08:14:49 +00:00
|
|
|
|
|
|
|
regval &= ~(ASIC3_INTMASK_MASK0 <<
|
2010-12-11 13:08:57 +00:00
|
|
|
(data->irq - (asic->irq_base + ASIC3_NUM_GPIOS)));
|
2008-02-07 08:14:49 +00:00
|
|
|
|
|
|
|
asic3_write_register(asic,
|
2008-06-20 09:12:21 +00:00
|
|
|
ASIC3_INTR_BASE +
|
|
|
|
ASIC3_INTR_INT_MASK,
|
2008-02-07 08:14:49 +00:00
|
|
|
regval);
|
2017-03-21 22:43:04 +00:00
|
|
|
raw_spin_unlock_irqrestore(&asic->lock, flags);
|
2008-02-07 08:14:49 +00:00
|
|
|
}
|
|
|
|
|
2010-12-11 13:08:57 +00:00
|
|
|
static void asic3_unmask_gpio_irq(struct irq_data *data)
|
2008-02-07 08:14:49 +00:00
|
|
|
{
|
2010-12-11 13:08:57 +00:00
|
|
|
struct asic3 *asic = irq_data_get_irq_chip_data(data);
|
2008-02-07 08:14:49 +00:00
|
|
|
u32 val, bank, index;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2010-12-11 13:08:57 +00:00
|
|
|
bank = asic3_irq_to_bank(asic, data->irq);
|
|
|
|
index = asic3_irq_to_index(asic, data->irq);
|
2008-02-07 08:14:49 +00:00
|
|
|
|
2017-03-21 22:43:04 +00:00
|
|
|
raw_spin_lock_irqsave(&asic->lock, flags);
|
2008-06-20 09:12:21 +00:00
|
|
|
val = asic3_read_register(asic, bank + ASIC3_GPIO_MASK);
|
2008-02-07 08:14:49 +00:00
|
|
|
val &= ~(1 << index);
|
2008-06-20 09:12:21 +00:00
|
|
|
asic3_write_register(asic, bank + ASIC3_GPIO_MASK, val);
|
2017-03-21 22:43:04 +00:00
|
|
|
raw_spin_unlock_irqrestore(&asic->lock, flags);
|
2008-02-07 08:14:49 +00:00
|
|
|
}
|
|
|
|
|
2010-12-11 13:08:57 +00:00
|
|
|
static void asic3_unmask_irq(struct irq_data *data)
|
2008-02-07 08:14:49 +00:00
|
|
|
{
|
2010-12-11 13:08:57 +00:00
|
|
|
struct asic3 *asic = irq_data_get_irq_chip_data(data);
|
2008-02-07 08:14:49 +00:00
|
|
|
int regval;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2017-03-21 22:43:04 +00:00
|
|
|
raw_spin_lock_irqsave(&asic->lock, flags);
|
2008-02-07 08:14:49 +00:00
|
|
|
regval = asic3_read_register(asic,
|
2008-06-20 09:12:21 +00:00
|
|
|
ASIC3_INTR_BASE +
|
|
|
|
ASIC3_INTR_INT_MASK);
|
2008-02-07 08:14:49 +00:00
|
|
|
|
|
|
|
regval |= (ASIC3_INTMASK_MASK0 <<
|
2010-12-11 13:08:57 +00:00
|
|
|
(data->irq - (asic->irq_base + ASIC3_NUM_GPIOS)));
|
2008-02-07 08:14:49 +00:00
|
|
|
|
|
|
|
asic3_write_register(asic,
|
2008-06-20 09:12:21 +00:00
|
|
|
ASIC3_INTR_BASE +
|
|
|
|
ASIC3_INTR_INT_MASK,
|
2008-02-07 08:14:49 +00:00
|
|
|
regval);
|
2017-03-21 22:43:04 +00:00
|
|
|
raw_spin_unlock_irqrestore(&asic->lock, flags);
|
2008-02-07 08:14:49 +00:00
|
|
|
}
|
|
|
|
|
2010-12-11 13:08:57 +00:00
|
|
|
static int asic3_gpio_irq_type(struct irq_data *data, unsigned int type)
|
2008-02-07 08:14:49 +00:00
|
|
|
{
|
2010-12-11 13:08:57 +00:00
|
|
|
struct asic3 *asic = irq_data_get_irq_chip_data(data);
|
2008-02-07 08:14:49 +00:00
|
|
|
u32 bank, index;
|
|
|
|
u16 trigger, level, edge, bit;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2010-12-11 13:08:57 +00:00
|
|
|
bank = asic3_irq_to_bank(asic, data->irq);
|
|
|
|
index = asic3_irq_to_index(asic, data->irq);
|
2008-02-07 08:14:49 +00:00
|
|
|
bit = 1<<index;
|
|
|
|
|
2017-03-21 22:43:04 +00:00
|
|
|
raw_spin_lock_irqsave(&asic->lock, flags);
|
2008-02-07 08:14:49 +00:00
|
|
|
level = asic3_read_register(asic,
|
2008-06-20 09:12:21 +00:00
|
|
|
bank + ASIC3_GPIO_LEVEL_TRIGGER);
|
2008-02-07 08:14:49 +00:00
|
|
|
edge = asic3_read_register(asic,
|
2008-06-20 09:12:21 +00:00
|
|
|
bank + ASIC3_GPIO_EDGE_TRIGGER);
|
2008-02-07 08:14:49 +00:00
|
|
|
trigger = asic3_read_register(asic,
|
2008-06-20 09:12:21 +00:00
|
|
|
bank + ASIC3_GPIO_TRIGGER_TYPE);
|
2010-12-11 13:08:57 +00:00
|
|
|
asic->irq_bothedge[(data->irq - asic->irq_base) >> 4] &= ~bit;
|
2008-02-07 08:14:49 +00:00
|
|
|
|
2008-07-27 03:23:31 +00:00
|
|
|
if (type == IRQ_TYPE_EDGE_RISING) {
|
2008-02-07 08:14:49 +00:00
|
|
|
trigger |= bit;
|
|
|
|
edge |= bit;
|
2008-07-27 03:23:31 +00:00
|
|
|
} else if (type == IRQ_TYPE_EDGE_FALLING) {
|
2008-02-07 08:14:49 +00:00
|
|
|
trigger |= bit;
|
|
|
|
edge &= ~bit;
|
2008-07-27 03:23:31 +00:00
|
|
|
} else if (type == IRQ_TYPE_EDGE_BOTH) {
|
2008-02-07 08:14:49 +00:00
|
|
|
trigger |= bit;
|
2010-12-11 13:08:57 +00:00
|
|
|
if (asic3_gpio_get(&asic->gpio, data->irq - asic->irq_base))
|
2008-02-07 08:14:49 +00:00
|
|
|
edge &= ~bit;
|
|
|
|
else
|
|
|
|
edge |= bit;
|
2010-12-11 13:08:57 +00:00
|
|
|
asic->irq_bothedge[(data->irq - asic->irq_base) >> 4] |= bit;
|
2008-07-27 03:23:31 +00:00
|
|
|
} else if (type == IRQ_TYPE_LEVEL_LOW) {
|
2008-02-07 08:14:49 +00:00
|
|
|
trigger &= ~bit;
|
|
|
|
level &= ~bit;
|
2008-07-27 03:23:31 +00:00
|
|
|
} else if (type == IRQ_TYPE_LEVEL_HIGH) {
|
2008-02-07 08:14:49 +00:00
|
|
|
trigger &= ~bit;
|
|
|
|
level |= bit;
|
|
|
|
} else {
|
|
|
|
/*
|
2008-07-27 03:23:31 +00:00
|
|
|
* if type == IRQ_TYPE_NONE, we should mask interrupts, but
|
2008-02-07 08:14:49 +00:00
|
|
|
* be careful to not unmask them if mask was also called.
|
|
|
|
* Probably need internal state for mask.
|
|
|
|
*/
|
2008-06-20 09:11:19 +00:00
|
|
|
dev_notice(asic->dev, "irq type not changed\n");
|
2008-02-07 08:14:49 +00:00
|
|
|
}
|
2008-06-20 09:12:21 +00:00
|
|
|
asic3_write_register(asic, bank + ASIC3_GPIO_LEVEL_TRIGGER,
|
2008-02-07 08:14:49 +00:00
|
|
|
level);
|
2008-06-20 09:12:21 +00:00
|
|
|
asic3_write_register(asic, bank + ASIC3_GPIO_EDGE_TRIGGER,
|
2008-02-07 08:14:49 +00:00
|
|
|
edge);
|
2008-06-20 09:12:21 +00:00
|
|
|
asic3_write_register(asic, bank + ASIC3_GPIO_TRIGGER_TYPE,
|
2008-02-07 08:14:49 +00:00
|
|
|
trigger);
|
2017-03-21 22:43:04 +00:00
|
|
|
raw_spin_unlock_irqrestore(&asic->lock, flags);
|
2008-02-07 08:14:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-10 23:35:34 +00:00
|
|
|
static int asic3_gpio_irq_set_wake(struct irq_data *data, unsigned int on)
|
|
|
|
{
|
|
|
|
struct asic3 *asic = irq_data_get_irq_chip_data(data);
|
|
|
|
u32 bank, index;
|
|
|
|
u16 bit;
|
|
|
|
|
|
|
|
bank = asic3_irq_to_bank(asic, data->irq);
|
|
|
|
index = asic3_irq_to_index(asic, data->irq);
|
|
|
|
bit = 1<<index;
|
|
|
|
|
|
|
|
asic3_set_register(asic, bank + ASIC3_GPIO_SLEEP_MASK, bit, !on);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-07 08:14:49 +00:00
|
|
|
static struct irq_chip asic3_gpio_irq_chip = {
|
|
|
|
.name = "ASIC3-GPIO",
|
2010-12-11 13:08:57 +00:00
|
|
|
.irq_ack = asic3_mask_gpio_irq,
|
|
|
|
.irq_mask = asic3_mask_gpio_irq,
|
|
|
|
.irq_unmask = asic3_unmask_gpio_irq,
|
|
|
|
.irq_set_type = asic3_gpio_irq_type,
|
2012-04-10 23:35:34 +00:00
|
|
|
.irq_set_wake = asic3_gpio_irq_set_wake,
|
2008-02-07 08:14:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct irq_chip asic3_irq_chip = {
|
|
|
|
.name = "ASIC3",
|
2010-12-11 13:08:57 +00:00
|
|
|
.irq_ack = asic3_mask_irq,
|
|
|
|
.irq_mask = asic3_mask_irq,
|
|
|
|
.irq_unmask = asic3_unmask_irq,
|
2008-02-07 08:14:49 +00:00
|
|
|
};
|
|
|
|
|
2008-06-20 22:51:38 +00:00
|
|
|
static int __init asic3_irq_probe(struct platform_device *pdev)
|
2008-02-07 08:14:49 +00:00
|
|
|
{
|
|
|
|
struct asic3 *asic = platform_get_drvdata(pdev);
|
|
|
|
unsigned long clksel = 0;
|
|
|
|
unsigned int irq, irq_base;
|
2008-07-26 02:44:41 +00:00
|
|
|
int ret;
|
2008-02-07 08:14:49 +00:00
|
|
|
|
2008-07-26 02:44:41 +00:00
|
|
|
ret = platform_get_irq(pdev, 0);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
asic->irq_nr = ret;
|
2008-02-07 08:14:49 +00:00
|
|
|
|
|
|
|
/* turn on clock to IRQ controller */
|
|
|
|
clksel |= CLOCK_SEL_CX;
|
|
|
|
asic3_write_register(asic, ASIC3_OFFSET(CLOCK, SEL),
|
|
|
|
clksel);
|
|
|
|
|
|
|
|
irq_base = asic->irq_base;
|
|
|
|
|
|
|
|
for (irq = irq_base; irq < irq_base + ASIC3_NR_IRQS; irq++) {
|
|
|
|
if (irq < asic->irq_base + ASIC3_NUM_GPIOS)
|
2011-03-25 11:12:32 +00:00
|
|
|
irq_set_chip(irq, &asic3_gpio_irq_chip);
|
2008-02-07 08:14:49 +00:00
|
|
|
else
|
2011-03-25 11:12:32 +00:00
|
|
|
irq_set_chip(irq, &asic3_irq_chip);
|
2008-02-07 08:14:49 +00:00
|
|
|
|
2011-03-25 11:12:32 +00:00
|
|
|
irq_set_chip_data(irq, asic);
|
|
|
|
irq_set_handler(irq, handle_level_irq);
|
2015-07-27 20:55:20 +00:00
|
|
|
irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE);
|
2008-02-07 08:14:49 +00:00
|
|
|
}
|
|
|
|
|
2008-06-20 09:12:21 +00:00
|
|
|
asic3_write_register(asic, ASIC3_OFFSET(INTR, INT_MASK),
|
2008-02-07 08:14:49 +00:00
|
|
|
ASIC3_INTMASK_GINTMASK);
|
|
|
|
|
mfd/asic3: Fix race in installing chained IRQ handler
Fix a race where a pending interrupt could be received and the handler
called before the handler's data has been setup, by converting to
irq_set_chained_handler_and_data().
Search and conversion was done with coccinelle:
@@
expression E1, E2, E3;
@@
(
-if (irq_set_chained_handler(E1, E3) != 0)
- BUG();
|
-irq_set_chained_handler(E1, E3);
)
-irq_set_handler_data(E1, E2);
+irq_set_chained_handler_and_data(E1, E3, E2);
@@
expression E1, E2, E3;
@@
(
-if (irq_set_chained_handler(E1, E3) != 0)
- BUG();
...
|
-irq_set_chained_handler(E1, E3);
...
)
-irq_set_handler_data(E1, E2);
+irq_set_chained_handler_and_data(E1, E3, E2);
Reported-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Julia Lawall <Julia.Lawall@lip6.fr>
Cc: Samuel Ortiz <sameo@linux.intel.com>
Cc: Lee Jones <lee.jones@linaro.org>
2015-06-21 18:16:06 +00:00
|
|
|
irq_set_chained_handler_and_data(asic->irq_nr, asic3_irq_demux, asic);
|
2011-03-25 11:12:32 +00:00
|
|
|
irq_set_irq_type(asic->irq_nr, IRQ_TYPE_EDGE_RISING);
|
2008-02-07 08:14:49 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void asic3_irq_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct asic3 *asic = platform_get_drvdata(pdev);
|
|
|
|
unsigned int irq, irq_base;
|
|
|
|
|
|
|
|
irq_base = asic->irq_base;
|
|
|
|
|
|
|
|
for (irq = irq_base; irq < irq_base + ASIC3_NR_IRQS; irq++) {
|
2015-07-27 20:55:20 +00:00
|
|
|
irq_set_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE);
|
2011-03-25 11:12:35 +00:00
|
|
|
irq_set_chip_and_handler(irq, NULL, NULL);
|
2011-03-25 11:12:32 +00:00
|
|
|
irq_set_chip_data(irq, NULL);
|
2008-02-07 08:14:49 +00:00
|
|
|
}
|
2011-03-25 11:12:32 +00:00
|
|
|
irq_set_chained_handler(asic->irq_nr, NULL);
|
2008-02-07 08:14:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* GPIOs */
|
2008-06-20 09:02:19 +00:00
|
|
|
static int asic3_gpio_direction(struct gpio_chip *chip,
|
|
|
|
unsigned offset, int out)
|
|
|
|
{
|
|
|
|
u32 mask = ASIC3_GPIO_TO_MASK(offset), out_reg;
|
|
|
|
unsigned int gpio_base;
|
|
|
|
unsigned long flags;
|
|
|
|
struct asic3 *asic;
|
|
|
|
|
2016-03-30 08:48:01 +00:00
|
|
|
asic = gpiochip_get_data(chip);
|
2008-06-20 09:02:19 +00:00
|
|
|
gpio_base = ASIC3_GPIO_TO_BASE(offset);
|
|
|
|
|
2008-06-20 09:12:21 +00:00
|
|
|
if (gpio_base > ASIC3_GPIO_D_BASE) {
|
2008-06-20 09:11:19 +00:00
|
|
|
dev_err(asic->dev, "Invalid base (0x%x) for gpio %d\n",
|
|
|
|
gpio_base, offset);
|
2008-06-20 09:02:19 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-03-21 22:43:04 +00:00
|
|
|
raw_spin_lock_irqsave(&asic->lock, flags);
|
2008-06-20 09:02:19 +00:00
|
|
|
|
2008-06-20 09:12:21 +00:00
|
|
|
out_reg = asic3_read_register(asic, gpio_base + ASIC3_GPIO_DIRECTION);
|
2008-06-20 09:02:19 +00:00
|
|
|
|
|
|
|
/* Input is 0, Output is 1 */
|
|
|
|
if (out)
|
|
|
|
out_reg |= mask;
|
|
|
|
else
|
|
|
|
out_reg &= ~mask;
|
|
|
|
|
2008-06-20 09:12:21 +00:00
|
|
|
asic3_write_register(asic, gpio_base + ASIC3_GPIO_DIRECTION, out_reg);
|
2008-06-20 09:02:19 +00:00
|
|
|
|
2017-03-21 22:43:04 +00:00
|
|
|
raw_spin_unlock_irqrestore(&asic->lock, flags);
|
2008-06-20 09:02:19 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int asic3_gpio_direction_input(struct gpio_chip *chip,
|
|
|
|
unsigned offset)
|
|
|
|
{
|
|
|
|
return asic3_gpio_direction(chip, offset, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int asic3_gpio_direction_output(struct gpio_chip *chip,
|
|
|
|
unsigned offset, int value)
|
|
|
|
{
|
|
|
|
return asic3_gpio_direction(chip, offset, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int asic3_gpio_get(struct gpio_chip *chip,
|
|
|
|
unsigned offset)
|
|
|
|
{
|
|
|
|
unsigned int gpio_base;
|
|
|
|
u32 mask = ASIC3_GPIO_TO_MASK(offset);
|
|
|
|
struct asic3 *asic;
|
|
|
|
|
2016-03-30 08:48:01 +00:00
|
|
|
asic = gpiochip_get_data(chip);
|
2008-06-20 09:02:19 +00:00
|
|
|
gpio_base = ASIC3_GPIO_TO_BASE(offset);
|
|
|
|
|
2008-06-20 09:12:21 +00:00
|
|
|
if (gpio_base > ASIC3_GPIO_D_BASE) {
|
2008-06-20 09:11:19 +00:00
|
|
|
dev_err(asic->dev, "Invalid base (0x%x) for gpio %d\n",
|
|
|
|
gpio_base, offset);
|
2008-06-20 09:02:19 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2015-12-22 14:47:05 +00:00
|
|
|
return !!(asic3_read_register(asic,
|
|
|
|
gpio_base + ASIC3_GPIO_STATUS) & mask);
|
2008-06-20 09:02:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void asic3_gpio_set(struct gpio_chip *chip,
|
|
|
|
unsigned offset, int value)
|
|
|
|
{
|
|
|
|
u32 mask, out_reg;
|
|
|
|
unsigned int gpio_base;
|
|
|
|
unsigned long flags;
|
|
|
|
struct asic3 *asic;
|
|
|
|
|
2016-03-30 08:48:01 +00:00
|
|
|
asic = gpiochip_get_data(chip);
|
2008-06-20 09:02:19 +00:00
|
|
|
gpio_base = ASIC3_GPIO_TO_BASE(offset);
|
|
|
|
|
2008-06-20 09:12:21 +00:00
|
|
|
if (gpio_base > ASIC3_GPIO_D_BASE) {
|
2008-06-20 09:11:19 +00:00
|
|
|
dev_err(asic->dev, "Invalid base (0x%x) for gpio %d\n",
|
|
|
|
gpio_base, offset);
|
2008-06-20 09:02:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mask = ASIC3_GPIO_TO_MASK(offset);
|
|
|
|
|
2017-03-21 22:43:04 +00:00
|
|
|
raw_spin_lock_irqsave(&asic->lock, flags);
|
2008-06-20 09:02:19 +00:00
|
|
|
|
2008-06-20 09:12:21 +00:00
|
|
|
out_reg = asic3_read_register(asic, gpio_base + ASIC3_GPIO_OUT);
|
2008-06-20 09:02:19 +00:00
|
|
|
|
|
|
|
if (value)
|
|
|
|
out_reg |= mask;
|
|
|
|
else
|
|
|
|
out_reg &= ~mask;
|
|
|
|
|
2008-06-20 09:12:21 +00:00
|
|
|
asic3_write_register(asic, gpio_base + ASIC3_GPIO_OUT, out_reg);
|
2008-06-20 09:02:19 +00:00
|
|
|
|
2017-03-21 22:43:04 +00:00
|
|
|
raw_spin_unlock_irqrestore(&asic->lock, flags);
|
2008-06-20 09:02:19 +00:00
|
|
|
}
|
|
|
|
|
2012-01-31 01:18:35 +00:00
|
|
|
static int asic3_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
|
|
|
|
{
|
2016-03-30 08:48:01 +00:00
|
|
|
struct asic3 *asic = gpiochip_get_data(chip);
|
2012-04-12 11:33:34 +00:00
|
|
|
|
2012-04-16 19:28:29 +00:00
|
|
|
return asic->irq_base + offset;
|
2012-01-31 01:18:35 +00:00
|
|
|
}
|
|
|
|
|
2008-06-20 22:51:38 +00:00
|
|
|
static __init int asic3_gpio_probe(struct platform_device *pdev,
|
|
|
|
u16 *gpio_config, int num)
|
2008-02-07 08:14:49 +00:00
|
|
|
{
|
|
|
|
struct asic3 *asic = platform_get_drvdata(pdev);
|
2008-06-20 09:09:51 +00:00
|
|
|
u16 alt_reg[ASIC3_NUM_GPIO_BANKS];
|
|
|
|
u16 out_reg[ASIC3_NUM_GPIO_BANKS];
|
|
|
|
u16 dir_reg[ASIC3_NUM_GPIO_BANKS];
|
|
|
|
int i;
|
2008-02-07 08:14:49 +00:00
|
|
|
|
2008-10-27 11:24:09 +00:00
|
|
|
memset(alt_reg, 0, ASIC3_NUM_GPIO_BANKS * sizeof(u16));
|
|
|
|
memset(out_reg, 0, ASIC3_NUM_GPIO_BANKS * sizeof(u16));
|
|
|
|
memset(dir_reg, 0, ASIC3_NUM_GPIO_BANKS * sizeof(u16));
|
2008-06-20 09:09:51 +00:00
|
|
|
|
|
|
|
/* Enable all GPIOs */
|
2008-06-20 09:12:21 +00:00
|
|
|
asic3_write_register(asic, ASIC3_GPIO_OFFSET(A, MASK), 0xffff);
|
|
|
|
asic3_write_register(asic, ASIC3_GPIO_OFFSET(B, MASK), 0xffff);
|
|
|
|
asic3_write_register(asic, ASIC3_GPIO_OFFSET(C, MASK), 0xffff);
|
|
|
|
asic3_write_register(asic, ASIC3_GPIO_OFFSET(D, MASK), 0xffff);
|
2008-02-07 08:14:49 +00:00
|
|
|
|
2008-06-20 09:09:51 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
u8 alt, pin, dir, init, bank_num, bit_num;
|
|
|
|
u16 config = gpio_config[i];
|
|
|
|
|
|
|
|
pin = ASIC3_CONFIG_GPIO_PIN(config);
|
|
|
|
alt = ASIC3_CONFIG_GPIO_ALT(config);
|
|
|
|
dir = ASIC3_CONFIG_GPIO_DIR(config);
|
|
|
|
init = ASIC3_CONFIG_GPIO_INIT(config);
|
|
|
|
|
|
|
|
bank_num = ASIC3_GPIO_TO_BANK(pin);
|
|
|
|
bit_num = ASIC3_GPIO_TO_BIT(pin);
|
|
|
|
|
|
|
|
alt_reg[bank_num] |= (alt << bit_num);
|
|
|
|
out_reg[bank_num] |= (init << bit_num);
|
|
|
|
dir_reg[bank_num] |= (dir << bit_num);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ASIC3_NUM_GPIO_BANKS; i++) {
|
|
|
|
asic3_write_register(asic,
|
|
|
|
ASIC3_BANK_TO_BASE(i) +
|
2008-06-20 09:12:21 +00:00
|
|
|
ASIC3_GPIO_DIRECTION,
|
2008-06-20 09:09:51 +00:00
|
|
|
dir_reg[i]);
|
|
|
|
asic3_write_register(asic,
|
2008-06-20 09:12:21 +00:00
|
|
|
ASIC3_BANK_TO_BASE(i) + ASIC3_GPIO_OUT,
|
2008-06-20 09:09:51 +00:00
|
|
|
out_reg[i]);
|
|
|
|
asic3_write_register(asic,
|
|
|
|
ASIC3_BANK_TO_BASE(i) +
|
2008-06-20 09:12:21 +00:00
|
|
|
ASIC3_GPIO_ALT_FUNCTION,
|
2008-06-20 09:09:51 +00:00
|
|
|
alt_reg[i]);
|
2008-02-07 08:14:49 +00:00
|
|
|
}
|
|
|
|
|
2016-03-30 08:48:01 +00:00
|
|
|
return gpiochip_add_data(&asic->gpio, asic);
|
2008-02-07 08:14:49 +00:00
|
|
|
}
|
|
|
|
|
2008-06-20 09:02:19 +00:00
|
|
|
static int asic3_gpio_remove(struct platform_device *pdev)
|
2008-02-07 08:14:49 +00:00
|
|
|
{
|
2008-06-20 09:02:19 +00:00
|
|
|
struct asic3 *asic = platform_get_drvdata(pdev);
|
|
|
|
|
2014-07-12 20:30:14 +00:00
|
|
|
gpiochip_remove(&asic->gpio);
|
|
|
|
return 0;
|
2008-02-07 08:14:49 +00:00
|
|
|
}
|
|
|
|
|
2011-08-09 16:27:43 +00:00
|
|
|
static void asic3_clk_enable(struct asic3 *asic, struct asic3_clk *clk)
|
2009-06-05 16:31:02 +00:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
u32 cdex;
|
|
|
|
|
2017-03-21 22:43:04 +00:00
|
|
|
raw_spin_lock_irqsave(&asic->lock, flags);
|
2009-06-05 16:31:02 +00:00
|
|
|
if (clk->enabled++ == 0) {
|
|
|
|
cdex = asic3_read_register(asic, ASIC3_OFFSET(CLOCK, CDEX));
|
|
|
|
cdex |= clk->cdex;
|
|
|
|
asic3_write_register(asic, ASIC3_OFFSET(CLOCK, CDEX), cdex);
|
|
|
|
}
|
2017-03-21 22:43:04 +00:00
|
|
|
raw_spin_unlock_irqrestore(&asic->lock, flags);
|
2009-06-05 16:31:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void asic3_clk_disable(struct asic3 *asic, struct asic3_clk *clk)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
u32 cdex;
|
|
|
|
|
|
|
|
WARN_ON(clk->enabled == 0);
|
|
|
|
|
2017-03-21 22:43:04 +00:00
|
|
|
raw_spin_lock_irqsave(&asic->lock, flags);
|
2009-06-05 16:31:02 +00:00
|
|
|
if (--clk->enabled == 0) {
|
|
|
|
cdex = asic3_read_register(asic, ASIC3_OFFSET(CLOCK, CDEX));
|
|
|
|
cdex &= ~clk->cdex;
|
|
|
|
asic3_write_register(asic, ASIC3_OFFSET(CLOCK, CDEX), cdex);
|
|
|
|
}
|
2017-03-21 22:43:04 +00:00
|
|
|
raw_spin_unlock_irqrestore(&asic->lock, flags);
|
2009-06-05 16:31:02 +00:00
|
|
|
}
|
2008-02-07 08:14:49 +00:00
|
|
|
|
2009-06-15 10:10:24 +00:00
|
|
|
/* MFD cells (SPI, PWM, LED, DS1WM, MMC) */
|
|
|
|
static struct ds1wm_driver_data ds1wm_pdata = {
|
|
|
|
.active_high = 1,
|
w1: ds1wm: add a reset recovery parameter
This fixes a regression in 3.0 reported by Paul Parsons regarding the
removal of the msleep(1) in the ds1wm_reset() function:
: The linux-3.0-rc4 DS1WM 1-wire driver is logging "bus error, retrying"
: error messages on an HP iPAQ hx4700 PDA (XScale-PXA270):
:
: <snip>
: Driver for 1-wire Dallas network protocol.
: DS1WM w1 busmaster driver - (c) 2004 Szabolcs Gyurko
: 1-Wire driver for the DS2760 battery monitor chip - (c) 2004-2005, Szabolcs Gyurko
: ds1wm ds1wm: pass: 1 bus error, retrying
: ds1wm ds1wm: pass: 2 bus error, retrying
: ds1wm ds1wm: pass: 3 bus error, retrying
: ds1wm ds1wm: pass: 4 bus error, retrying
: ds1wm ds1wm: pass: 5 bus error, retrying
: ...
:
: The visible result is that the battery charging LED is erratic; sometimes
: it works, mostly it doesn't.
:
: The linux-2.6.39 DS1WM 1-wire driver worked OK. I haven't tried 3.0-rc1,
: 3.0-rc2, or 3.0-rc3.
This sleep should not be required on normal circuitry provided the
pull-ups on the bus are correctly adapted to the slaves. Unfortunately,
this is not always the case. The sleep is restored but as a parameter to
the probe function in the pdata.
[akpm@linux-foundation.org: coding-style fixes]
Reported-by: Paul Parsons <lost.distance@yahoo.com>
Tested-by: Paul Parsons <lost.distance@yahoo.com>
Signed-off-by: Jean-François Dagenais <dagenaisj@sonatest.com>
Cc: Evgeniy Polyakov <johnpol@2ka.mipt.ru>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-07-08 22:39:44 +00:00
|
|
|
.reset_recover_delay = 1,
|
2009-06-15 10:10:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct resource ds1wm_resources[] = {
|
|
|
|
{
|
|
|
|
.start = ASIC3_OWM_BASE,
|
|
|
|
.end = ASIC3_OWM_BASE + 0x13,
|
|
|
|
.flags = IORESOURCE_MEM,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.start = ASIC3_IRQ_OWM,
|
2010-12-11 13:00:34 +00:00
|
|
|
.end = ASIC3_IRQ_OWM,
|
2009-06-15 10:10:24 +00:00
|
|
|
.flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int ds1wm_enable(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct asic3 *asic = dev_get_drvdata(pdev->dev.parent);
|
|
|
|
|
|
|
|
/* Turn on external clocks and the OWM clock */
|
|
|
|
asic3_clk_enable(asic, &asic->clocks[ASIC3_CLOCK_EX0]);
|
|
|
|
asic3_clk_enable(asic, &asic->clocks[ASIC3_CLOCK_EX1]);
|
|
|
|
asic3_clk_enable(asic, &asic->clocks[ASIC3_CLOCK_OWM]);
|
2015-10-28 14:11:23 +00:00
|
|
|
usleep_range(1000, 5000);
|
2009-06-15 10:10:24 +00:00
|
|
|
|
|
|
|
/* Reset and enable DS1WM */
|
|
|
|
asic3_set_register(asic, ASIC3_OFFSET(EXTCF, RESET),
|
|
|
|
ASIC3_EXTCF_OWM_RESET, 1);
|
2015-10-28 14:11:23 +00:00
|
|
|
usleep_range(1000, 5000);
|
2009-06-15 10:10:24 +00:00
|
|
|
asic3_set_register(asic, ASIC3_OFFSET(EXTCF, RESET),
|
|
|
|
ASIC3_EXTCF_OWM_RESET, 0);
|
2015-10-28 14:11:23 +00:00
|
|
|
usleep_range(1000, 5000);
|
2009-06-15 10:10:24 +00:00
|
|
|
asic3_set_register(asic, ASIC3_OFFSET(EXTCF, SELECT),
|
|
|
|
ASIC3_EXTCF_OWM_EN, 1);
|
2015-10-28 14:11:23 +00:00
|
|
|
usleep_range(1000, 5000);
|
2009-06-15 10:10:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ds1wm_disable(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct asic3 *asic = dev_get_drvdata(pdev->dev.parent);
|
|
|
|
|
|
|
|
asic3_set_register(asic, ASIC3_OFFSET(EXTCF, SELECT),
|
|
|
|
ASIC3_EXTCF_OWM_EN, 0);
|
|
|
|
|
|
|
|
asic3_clk_disable(asic, &asic->clocks[ASIC3_CLOCK_OWM]);
|
|
|
|
asic3_clk_disable(asic, &asic->clocks[ASIC3_CLOCK_EX0]);
|
|
|
|
asic3_clk_disable(asic, &asic->clocks[ASIC3_CLOCK_EX1]);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-18 13:33:06 +00:00
|
|
|
static const struct mfd_cell asic3_cell_ds1wm = {
|
2009-06-15 10:10:24 +00:00
|
|
|
.name = "ds1wm",
|
|
|
|
.enable = ds1wm_enable,
|
|
|
|
.disable = ds1wm_disable,
|
2011-04-06 09:41:03 +00:00
|
|
|
.platform_data = &ds1wm_pdata,
|
|
|
|
.pdata_size = sizeof(ds1wm_pdata),
|
2009-06-15 10:10:24 +00:00
|
|
|
.num_resources = ARRAY_SIZE(ds1wm_resources),
|
|
|
|
.resources = ds1wm_resources,
|
|
|
|
};
|
|
|
|
|
2010-01-06 12:51:48 +00:00
|
|
|
static void asic3_mmc_pwr(struct platform_device *pdev, int state)
|
|
|
|
{
|
|
|
|
struct asic3 *asic = dev_get_drvdata(pdev->dev.parent);
|
|
|
|
|
|
|
|
tmio_core_mmc_pwr(asic->tmio_cnf, 1 - asic->bus_shift, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void asic3_mmc_clk_div(struct platform_device *pdev, int state)
|
|
|
|
{
|
|
|
|
struct asic3 *asic = dev_get_drvdata(pdev->dev.parent);
|
|
|
|
|
|
|
|
tmio_core_mmc_clk_div(asic->tmio_cnf, 1 - asic->bus_shift, state);
|
|
|
|
}
|
|
|
|
|
2009-06-15 10:10:25 +00:00
|
|
|
static struct tmio_mmc_data asic3_mmc_data = {
|
2010-01-06 12:51:48 +00:00
|
|
|
.hclk = 24576000,
|
2018-05-26 09:31:50 +00:00
|
|
|
.ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
|
2010-01-06 12:51:48 +00:00
|
|
|
.set_pwr = asic3_mmc_pwr,
|
|
|
|
.set_clk_div = asic3_mmc_clk_div,
|
2009-06-15 10:10:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct resource asic3_mmc_resources[] = {
|
|
|
|
{
|
|
|
|
.start = ASIC3_SD_CTRL_BASE,
|
|
|
|
.end = ASIC3_SD_CTRL_BASE + 0x3ff,
|
|
|
|
.flags = IORESOURCE_MEM,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.start = 0,
|
|
|
|
.end = 0,
|
|
|
|
.flags = IORESOURCE_IRQ,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int asic3_mmc_enable(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct asic3 *asic = dev_get_drvdata(pdev->dev.parent);
|
|
|
|
|
|
|
|
/* Not sure if it must be done bit by bit, but leaving as-is */
|
|
|
|
asic3_set_register(asic, ASIC3_OFFSET(SDHWCTRL, SDCONF),
|
|
|
|
ASIC3_SDHWCTRL_LEVCD, 1);
|
|
|
|
asic3_set_register(asic, ASIC3_OFFSET(SDHWCTRL, SDCONF),
|
|
|
|
ASIC3_SDHWCTRL_LEVWP, 1);
|
|
|
|
asic3_set_register(asic, ASIC3_OFFSET(SDHWCTRL, SDCONF),
|
|
|
|
ASIC3_SDHWCTRL_SUSPEND, 0);
|
|
|
|
asic3_set_register(asic, ASIC3_OFFSET(SDHWCTRL, SDCONF),
|
|
|
|
ASIC3_SDHWCTRL_PCLR, 0);
|
|
|
|
|
|
|
|
asic3_clk_enable(asic, &asic->clocks[ASIC3_CLOCK_EX0]);
|
|
|
|
/* CLK32 used for card detection and for interruption detection
|
|
|
|
* when HCLK is stopped.
|
|
|
|
*/
|
|
|
|
asic3_clk_enable(asic, &asic->clocks[ASIC3_CLOCK_EX1]);
|
2015-10-28 14:11:23 +00:00
|
|
|
usleep_range(1000, 5000);
|
2009-06-15 10:10:25 +00:00
|
|
|
|
|
|
|
/* HCLK 24.576 MHz, BCLK 12.288 MHz: */
|
|
|
|
asic3_write_register(asic, ASIC3_OFFSET(CLOCK, SEL),
|
|
|
|
CLOCK_SEL_CX | CLOCK_SEL_SD_HCLK_SEL);
|
|
|
|
|
|
|
|
asic3_clk_enable(asic, &asic->clocks[ASIC3_CLOCK_SD_HOST]);
|
|
|
|
asic3_clk_enable(asic, &asic->clocks[ASIC3_CLOCK_SD_BUS]);
|
2015-10-28 14:11:23 +00:00
|
|
|
usleep_range(1000, 5000);
|
2009-06-15 10:10:25 +00:00
|
|
|
|
|
|
|
asic3_set_register(asic, ASIC3_OFFSET(EXTCF, SELECT),
|
|
|
|
ASIC3_EXTCF_SD_MEM_ENABLE, 1);
|
|
|
|
|
|
|
|
/* Enable SD card slot 3.3V power supply */
|
|
|
|
asic3_set_register(asic, ASIC3_OFFSET(SDHWCTRL, SDCONF),
|
|
|
|
ASIC3_SDHWCTRL_SDPWR, 1);
|
|
|
|
|
2010-01-06 12:51:48 +00:00
|
|
|
/* ASIC3_SD_CTRL_BASE assumes 32-bit addressing, TMIO is 16-bit */
|
|
|
|
tmio_core_mmc_enable(asic->tmio_cnf, 1 - asic->bus_shift,
|
|
|
|
ASIC3_SD_CTRL_BASE >> 1);
|
|
|
|
|
2009-06-15 10:10:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int asic3_mmc_disable(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct asic3 *asic = dev_get_drvdata(pdev->dev.parent);
|
|
|
|
|
|
|
|
/* Put in suspend mode */
|
|
|
|
asic3_set_register(asic, ASIC3_OFFSET(SDHWCTRL, SDCONF),
|
|
|
|
ASIC3_SDHWCTRL_SUSPEND, 1);
|
|
|
|
|
|
|
|
/* Disable clocks */
|
|
|
|
asic3_clk_disable(asic, &asic->clocks[ASIC3_CLOCK_SD_HOST]);
|
|
|
|
asic3_clk_disable(asic, &asic->clocks[ASIC3_CLOCK_SD_BUS]);
|
|
|
|
asic3_clk_disable(asic, &asic->clocks[ASIC3_CLOCK_EX0]);
|
|
|
|
asic3_clk_disable(asic, &asic->clocks[ASIC3_CLOCK_EX1]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-18 13:33:06 +00:00
|
|
|
static const struct mfd_cell asic3_cell_mmc = {
|
2009-06-15 10:10:25 +00:00
|
|
|
.name = "tmio-mmc",
|
|
|
|
.enable = asic3_mmc_enable,
|
|
|
|
.disable = asic3_mmc_disable,
|
2011-08-09 16:27:24 +00:00
|
|
|
.suspend = asic3_mmc_disable,
|
|
|
|
.resume = asic3_mmc_enable,
|
2011-04-06 09:38:14 +00:00
|
|
|
.platform_data = &asic3_mmc_data,
|
|
|
|
.pdata_size = sizeof(asic3_mmc_data),
|
2009-06-15 10:10:25 +00:00
|
|
|
.num_resources = ARRAY_SIZE(asic3_mmc_resources),
|
|
|
|
.resources = asic3_mmc_resources,
|
|
|
|
};
|
|
|
|
|
2011-05-13 18:53:03 +00:00
|
|
|
static const int clock_ledn[ASIC3_NUM_LEDS] = {
|
|
|
|
[0] = ASIC3_CLOCK_LED0,
|
|
|
|
[1] = ASIC3_CLOCK_LED1,
|
|
|
|
[2] = ASIC3_CLOCK_LED2,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int asic3_leds_enable(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
const struct mfd_cell *cell = mfd_get_cell(pdev);
|
|
|
|
struct asic3 *asic = dev_get_drvdata(pdev->dev.parent);
|
|
|
|
|
|
|
|
asic3_clk_enable(asic, &asic->clocks[clock_ledn[cell->id]]);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int asic3_leds_disable(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
const struct mfd_cell *cell = mfd_get_cell(pdev);
|
|
|
|
struct asic3 *asic = dev_get_drvdata(pdev->dev.parent);
|
|
|
|
|
|
|
|
asic3_clk_disable(asic, &asic->clocks[clock_ledn[cell->id]]);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-09 16:27:33 +00:00
|
|
|
static int asic3_leds_suspend(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
const struct mfd_cell *cell = mfd_get_cell(pdev);
|
|
|
|
struct asic3 *asic = dev_get_drvdata(pdev->dev.parent);
|
|
|
|
|
|
|
|
while (asic3_gpio_get(&asic->gpio, ASIC3_GPIO(C, cell->id)) != 0)
|
2015-10-28 14:11:23 +00:00
|
|
|
usleep_range(1000, 5000);
|
2011-08-09 16:27:33 +00:00
|
|
|
|
|
|
|
asic3_clk_disable(asic, &asic->clocks[clock_ledn[cell->id]]);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-13 18:53:03 +00:00
|
|
|
static struct mfd_cell asic3_cell_leds[ASIC3_NUM_LEDS] = {
|
|
|
|
[0] = {
|
|
|
|
.name = "leds-asic3",
|
|
|
|
.id = 0,
|
|
|
|
.enable = asic3_leds_enable,
|
|
|
|
.disable = asic3_leds_disable,
|
2011-08-09 16:27:33 +00:00
|
|
|
.suspend = asic3_leds_suspend,
|
|
|
|
.resume = asic3_leds_enable,
|
2011-05-13 18:53:03 +00:00
|
|
|
},
|
|
|
|
[1] = {
|
|
|
|
.name = "leds-asic3",
|
|
|
|
.id = 1,
|
|
|
|
.enable = asic3_leds_enable,
|
|
|
|
.disable = asic3_leds_disable,
|
2011-08-09 16:27:33 +00:00
|
|
|
.suspend = asic3_leds_suspend,
|
|
|
|
.resume = asic3_leds_enable,
|
2011-05-13 18:53:03 +00:00
|
|
|
},
|
|
|
|
[2] = {
|
|
|
|
.name = "leds-asic3",
|
|
|
|
.id = 2,
|
|
|
|
.enable = asic3_leds_enable,
|
|
|
|
.disable = asic3_leds_disable,
|
2011-08-09 16:27:33 +00:00
|
|
|
.suspend = asic3_leds_suspend,
|
|
|
|
.resume = asic3_leds_enable,
|
2011-05-13 18:53:03 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2009-06-15 10:10:24 +00:00
|
|
|
static int __init asic3_mfd_probe(struct platform_device *pdev,
|
2011-05-13 18:53:03 +00:00
|
|
|
struct asic3_platform_data *pdata,
|
2009-06-15 10:10:24 +00:00
|
|
|
struct resource *mem)
|
|
|
|
{
|
|
|
|
struct asic3 *asic = platform_get_drvdata(pdev);
|
2009-06-15 10:10:25 +00:00
|
|
|
struct resource *mem_sdio;
|
|
|
|
int irq, ret;
|
|
|
|
|
|
|
|
mem_sdio = platform_get_resource(pdev, IORESOURCE_MEM, 1);
|
|
|
|
if (!mem_sdio)
|
|
|
|
dev_dbg(asic->dev, "no SDIO MEM resource\n");
|
|
|
|
|
|
|
|
irq = platform_get_irq(pdev, 1);
|
|
|
|
if (irq < 0)
|
|
|
|
dev_dbg(asic->dev, "no SDIO IRQ resource\n");
|
2009-06-15 10:10:24 +00:00
|
|
|
|
|
|
|
/* DS1WM */
|
|
|
|
asic3_set_register(asic, ASIC3_OFFSET(EXTCF, SELECT),
|
|
|
|
ASIC3_EXTCF_OWM_SMB, 0);
|
|
|
|
|
|
|
|
ds1wm_resources[0].start >>= asic->bus_shift;
|
|
|
|
ds1wm_resources[0].end >>= asic->bus_shift;
|
|
|
|
|
2009-06-15 10:10:25 +00:00
|
|
|
/* MMC */
|
2014-06-10 10:00:34 +00:00
|
|
|
if (mem_sdio) {
|
2015-10-28 14:11:23 +00:00
|
|
|
asic->tmio_cnf = ioremap((ASIC3_SD_CONFIG_BASE >>
|
|
|
|
asic->bus_shift) + mem_sdio->start,
|
2011-05-15 14:13:11 +00:00
|
|
|
ASIC3_SD_CONFIG_SIZE >> asic->bus_shift);
|
2014-06-10 10:00:34 +00:00
|
|
|
if (!asic->tmio_cnf) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
dev_dbg(asic->dev, "Couldn't ioremap SD_CONFIG\n");
|
|
|
|
goto out;
|
|
|
|
}
|
2010-01-06 12:51:48 +00:00
|
|
|
}
|
2009-06-15 10:10:25 +00:00
|
|
|
asic3_mmc_resources[0].start >>= asic->bus_shift;
|
|
|
|
asic3_mmc_resources[0].end >>= asic->bus_shift;
|
|
|
|
|
2012-04-09 12:18:31 +00:00
|
|
|
if (pdata->clock_rate) {
|
|
|
|
ds1wm_pdata.clock_rate = pdata->clock_rate;
|
|
|
|
ret = mfd_add_devices(&pdev->dev, pdev->id,
|
2012-09-11 07:16:36 +00:00
|
|
|
&asic3_cell_ds1wm, 1, mem, asic->irq_base, NULL);
|
2012-04-09 12:18:31 +00:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
}
|
2009-06-15 10:10:25 +00:00
|
|
|
|
2011-05-13 18:53:03 +00:00
|
|
|
if (mem_sdio && (irq >= 0)) {
|
2009-06-15 10:10:25 +00:00
|
|
|
ret = mfd_add_devices(&pdev->dev, pdev->id,
|
2012-09-11 07:16:36 +00:00
|
|
|
&asic3_cell_mmc, 1, mem_sdio, irq, NULL);
|
2011-05-13 18:53:03 +00:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2012-08-04 06:20:49 +00:00
|
|
|
ret = 0;
|
2011-05-13 18:53:03 +00:00
|
|
|
if (pdata->leds) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ASIC3_NUM_LEDS; ++i) {
|
|
|
|
asic3_cell_leds[i].platform_data = &pdata->leds[i];
|
|
|
|
asic3_cell_leds[i].pdata_size = sizeof(pdata->leds[i]);
|
|
|
|
}
|
|
|
|
ret = mfd_add_devices(&pdev->dev, 0,
|
2012-09-11 07:16:36 +00:00
|
|
|
asic3_cell_leds, ASIC3_NUM_LEDS, NULL, 0, NULL);
|
2011-05-13 18:53:03 +00:00
|
|
|
}
|
2009-06-15 10:10:24 +00:00
|
|
|
|
2009-06-15 10:10:25 +00:00
|
|
|
out:
|
2009-06-15 10:10:24 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void asic3_mfd_remove(struct platform_device *pdev)
|
|
|
|
{
|
2010-01-06 12:51:48 +00:00
|
|
|
struct asic3 *asic = platform_get_drvdata(pdev);
|
|
|
|
|
2009-06-15 10:10:24 +00:00
|
|
|
mfd_remove_devices(&pdev->dev);
|
2010-01-06 12:51:48 +00:00
|
|
|
iounmap(asic->tmio_cnf);
|
2009-06-15 10:10:24 +00:00
|
|
|
}
|
|
|
|
|
2008-02-07 08:14:49 +00:00
|
|
|
/* Core */
|
2008-06-20 22:51:38 +00:00
|
|
|
static int __init asic3_probe(struct platform_device *pdev)
|
2008-02-07 08:14:49 +00:00
|
|
|
{
|
2013-07-30 08:10:05 +00:00
|
|
|
struct asic3_platform_data *pdata = dev_get_platdata(&pdev->dev);
|
2008-02-07 08:14:49 +00:00
|
|
|
struct asic3 *asic;
|
|
|
|
struct resource *mem;
|
|
|
|
unsigned long clksel;
|
2008-06-20 09:02:19 +00:00
|
|
|
int ret = 0;
|
2008-02-07 08:14:49 +00:00
|
|
|
|
2013-05-23 15:25:09 +00:00
|
|
|
asic = devm_kzalloc(&pdev->dev,
|
|
|
|
sizeof(struct asic3), GFP_KERNEL);
|
2015-10-28 14:11:23 +00:00
|
|
|
if (!asic)
|
2008-02-07 08:14:49 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2017-03-21 22:43:04 +00:00
|
|
|
raw_spin_lock_init(&asic->lock);
|
2008-02-07 08:14:49 +00:00
|
|
|
platform_set_drvdata(pdev, asic);
|
|
|
|
asic->dev = &pdev->dev;
|
|
|
|
|
|
|
|
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (!mem) {
|
2008-06-20 09:11:19 +00:00
|
|
|
dev_err(asic->dev, "no MEM resource\n");
|
2013-05-23 15:25:09 +00:00
|
|
|
return -ENOMEM;
|
2008-02-07 08:14:49 +00:00
|
|
|
}
|
|
|
|
|
2009-06-05 16:31:04 +00:00
|
|
|
asic->mapping = ioremap(mem->start, resource_size(mem));
|
2008-02-07 08:14:49 +00:00
|
|
|
if (!asic->mapping) {
|
2008-06-20 09:11:19 +00:00
|
|
|
dev_err(asic->dev, "Couldn't ioremap\n");
|
2013-05-23 15:25:09 +00:00
|
|
|
return -ENOMEM;
|
2008-02-07 08:14:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
asic->irq_base = pdata->irq_base;
|
|
|
|
|
2008-07-10 00:17:02 +00:00
|
|
|
/* calculate bus shift from mem resource */
|
2009-06-05 16:31:04 +00:00
|
|
|
asic->bus_shift = 2 - (resource_size(mem) >> 12);
|
2008-02-07 08:14:49 +00:00
|
|
|
|
|
|
|
clksel = 0;
|
|
|
|
asic3_write_register(asic, ASIC3_OFFSET(CLOCK, SEL), clksel);
|
|
|
|
|
|
|
|
ret = asic3_irq_probe(pdev);
|
|
|
|
if (ret < 0) {
|
2008-06-20 09:11:19 +00:00
|
|
|
dev_err(asic->dev, "Couldn't probe IRQs\n");
|
2008-06-20 09:02:19 +00:00
|
|
|
goto out_unmap;
|
|
|
|
}
|
|
|
|
|
2011-08-09 16:27:50 +00:00
|
|
|
asic->gpio.label = "asic3";
|
2008-06-20 09:02:19 +00:00
|
|
|
asic->gpio.base = pdata->gpio_base;
|
|
|
|
asic->gpio.ngpio = ASIC3_NUM_GPIOS;
|
|
|
|
asic->gpio.get = asic3_gpio_get;
|
|
|
|
asic->gpio.set = asic3_gpio_set;
|
|
|
|
asic->gpio.direction_input = asic3_gpio_direction_input;
|
|
|
|
asic->gpio.direction_output = asic3_gpio_direction_output;
|
2012-01-31 01:18:35 +00:00
|
|
|
asic->gpio.to_irq = asic3_gpio_to_irq;
|
2008-06-20 09:02:19 +00:00
|
|
|
|
2008-06-20 09:09:51 +00:00
|
|
|
ret = asic3_gpio_probe(pdev,
|
|
|
|
pdata->gpio_config,
|
|
|
|
pdata->gpio_config_num);
|
2008-06-20 09:02:19 +00:00
|
|
|
if (ret < 0) {
|
2008-06-20 09:11:19 +00:00
|
|
|
dev_err(asic->dev, "GPIO probe failed\n");
|
2008-06-20 09:02:19 +00:00
|
|
|
goto out_irq;
|
2008-02-07 08:14:49 +00:00
|
|
|
}
|
|
|
|
|
2009-06-05 16:31:02 +00:00
|
|
|
/* Making a per-device copy is only needed for the
|
|
|
|
* theoretical case of multiple ASIC3s on one board:
|
|
|
|
*/
|
|
|
|
memcpy(asic->clocks, asic3_clk_init, sizeof(asic3_clk_init));
|
|
|
|
|
2011-05-13 18:53:03 +00:00
|
|
|
asic3_mfd_probe(pdev, pdata, mem);
|
2009-06-15 10:10:24 +00:00
|
|
|
|
2012-04-05 16:45:04 +00:00
|
|
|
asic3_set_register(asic, ASIC3_OFFSET(EXTCF, SELECT),
|
|
|
|
(ASIC3_EXTCF_CF0_BUF_EN|ASIC3_EXTCF_CF0_PWAIT_EN), 1);
|
|
|
|
|
2008-06-20 09:11:19 +00:00
|
|
|
dev_info(asic->dev, "ASIC3 Core driver\n");
|
2008-02-07 08:14:49 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2008-06-20 09:02:19 +00:00
|
|
|
out_irq:
|
|
|
|
asic3_irq_remove(pdev);
|
|
|
|
|
|
|
|
out_unmap:
|
2008-02-07 08:14:49 +00:00
|
|
|
iounmap(asic->mapping);
|
2008-06-20 09:02:19 +00:00
|
|
|
|
2008-02-07 08:14:49 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-19 18:26:01 +00:00
|
|
|
static int asic3_remove(struct platform_device *pdev)
|
2008-02-07 08:14:49 +00:00
|
|
|
{
|
2008-06-20 09:02:19 +00:00
|
|
|
int ret;
|
2008-02-07 08:14:49 +00:00
|
|
|
struct asic3 *asic = platform_get_drvdata(pdev);
|
|
|
|
|
2012-04-05 16:45:04 +00:00
|
|
|
asic3_set_register(asic, ASIC3_OFFSET(EXTCF, SELECT),
|
|
|
|
(ASIC3_EXTCF_CF0_BUF_EN|ASIC3_EXTCF_CF0_PWAIT_EN), 0);
|
|
|
|
|
2009-06-15 10:10:24 +00:00
|
|
|
asic3_mfd_remove(pdev);
|
|
|
|
|
2008-06-20 09:02:19 +00:00
|
|
|
ret = asic3_gpio_remove(pdev);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2008-02-07 08:14:49 +00:00
|
|
|
asic3_irq_remove(pdev);
|
|
|
|
|
|
|
|
asic3_write_register(asic, ASIC3_OFFSET(CLOCK, SEL), 0);
|
|
|
|
|
|
|
|
iounmap(asic->mapping);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void asic3_shutdown(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver asic3_device_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "asic3",
|
|
|
|
},
|
2012-11-19 18:20:24 +00:00
|
|
|
.remove = asic3_remove,
|
2008-02-07 08:14:49 +00:00
|
|
|
.shutdown = asic3_shutdown,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init asic3_init(void)
|
|
|
|
{
|
|
|
|
int retval = 0;
|
2015-10-28 14:11:23 +00:00
|
|
|
|
2008-06-20 22:51:38 +00:00
|
|
|
retval = platform_driver_probe(&asic3_device_driver, asic3_probe);
|
2015-10-28 14:11:23 +00:00
|
|
|
|
2008-02-07 08:14:49 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
subsys_initcall(asic3_init);
|