2008-10-15 10:20:06 +00:00
|
|
|
/*
|
|
|
|
* Base driver for Dialog Semiconductor DA9030/DA9034
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Compulab, Ltd.
|
|
|
|
* Mike Rapoport <mike@compulab.co.il>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006-2008 Marvell International Ltd.
|
|
|
|
* Eric Miao <eric.miao@marvell.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/mfd/da903x.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-10-15 10:20:06 +00:00
|
|
|
|
|
|
|
#define DA9030_CHIP_ID 0x00
|
|
|
|
#define DA9030_EVENT_A 0x01
|
|
|
|
#define DA9030_EVENT_B 0x02
|
|
|
|
#define DA9030_EVENT_C 0x03
|
|
|
|
#define DA9030_STATUS 0x04
|
|
|
|
#define DA9030_IRQ_MASK_A 0x05
|
|
|
|
#define DA9030_IRQ_MASK_B 0x06
|
|
|
|
#define DA9030_IRQ_MASK_C 0x07
|
|
|
|
#define DA9030_SYS_CTRL_A 0x08
|
|
|
|
#define DA9030_SYS_CTRL_B 0x09
|
|
|
|
#define DA9030_FAULT_LOG 0x0a
|
|
|
|
|
|
|
|
#define DA9034_CHIP_ID 0x00
|
|
|
|
#define DA9034_EVENT_A 0x01
|
|
|
|
#define DA9034_EVENT_B 0x02
|
|
|
|
#define DA9034_EVENT_C 0x03
|
|
|
|
#define DA9034_EVENT_D 0x04
|
|
|
|
#define DA9034_STATUS_A 0x05
|
|
|
|
#define DA9034_STATUS_B 0x06
|
|
|
|
#define DA9034_IRQ_MASK_A 0x07
|
|
|
|
#define DA9034_IRQ_MASK_B 0x08
|
|
|
|
#define DA9034_IRQ_MASK_C 0x09
|
|
|
|
#define DA9034_IRQ_MASK_D 0x0a
|
|
|
|
#define DA9034_SYS_CTRL_A 0x0b
|
|
|
|
#define DA9034_SYS_CTRL_B 0x0c
|
|
|
|
#define DA9034_FAULT_LOG 0x0d
|
|
|
|
|
|
|
|
struct da903x_chip;
|
|
|
|
|
|
|
|
struct da903x_chip_ops {
|
|
|
|
int (*init_chip)(struct da903x_chip *);
|
|
|
|
int (*unmask_events)(struct da903x_chip *, unsigned int events);
|
|
|
|
int (*mask_events)(struct da903x_chip *, unsigned int events);
|
|
|
|
int (*read_events)(struct da903x_chip *, unsigned int *events);
|
|
|
|
int (*read_status)(struct da903x_chip *, unsigned int *status);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct da903x_chip {
|
|
|
|
struct i2c_client *client;
|
|
|
|
struct device *dev;
|
|
|
|
struct da903x_chip_ops *ops;
|
|
|
|
|
|
|
|
int type;
|
|
|
|
uint32_t events_mask;
|
|
|
|
|
|
|
|
struct mutex lock;
|
|
|
|
struct work_struct irq_work;
|
|
|
|
|
|
|
|
struct blocking_notifier_head notifier_list;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline int __da903x_read(struct i2c_client *client,
|
|
|
|
int reg, uint8_t *val)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = i2c_smbus_read_byte_data(client, reg);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&client->dev, "failed reading at 0x%02x\n", reg);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
*val = (uint8_t)ret;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int __da903x_reads(struct i2c_client *client, int reg,
|
|
|
|
int len, uint8_t *val)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = i2c_smbus_read_i2c_block_data(client, reg, len, val);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&client->dev, "failed reading from 0x%02x\n", reg);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int __da903x_write(struct i2c_client *client,
|
|
|
|
int reg, uint8_t val)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = i2c_smbus_write_byte_data(client, reg, val);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&client->dev, "failed writing 0x%02x to 0x%02x\n",
|
|
|
|
val, reg);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int __da903x_writes(struct i2c_client *client, int reg,
|
|
|
|
int len, uint8_t *val)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = i2c_smbus_write_i2c_block_data(client, reg, len, val);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&client->dev, "failed writings to 0x%02x\n", reg);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int da903x_register_notifier(struct device *dev, struct notifier_block *nb,
|
|
|
|
unsigned int events)
|
|
|
|
{
|
|
|
|
struct da903x_chip *chip = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
chip->ops->unmask_events(chip, events);
|
|
|
|
return blocking_notifier_chain_register(&chip->notifier_list, nb);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(da903x_register_notifier);
|
|
|
|
|
|
|
|
int da903x_unregister_notifier(struct device *dev, struct notifier_block *nb,
|
|
|
|
unsigned int events)
|
|
|
|
{
|
|
|
|
struct da903x_chip *chip = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
chip->ops->mask_events(chip, events);
|
|
|
|
return blocking_notifier_chain_unregister(&chip->notifier_list, nb);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(da903x_unregister_notifier);
|
|
|
|
|
|
|
|
int da903x_write(struct device *dev, int reg, uint8_t val)
|
|
|
|
{
|
|
|
|
return __da903x_write(to_i2c_client(dev), reg, val);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(da903x_write);
|
|
|
|
|
2008-12-18 09:54:27 +00:00
|
|
|
int da903x_writes(struct device *dev, int reg, int len, uint8_t *val)
|
|
|
|
{
|
|
|
|
return __da903x_writes(to_i2c_client(dev), reg, len, val);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(da903x_writes);
|
|
|
|
|
2008-10-15 10:20:06 +00:00
|
|
|
int da903x_read(struct device *dev, int reg, uint8_t *val)
|
|
|
|
{
|
|
|
|
return __da903x_read(to_i2c_client(dev), reg, val);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(da903x_read);
|
|
|
|
|
2008-12-18 09:54:27 +00:00
|
|
|
int da903x_reads(struct device *dev, int reg, int len, uint8_t *val)
|
|
|
|
{
|
|
|
|
return __da903x_reads(to_i2c_client(dev), reg, len, val);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(da903x_reads);
|
|
|
|
|
2008-10-15 10:20:06 +00:00
|
|
|
int da903x_set_bits(struct device *dev, int reg, uint8_t bit_mask)
|
|
|
|
{
|
|
|
|
struct da903x_chip *chip = dev_get_drvdata(dev);
|
|
|
|
uint8_t reg_val;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
mutex_lock(&chip->lock);
|
|
|
|
|
|
|
|
ret = __da903x_read(chip->client, reg, ®_val);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
2011-10-31 06:23:03 +00:00
|
|
|
if ((reg_val & bit_mask) != bit_mask) {
|
2008-10-15 10:20:06 +00:00
|
|
|
reg_val |= bit_mask;
|
|
|
|
ret = __da903x_write(chip->client, reg, reg_val);
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
mutex_unlock(&chip->lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(da903x_set_bits);
|
|
|
|
|
|
|
|
int da903x_clr_bits(struct device *dev, int reg, uint8_t bit_mask)
|
|
|
|
{
|
|
|
|
struct da903x_chip *chip = dev_get_drvdata(dev);
|
|
|
|
uint8_t reg_val;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
mutex_lock(&chip->lock);
|
|
|
|
|
|
|
|
ret = __da903x_read(chip->client, reg, ®_val);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (reg_val & bit_mask) {
|
|
|
|
reg_val &= ~bit_mask;
|
|
|
|
ret = __da903x_write(chip->client, reg, reg_val);
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
mutex_unlock(&chip->lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(da903x_clr_bits);
|
|
|
|
|
|
|
|
int da903x_update(struct device *dev, int reg, uint8_t val, uint8_t mask)
|
|
|
|
{
|
|
|
|
struct da903x_chip *chip = dev_get_drvdata(dev);
|
|
|
|
uint8_t reg_val;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
mutex_lock(&chip->lock);
|
|
|
|
|
|
|
|
ret = __da903x_read(chip->client, reg, ®_val);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if ((reg_val & mask) != val) {
|
|
|
|
reg_val = (reg_val & ~mask) | val;
|
|
|
|
ret = __da903x_write(chip->client, reg, reg_val);
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
mutex_unlock(&chip->lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(da903x_update);
|
|
|
|
|
|
|
|
int da903x_query_status(struct device *dev, unsigned int sbits)
|
|
|
|
{
|
|
|
|
struct da903x_chip *chip = dev_get_drvdata(dev);
|
|
|
|
unsigned int status = 0;
|
|
|
|
|
|
|
|
chip->ops->read_status(chip, &status);
|
|
|
|
return ((status & sbits) == sbits);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(da903x_query_status);
|
|
|
|
|
2012-11-19 18:23:04 +00:00
|
|
|
static int da9030_init_chip(struct da903x_chip *chip)
|
2008-10-15 10:20:06 +00:00
|
|
|
{
|
|
|
|
uint8_t chip_id;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = __da903x_read(chip->client, DA9030_CHIP_ID, &chip_id);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = __da903x_write(chip->client, DA9030_SYS_CTRL_A, 0xE8);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
dev_info(chip->dev, "DA9030 (CHIP ID: 0x%02x) detected\n", chip_id);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int da9030_unmask_events(struct da903x_chip *chip, unsigned int events)
|
|
|
|
{
|
|
|
|
uint8_t v[3];
|
|
|
|
|
|
|
|
chip->events_mask &= ~events;
|
|
|
|
|
|
|
|
v[0] = (chip->events_mask & 0xff);
|
|
|
|
v[1] = (chip->events_mask >> 8) & 0xff;
|
|
|
|
v[2] = (chip->events_mask >> 16) & 0xff;
|
|
|
|
|
|
|
|
return __da903x_writes(chip->client, DA9030_IRQ_MASK_A, 3, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int da9030_mask_events(struct da903x_chip *chip, unsigned int events)
|
|
|
|
{
|
|
|
|
uint8_t v[3];
|
|
|
|
|
2008-11-08 00:28:19 +00:00
|
|
|
chip->events_mask |= events;
|
2008-10-15 10:20:06 +00:00
|
|
|
|
|
|
|
v[0] = (chip->events_mask & 0xff);
|
|
|
|
v[1] = (chip->events_mask >> 8) & 0xff;
|
|
|
|
v[2] = (chip->events_mask >> 16) & 0xff;
|
|
|
|
|
|
|
|
return __da903x_writes(chip->client, DA9030_IRQ_MASK_A, 3, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int da9030_read_events(struct da903x_chip *chip, unsigned int *events)
|
|
|
|
{
|
|
|
|
uint8_t v[3] = {0, 0, 0};
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = __da903x_reads(chip->client, DA9030_EVENT_A, 3, v);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
*events = (v[2] << 16) | (v[1] << 8) | v[0];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int da9030_read_status(struct da903x_chip *chip, unsigned int *status)
|
|
|
|
{
|
|
|
|
return __da903x_read(chip->client, DA9030_STATUS, (uint8_t *)status);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int da9034_init_chip(struct da903x_chip *chip)
|
|
|
|
{
|
|
|
|
uint8_t chip_id;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = __da903x_read(chip->client, DA9034_CHIP_ID, &chip_id);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = __da903x_write(chip->client, DA9034_SYS_CTRL_A, 0xE8);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
/* avoid SRAM power off during sleep*/
|
|
|
|
__da903x_write(chip->client, 0x10, 0x07);
|
|
|
|
__da903x_write(chip->client, 0x11, 0xff);
|
|
|
|
__da903x_write(chip->client, 0x12, 0xff);
|
|
|
|
|
|
|
|
/* Enable the ONKEY power down functionality */
|
|
|
|
__da903x_write(chip->client, DA9034_SYS_CTRL_B, 0x20);
|
|
|
|
__da903x_write(chip->client, DA9034_SYS_CTRL_A, 0x60);
|
|
|
|
|
|
|
|
/* workaround to make LEDs work */
|
|
|
|
__da903x_write(chip->client, 0x90, 0x01);
|
|
|
|
__da903x_write(chip->client, 0xB0, 0x08);
|
|
|
|
|
|
|
|
/* make ADTV1 and SDTV1 effective */
|
|
|
|
__da903x_write(chip->client, 0x20, 0x00);
|
|
|
|
|
|
|
|
dev_info(chip->dev, "DA9034 (CHIP ID: 0x%02x) detected\n", chip_id);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int da9034_unmask_events(struct da903x_chip *chip, unsigned int events)
|
|
|
|
{
|
|
|
|
uint8_t v[4];
|
|
|
|
|
|
|
|
chip->events_mask &= ~events;
|
|
|
|
|
|
|
|
v[0] = (chip->events_mask & 0xff);
|
|
|
|
v[1] = (chip->events_mask >> 8) & 0xff;
|
|
|
|
v[2] = (chip->events_mask >> 16) & 0xff;
|
|
|
|
v[3] = (chip->events_mask >> 24) & 0xff;
|
|
|
|
|
|
|
|
return __da903x_writes(chip->client, DA9034_IRQ_MASK_A, 4, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int da9034_mask_events(struct da903x_chip *chip, unsigned int events)
|
|
|
|
{
|
|
|
|
uint8_t v[4];
|
|
|
|
|
|
|
|
chip->events_mask |= events;
|
|
|
|
|
|
|
|
v[0] = (chip->events_mask & 0xff);
|
|
|
|
v[1] = (chip->events_mask >> 8) & 0xff;
|
|
|
|
v[2] = (chip->events_mask >> 16) & 0xff;
|
|
|
|
v[3] = (chip->events_mask >> 24) & 0xff;
|
|
|
|
|
|
|
|
return __da903x_writes(chip->client, DA9034_IRQ_MASK_A, 4, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int da9034_read_events(struct da903x_chip *chip, unsigned int *events)
|
|
|
|
{
|
|
|
|
uint8_t v[4] = {0, 0, 0, 0};
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = __da903x_reads(chip->client, DA9034_EVENT_A, 4, v);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
*events = (v[3] << 24) | (v[2] << 16) | (v[1] << 8) | v[0];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int da9034_read_status(struct da903x_chip *chip, unsigned int *status)
|
|
|
|
{
|
|
|
|
uint8_t v[2] = {0, 0};
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
ret = __da903x_reads(chip->client, DA9034_STATUS_A, 2, v);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
*status = (v[1] << 8) | v[0];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void da903x_irq_work(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct da903x_chip *chip =
|
|
|
|
container_of(work, struct da903x_chip, irq_work);
|
|
|
|
unsigned int events = 0;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
if (chip->ops->read_events(chip, &events))
|
|
|
|
break;
|
|
|
|
|
|
|
|
events &= ~chip->events_mask;
|
|
|
|
if (events == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
blocking_notifier_call_chain(
|
|
|
|
&chip->notifier_list, events, NULL);
|
|
|
|
}
|
|
|
|
enable_irq(chip->client->irq);
|
|
|
|
}
|
|
|
|
|
2009-03-31 10:27:21 +00:00
|
|
|
static irqreturn_t da903x_irq_handler(int irq, void *data)
|
2008-10-15 10:20:06 +00:00
|
|
|
{
|
|
|
|
struct da903x_chip *chip = data;
|
|
|
|
|
|
|
|
disable_irq_nosync(irq);
|
|
|
|
(void)schedule_work(&chip->irq_work);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct da903x_chip_ops da903x_ops[] = {
|
|
|
|
[0] = {
|
|
|
|
.init_chip = da9030_init_chip,
|
|
|
|
.unmask_events = da9030_unmask_events,
|
|
|
|
.mask_events = da9030_mask_events,
|
|
|
|
.read_events = da9030_read_events,
|
|
|
|
.read_status = da9030_read_status,
|
|
|
|
},
|
|
|
|
[1] = {
|
|
|
|
.init_chip = da9034_init_chip,
|
|
|
|
.unmask_events = da9034_unmask_events,
|
|
|
|
.mask_events = da9034_mask_events,
|
|
|
|
.read_events = da9034_read_events,
|
|
|
|
.read_status = da9034_read_status,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct i2c_device_id da903x_id_table[] = {
|
|
|
|
{ "da9030", 0 },
|
|
|
|
{ "da9034", 1 },
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, da903x_id_table);
|
|
|
|
|
2009-01-04 14:31:49 +00:00
|
|
|
static int __remove_subdev(struct device *dev, void *unused)
|
2008-10-15 10:20:06 +00:00
|
|
|
{
|
|
|
|
platform_device_unregister(to_platform_device(dev));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-04 14:31:49 +00:00
|
|
|
static int da903x_remove_subdevs(struct da903x_chip *chip)
|
2008-10-15 10:20:06 +00:00
|
|
|
{
|
|
|
|
return device_for_each_child(chip->dev, NULL, __remove_subdev);
|
|
|
|
}
|
|
|
|
|
2012-11-19 18:23:04 +00:00
|
|
|
static int da903x_add_subdevs(struct da903x_chip *chip,
|
2008-10-15 10:20:06 +00:00
|
|
|
struct da903x_platform_data *pdata)
|
|
|
|
{
|
|
|
|
struct da903x_subdev_info *subdev;
|
|
|
|
struct platform_device *pdev;
|
|
|
|
int i, ret = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < pdata->num_subdevs; i++) {
|
|
|
|
subdev = &pdata->subdevs[i];
|
|
|
|
|
|
|
|
pdev = platform_device_alloc(subdev->name, subdev->id);
|
2010-08-24 05:44:05 +00:00
|
|
|
if (!pdev) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto failed;
|
|
|
|
}
|
2008-10-15 10:20:06 +00:00
|
|
|
|
|
|
|
pdev->dev.parent = chip->dev;
|
|
|
|
pdev->dev.platform_data = subdev->platform_data;
|
|
|
|
|
|
|
|
ret = platform_device_add(pdev);
|
2010-08-24 05:44:05 +00:00
|
|
|
if (ret) {
|
|
|
|
platform_device_put(pdev);
|
2008-10-15 10:20:06 +00:00
|
|
|
goto failed;
|
2010-08-24 05:44:05 +00:00
|
|
|
}
|
2008-10-15 10:20:06 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
failed:
|
|
|
|
da903x_remove_subdevs(chip);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-19 18:23:04 +00:00
|
|
|
static int da903x_probe(struct i2c_client *client,
|
2008-10-15 10:20:06 +00:00
|
|
|
const struct i2c_device_id *id)
|
|
|
|
{
|
|
|
|
struct da903x_platform_data *pdata = client->dev.platform_data;
|
|
|
|
struct da903x_chip *chip;
|
|
|
|
unsigned int tmp;
|
|
|
|
int ret;
|
|
|
|
|
2013-02-20 09:31:26 +00:00
|
|
|
chip = devm_kzalloc(&client->dev, sizeof(struct da903x_chip),
|
|
|
|
GFP_KERNEL);
|
2008-10-15 10:20:06 +00:00
|
|
|
if (chip == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
chip->client = client;
|
|
|
|
chip->dev = &client->dev;
|
|
|
|
chip->ops = &da903x_ops[id->driver_data];
|
|
|
|
|
|
|
|
mutex_init(&chip->lock);
|
|
|
|
INIT_WORK(&chip->irq_work, da903x_irq_work);
|
|
|
|
BLOCKING_INIT_NOTIFIER_HEAD(&chip->notifier_list);
|
|
|
|
|
|
|
|
i2c_set_clientdata(client, chip);
|
|
|
|
|
|
|
|
ret = chip->ops->init_chip(chip);
|
|
|
|
if (ret)
|
2013-02-20 09:31:26 +00:00
|
|
|
return ret;
|
2008-10-15 10:20:06 +00:00
|
|
|
|
|
|
|
/* mask and clear all IRQs */
|
|
|
|
chip->events_mask = 0xffffffff;
|
|
|
|
chip->ops->mask_events(chip, chip->events_mask);
|
|
|
|
chip->ops->read_events(chip, &tmp);
|
|
|
|
|
2013-02-20 09:31:26 +00:00
|
|
|
ret = devm_request_irq(&client->dev, client->irq, da903x_irq_handler,
|
2011-09-15 19:52:09 +00:00
|
|
|
IRQF_TRIGGER_FALLING,
|
2008-10-15 10:20:06 +00:00
|
|
|
"da903x", chip);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&client->dev, "failed to request irq %d\n",
|
|
|
|
client->irq);
|
2013-02-20 09:31:26 +00:00
|
|
|
return ret;
|
2008-10-15 10:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = da903x_add_subdevs(chip, pdata);
|
|
|
|
if (ret)
|
2013-02-20 09:31:26 +00:00
|
|
|
return ret;
|
2008-10-15 10:20:06 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-19 18:26:01 +00:00
|
|
|
static int da903x_remove(struct i2c_client *client)
|
2008-10-15 10:20:06 +00:00
|
|
|
{
|
|
|
|
struct da903x_chip *chip = i2c_get_clientdata(client);
|
|
|
|
|
|
|
|
da903x_remove_subdevs(chip);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct i2c_driver da903x_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "da903x",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
|
|
|
.probe = da903x_probe,
|
2012-11-19 18:20:24 +00:00
|
|
|
.remove = da903x_remove,
|
2008-10-15 10:20:06 +00:00
|
|
|
.id_table = da903x_id_table,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init da903x_init(void)
|
|
|
|
{
|
|
|
|
return i2c_add_driver(&da903x_driver);
|
|
|
|
}
|
2009-06-15 16:04:54 +00:00
|
|
|
subsys_initcall(da903x_init);
|
2008-10-15 10:20:06 +00:00
|
|
|
|
|
|
|
static void __exit da903x_exit(void)
|
|
|
|
{
|
|
|
|
i2c_del_driver(&da903x_driver);
|
|
|
|
}
|
|
|
|
module_exit(da903x_exit);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("PMIC Driver for Dialog Semiconductor DA9034");
|
|
|
|
MODULE_AUTHOR("Eric Miao <eric.miao@marvell.com>"
|
|
|
|
"Mike Rapoport <mike@compulab.co.il>");
|
|
|
|
MODULE_LICENSE("GPL");
|