You've already forked linux-apfs
mirror of
https://github.com/linux-apfs/linux-apfs.git
synced 2026-05-01 15:00:59 -07:00
Merge tag 'iio-for-3.17d' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next
Jonathan writes: Fourth round of IIO new drivers, functionality and cleanups for the 3.17 cycle New functionality * A new modifier to indicate that a rotation is relative to either true or magnetic north. This is to be used by some magnetometers that provide data in this way. * hid magnetometer now supports output rotations from various variants on North * HMC5843 driver converted to regmap and reworked to allow easy support of other similar devices. Support for HMC5983 added via both i2c and SPI. * Rework of Exynos driver to simplify extension to support more devices. * Addition of support for the Exynos3250 ADC (which requires an additional clock) Support for quite a few more devices on its way. Cleanups * ad7997 - a number of cleanups and tweaks to how the events are controlled to make it more intuitive. * kxcjk - cleanups and minor fixes for this new driver.
This commit is contained in:
@@ -98,7 +98,7 @@ static const struct {
|
||||
int val2;
|
||||
int odr_bits;
|
||||
} samp_freq_table[] = { {0, 781000, 0x08}, {1, 563000, 0x09},
|
||||
{3, 125000, 0x0A}, {6, 25000, 0x0B}, {12, 5000, 0},
|
||||
{3, 125000, 0x0A}, {6, 250000, 0x0B}, {12, 500000, 0},
|
||||
{25, 0, 0x01}, {50, 0, 0x02}, {100, 0, 0x03},
|
||||
{200, 0, 0x04}, {400, 0, 0x05}, {800, 0, 0x06},
|
||||
{1600, 0, 0x07} };
|
||||
@@ -138,19 +138,6 @@ static int kxcjk1013_set_mode(struct kxcjk1013_data *data,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int kxcjk1013_chip_ack_intr(struct kxcjk1013_data *data)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = i2c_smbus_read_byte_data(data->client, KXCJK1013_REG_INT_REL);
|
||||
if (ret < 0) {
|
||||
dev_err(&data->client->dev, "Error writing reg_int_rel\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int kxcjk1013_chip_init(struct kxcjk1013_data *data)
|
||||
{
|
||||
int ret;
|
||||
@@ -466,7 +453,7 @@ static const struct attribute_group kxcjk1013_attrs_group = {
|
||||
.realbits = 12, \
|
||||
.storagebits = 16, \
|
||||
.shift = 4, \
|
||||
.endianness = IIO_LE, \
|
||||
.endianness = IIO_CPU, \
|
||||
}, \
|
||||
}
|
||||
|
||||
@@ -498,15 +485,11 @@ static irqreturn_t kxcjk1013_trigger_handler(int irq, void *p)
|
||||
indio_dev->masklength) {
|
||||
ret = kxcjk1013_get_acc_reg(data, bit);
|
||||
if (ret < 0) {
|
||||
kxcjk1013_chip_ack_intr(data);
|
||||
mutex_unlock(&data->mutex);
|
||||
goto err;
|
||||
}
|
||||
data->buffer[i++] = ret;
|
||||
}
|
||||
|
||||
kxcjk1013_chip_ack_intr(data);
|
||||
|
||||
mutex_unlock(&data->mutex);
|
||||
|
||||
iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
|
||||
@@ -517,6 +500,21 @@ err:
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
static int kxcjk1013_trig_try_reen(struct iio_trigger *trig)
|
||||
{
|
||||
struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
|
||||
struct kxcjk1013_data *data = iio_priv(indio_dev);
|
||||
int ret;
|
||||
|
||||
ret = i2c_smbus_read_byte_data(data->client, KXCJK1013_REG_INT_REL);
|
||||
if (ret < 0) {
|
||||
dev_err(&data->client->dev, "Error reading reg_int_rel\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int kxcjk1013_data_rdy_trigger_set_state(struct iio_trigger *trig,
|
||||
bool state)
|
||||
{
|
||||
@@ -543,6 +541,7 @@ static int kxcjk1013_data_rdy_trigger_set_state(struct iio_trigger *trig,
|
||||
|
||||
static const struct iio_trigger_ops kxcjk1013_trigger_ops = {
|
||||
.set_trigger_state = kxcjk1013_data_rdy_trigger_set_state,
|
||||
.try_reenable = kxcjk1013_trig_try_reen,
|
||||
.owner = THIS_MODULE,
|
||||
};
|
||||
|
||||
@@ -645,6 +644,7 @@ static int kxcjk1013_probe(struct i2c_client *client,
|
||||
iio_trigger_set_drvdata(trig, indio_dev);
|
||||
data->trig = trig;
|
||||
indio_dev->trig = trig;
|
||||
iio_trigger_get(indio_dev->trig);
|
||||
|
||||
ret = iio_trigger_register(trig);
|
||||
if (ret)
|
||||
|
||||
+302
-202
File diff suppressed because it is too large
Load Diff
+252
-89
@@ -24,6 +24,7 @@
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/io.h>
|
||||
@@ -39,11 +40,6 @@
|
||||
#include <linux/iio/machine.h>
|
||||
#include <linux/iio/driver.h>
|
||||
|
||||
enum adc_version {
|
||||
ADC_V1,
|
||||
ADC_V2
|
||||
};
|
||||
|
||||
/* EXYNOS4412/5250 ADC_V1 registers definitions */
|
||||
#define ADC_V1_CON(x) ((x) + 0x00)
|
||||
#define ADC_V1_DLY(x) ((x) + 0x08)
|
||||
@@ -75,8 +71,9 @@ enum adc_version {
|
||||
#define ADC_V2_CON2_ACH_SEL(x) (((x) & 0xF) << 0)
|
||||
#define ADC_V2_CON2_ACH_MASK 0xF
|
||||
|
||||
#define MAX_ADC_V2_CHANNELS 10
|
||||
#define MAX_ADC_V1_CHANNELS 8
|
||||
#define MAX_ADC_V2_CHANNELS 10
|
||||
#define MAX_ADC_V1_CHANNELS 8
|
||||
#define MAX_EXYNOS3250_ADC_CHANNELS 2
|
||||
|
||||
/* Bit definitions common for ADC_V1 and ADC_V2 */
|
||||
#define ADC_CON_EN_START (1u << 0)
|
||||
@@ -85,9 +82,12 @@ enum adc_version {
|
||||
#define EXYNOS_ADC_TIMEOUT (msecs_to_jiffies(100))
|
||||
|
||||
struct exynos_adc {
|
||||
struct exynos_adc_data *data;
|
||||
struct device *dev;
|
||||
void __iomem *regs;
|
||||
void __iomem *enable_reg;
|
||||
struct clk *clk;
|
||||
struct clk *sclk;
|
||||
unsigned int irq;
|
||||
struct regulator *vdd;
|
||||
|
||||
@@ -97,43 +97,213 @@ struct exynos_adc {
|
||||
unsigned int version;
|
||||
};
|
||||
|
||||
struct exynos_adc_data {
|
||||
int num_channels;
|
||||
bool needs_sclk;
|
||||
|
||||
void (*init_hw)(struct exynos_adc *info);
|
||||
void (*exit_hw)(struct exynos_adc *info);
|
||||
void (*clear_irq)(struct exynos_adc *info);
|
||||
void (*start_conv)(struct exynos_adc *info, unsigned long addr);
|
||||
};
|
||||
|
||||
static void exynos_adc_unprepare_clk(struct exynos_adc *info)
|
||||
{
|
||||
if (info->data->needs_sclk)
|
||||
clk_unprepare(info->sclk);
|
||||
clk_unprepare(info->clk);
|
||||
}
|
||||
|
||||
static int exynos_adc_prepare_clk(struct exynos_adc *info)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = clk_prepare(info->clk);
|
||||
if (ret) {
|
||||
dev_err(info->dev, "failed preparing adc clock: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (info->data->needs_sclk) {
|
||||
ret = clk_prepare(info->sclk);
|
||||
if (ret) {
|
||||
clk_unprepare(info->clk);
|
||||
dev_err(info->dev,
|
||||
"failed preparing sclk_adc clock: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void exynos_adc_disable_clk(struct exynos_adc *info)
|
||||
{
|
||||
if (info->data->needs_sclk)
|
||||
clk_disable(info->sclk);
|
||||
clk_disable(info->clk);
|
||||
}
|
||||
|
||||
static int exynos_adc_enable_clk(struct exynos_adc *info)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = clk_enable(info->clk);
|
||||
if (ret) {
|
||||
dev_err(info->dev, "failed enabling adc clock: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (info->data->needs_sclk) {
|
||||
ret = clk_enable(info->sclk);
|
||||
if (ret) {
|
||||
clk_disable(info->clk);
|
||||
dev_err(info->dev,
|
||||
"failed enabling sclk_adc clock: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void exynos_adc_v1_init_hw(struct exynos_adc *info)
|
||||
{
|
||||
u32 con1;
|
||||
|
||||
writel(1, info->enable_reg);
|
||||
|
||||
/* set default prescaler values and Enable prescaler */
|
||||
con1 = ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
|
||||
|
||||
/* Enable 12-bit ADC resolution */
|
||||
con1 |= ADC_V1_CON_RES;
|
||||
writel(con1, ADC_V1_CON(info->regs));
|
||||
}
|
||||
|
||||
static void exynos_adc_v1_exit_hw(struct exynos_adc *info)
|
||||
{
|
||||
u32 con;
|
||||
|
||||
writel(0, info->enable_reg);
|
||||
|
||||
con = readl(ADC_V1_CON(info->regs));
|
||||
con |= ADC_V1_CON_STANDBY;
|
||||
writel(con, ADC_V1_CON(info->regs));
|
||||
}
|
||||
|
||||
static void exynos_adc_v1_clear_irq(struct exynos_adc *info)
|
||||
{
|
||||
writel(1, ADC_V1_INTCLR(info->regs));
|
||||
}
|
||||
|
||||
static void exynos_adc_v1_start_conv(struct exynos_adc *info,
|
||||
unsigned long addr)
|
||||
{
|
||||
u32 con1;
|
||||
|
||||
writel(addr, ADC_V1_MUX(info->regs));
|
||||
|
||||
con1 = readl(ADC_V1_CON(info->regs));
|
||||
writel(con1 | ADC_CON_EN_START, ADC_V1_CON(info->regs));
|
||||
}
|
||||
|
||||
static const struct exynos_adc_data exynos_adc_v1_data = {
|
||||
.num_channels = MAX_ADC_V1_CHANNELS,
|
||||
|
||||
.init_hw = exynos_adc_v1_init_hw,
|
||||
.exit_hw = exynos_adc_v1_exit_hw,
|
||||
.clear_irq = exynos_adc_v1_clear_irq,
|
||||
.start_conv = exynos_adc_v1_start_conv,
|
||||
};
|
||||
|
||||
static void exynos_adc_v2_init_hw(struct exynos_adc *info)
|
||||
{
|
||||
u32 con1, con2;
|
||||
|
||||
writel(1, info->enable_reg);
|
||||
|
||||
con1 = ADC_V2_CON1_SOFT_RESET;
|
||||
writel(con1, ADC_V2_CON1(info->regs));
|
||||
|
||||
con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
|
||||
ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
|
||||
writel(con2, ADC_V2_CON2(info->regs));
|
||||
|
||||
/* Enable interrupts */
|
||||
writel(1, ADC_V2_INT_EN(info->regs));
|
||||
}
|
||||
|
||||
static void exynos_adc_v2_exit_hw(struct exynos_adc *info)
|
||||
{
|
||||
u32 con;
|
||||
|
||||
writel(0, info->enable_reg);
|
||||
|
||||
con = readl(ADC_V2_CON1(info->regs));
|
||||
con &= ~ADC_CON_EN_START;
|
||||
writel(con, ADC_V2_CON1(info->regs));
|
||||
}
|
||||
|
||||
static void exynos_adc_v2_clear_irq(struct exynos_adc *info)
|
||||
{
|
||||
writel(1, ADC_V2_INT_ST(info->regs));
|
||||
}
|
||||
|
||||
static void exynos_adc_v2_start_conv(struct exynos_adc *info,
|
||||
unsigned long addr)
|
||||
{
|
||||
u32 con1, con2;
|
||||
|
||||
con2 = readl(ADC_V2_CON2(info->regs));
|
||||
con2 &= ~ADC_V2_CON2_ACH_MASK;
|
||||
con2 |= ADC_V2_CON2_ACH_SEL(addr);
|
||||
writel(con2, ADC_V2_CON2(info->regs));
|
||||
|
||||
con1 = readl(ADC_V2_CON1(info->regs));
|
||||
writel(con1 | ADC_CON_EN_START, ADC_V2_CON1(info->regs));
|
||||
}
|
||||
|
||||
static const struct exynos_adc_data exynos_adc_v2_data = {
|
||||
.num_channels = MAX_ADC_V2_CHANNELS,
|
||||
|
||||
.init_hw = exynos_adc_v2_init_hw,
|
||||
.exit_hw = exynos_adc_v2_exit_hw,
|
||||
.clear_irq = exynos_adc_v2_clear_irq,
|
||||
.start_conv = exynos_adc_v2_start_conv,
|
||||
};
|
||||
|
||||
static const struct exynos_adc_data exynos3250_adc_data = {
|
||||
.num_channels = MAX_EXYNOS3250_ADC_CHANNELS,
|
||||
.needs_sclk = true,
|
||||
|
||||
.init_hw = exynos_adc_v2_init_hw,
|
||||
.exit_hw = exynos_adc_v2_exit_hw,
|
||||
.clear_irq = exynos_adc_v2_clear_irq,
|
||||
.start_conv = exynos_adc_v2_start_conv,
|
||||
};
|
||||
|
||||
static const struct of_device_id exynos_adc_match[] = {
|
||||
{ .compatible = "samsung,exynos-adc-v1", .data = (void *)ADC_V1 },
|
||||
{ .compatible = "samsung,exynos-adc-v2", .data = (void *)ADC_V2 },
|
||||
{
|
||||
.compatible = "samsung,exynos-adc-v1",
|
||||
.data = &exynos_adc_v1_data,
|
||||
}, {
|
||||
.compatible = "samsung,exynos-adc-v2",
|
||||
.data = &exynos_adc_v2_data,
|
||||
}, {
|
||||
.compatible = "samsung,exynos3250-adc",
|
||||
.data = &exynos3250_adc_data,
|
||||
},
|
||||
{},
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, exynos_adc_match);
|
||||
|
||||
static inline unsigned int exynos_adc_get_version(struct platform_device *pdev)
|
||||
static struct exynos_adc_data *exynos_adc_get_data(struct platform_device *pdev)
|
||||
{
|
||||
const struct of_device_id *match;
|
||||
|
||||
match = of_match_node(exynos_adc_match, pdev->dev.of_node);
|
||||
return (unsigned int)match->data;
|
||||
}
|
||||
|
||||
static void exynos_adc_hw_init(struct exynos_adc *info)
|
||||
{
|
||||
u32 con1, con2;
|
||||
|
||||
if (info->version == ADC_V2) {
|
||||
con1 = ADC_V2_CON1_SOFT_RESET;
|
||||
writel(con1, ADC_V2_CON1(info->regs));
|
||||
|
||||
con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
|
||||
ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
|
||||
writel(con2, ADC_V2_CON2(info->regs));
|
||||
|
||||
/* Enable interrupts */
|
||||
writel(1, ADC_V2_INT_EN(info->regs));
|
||||
} else {
|
||||
/* set default prescaler values and Enable prescaler */
|
||||
con1 = ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
|
||||
|
||||
/* Enable 12-bit ADC resolution */
|
||||
con1 |= ADC_V1_CON_RES;
|
||||
writel(con1, ADC_V1_CON(info->regs));
|
||||
}
|
||||
return (struct exynos_adc_data *)match->data;
|
||||
}
|
||||
|
||||
static int exynos_read_raw(struct iio_dev *indio_dev,
|
||||
@@ -144,7 +314,6 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
|
||||
{
|
||||
struct exynos_adc *info = iio_priv(indio_dev);
|
||||
unsigned long timeout;
|
||||
u32 con1, con2;
|
||||
int ret;
|
||||
|
||||
if (mask != IIO_CHAN_INFO_RAW)
|
||||
@@ -154,28 +323,15 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
|
||||
reinit_completion(&info->completion);
|
||||
|
||||
/* Select the channel to be used and Trigger conversion */
|
||||
if (info->version == ADC_V2) {
|
||||
con2 = readl(ADC_V2_CON2(info->regs));
|
||||
con2 &= ~ADC_V2_CON2_ACH_MASK;
|
||||
con2 |= ADC_V2_CON2_ACH_SEL(chan->address);
|
||||
writel(con2, ADC_V2_CON2(info->regs));
|
||||
|
||||
con1 = readl(ADC_V2_CON1(info->regs));
|
||||
writel(con1 | ADC_CON_EN_START,
|
||||
ADC_V2_CON1(info->regs));
|
||||
} else {
|
||||
writel(chan->address, ADC_V1_MUX(info->regs));
|
||||
|
||||
con1 = readl(ADC_V1_CON(info->regs));
|
||||
writel(con1 | ADC_CON_EN_START,
|
||||
ADC_V1_CON(info->regs));
|
||||
}
|
||||
if (info->data->start_conv)
|
||||
info->data->start_conv(info, chan->address);
|
||||
|
||||
timeout = wait_for_completion_timeout
|
||||
(&info->completion, EXYNOS_ADC_TIMEOUT);
|
||||
if (timeout == 0) {
|
||||
dev_warn(&indio_dev->dev, "Conversion timed out! Resetting\n");
|
||||
exynos_adc_hw_init(info);
|
||||
if (info->data->init_hw)
|
||||
info->data->init_hw(info);
|
||||
ret = -ETIMEDOUT;
|
||||
} else {
|
||||
*val = info->value;
|
||||
@@ -193,13 +349,11 @@ static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
|
||||
struct exynos_adc *info = (struct exynos_adc *)dev_id;
|
||||
|
||||
/* Read value */
|
||||
info->value = readl(ADC_V1_DATX(info->regs)) &
|
||||
ADC_DATX_MASK;
|
||||
info->value = readl(ADC_V1_DATX(info->regs)) & ADC_DATX_MASK;
|
||||
|
||||
/* clear irq */
|
||||
if (info->version == ADC_V2)
|
||||
writel(1, ADC_V2_INT_ST(info->regs));
|
||||
else
|
||||
writel(1, ADC_V1_INTCLR(info->regs));
|
||||
if (info->data->clear_irq)
|
||||
info->data->clear_irq(info);
|
||||
|
||||
complete(&info->completion);
|
||||
|
||||
@@ -277,6 +431,12 @@ static int exynos_adc_probe(struct platform_device *pdev)
|
||||
|
||||
info = iio_priv(indio_dev);
|
||||
|
||||
info->data = exynos_adc_get_data(pdev);
|
||||
if (!info->data) {
|
||||
dev_err(&pdev->dev, "failed getting exynos_adc_data\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
info->regs = devm_ioremap_resource(&pdev->dev, mem);
|
||||
if (IS_ERR(info->regs))
|
||||
@@ -294,6 +454,7 @@ static int exynos_adc_probe(struct platform_device *pdev)
|
||||
}
|
||||
|
||||
info->irq = irq;
|
||||
info->dev = &pdev->dev;
|
||||
|
||||
init_completion(&info->completion);
|
||||
|
||||
@@ -304,6 +465,16 @@ static int exynos_adc_probe(struct platform_device *pdev)
|
||||
return PTR_ERR(info->clk);
|
||||
}
|
||||
|
||||
if (info->data->needs_sclk) {
|
||||
info->sclk = devm_clk_get(&pdev->dev, "sclk");
|
||||
if (IS_ERR(info->sclk)) {
|
||||
dev_err(&pdev->dev,
|
||||
"failed getting sclk clock, err = %ld\n",
|
||||
PTR_ERR(info->sclk));
|
||||
return PTR_ERR(info->sclk);
|
||||
}
|
||||
}
|
||||
|
||||
info->vdd = devm_regulator_get(&pdev->dev, "vdd");
|
||||
if (IS_ERR(info->vdd)) {
|
||||
dev_err(&pdev->dev, "failed getting regulator, err = %ld\n",
|
||||
@@ -315,13 +486,13 @@ static int exynos_adc_probe(struct platform_device *pdev)
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = clk_prepare_enable(info->clk);
|
||||
ret = exynos_adc_prepare_clk(info);
|
||||
if (ret)
|
||||
goto err_disable_reg;
|
||||
|
||||
writel(1, info->enable_reg);
|
||||
|
||||
info->version = exynos_adc_get_version(pdev);
|
||||
ret = exynos_adc_enable_clk(info);
|
||||
if (ret)
|
||||
goto err_unprepare_clk;
|
||||
|
||||
platform_set_drvdata(pdev, indio_dev);
|
||||
|
||||
@@ -331,11 +502,7 @@ static int exynos_adc_probe(struct platform_device *pdev)
|
||||
indio_dev->info = &exynos_adc_iio_info;
|
||||
indio_dev->modes = INDIO_DIRECT_MODE;
|
||||
indio_dev->channels = exynos_adc_iio_channels;
|
||||
|
||||
if (info->version == ADC_V1)
|
||||
indio_dev->num_channels = MAX_ADC_V1_CHANNELS;
|
||||
else
|
||||
indio_dev->num_channels = MAX_ADC_V2_CHANNELS;
|
||||
indio_dev->num_channels = info->data->num_channels;
|
||||
|
||||
ret = request_irq(info->irq, exynos_adc_isr,
|
||||
0, dev_name(&pdev->dev), info);
|
||||
@@ -349,7 +516,8 @@ static int exynos_adc_probe(struct platform_device *pdev)
|
||||
if (ret)
|
||||
goto err_irq;
|
||||
|
||||
exynos_adc_hw_init(info);
|
||||
if (info->data->init_hw)
|
||||
info->data->init_hw(info);
|
||||
|
||||
ret = of_platform_populate(np, exynos_adc_match, NULL, &indio_dev->dev);
|
||||
if (ret < 0) {
|
||||
@@ -366,8 +534,11 @@ err_of_populate:
|
||||
err_irq:
|
||||
free_irq(info->irq, info);
|
||||
err_disable_clk:
|
||||
writel(0, info->enable_reg);
|
||||
clk_disable_unprepare(info->clk);
|
||||
if (info->data->exit_hw)
|
||||
info->data->exit_hw(info);
|
||||
exynos_adc_disable_clk(info);
|
||||
err_unprepare_clk:
|
||||
exynos_adc_unprepare_clk(info);
|
||||
err_disable_reg:
|
||||
regulator_disable(info->vdd);
|
||||
return ret;
|
||||
@@ -382,8 +553,10 @@ static int exynos_adc_remove(struct platform_device *pdev)
|
||||
exynos_adc_remove_devices);
|
||||
iio_device_unregister(indio_dev);
|
||||
free_irq(info->irq, info);
|
||||
writel(0, info->enable_reg);
|
||||
clk_disable_unprepare(info->clk);
|
||||
if (info->data->exit_hw)
|
||||
info->data->exit_hw(info);
|
||||
exynos_adc_disable_clk(info);
|
||||
exynos_adc_unprepare_clk(info);
|
||||
regulator_disable(info->vdd);
|
||||
|
||||
return 0;
|
||||
@@ -394,20 +567,10 @@ static int exynos_adc_suspend(struct device *dev)
|
||||
{
|
||||
struct iio_dev *indio_dev = dev_get_drvdata(dev);
|
||||
struct exynos_adc *info = iio_priv(indio_dev);
|
||||
u32 con;
|
||||
|
||||
if (info->version == ADC_V2) {
|
||||
con = readl(ADC_V2_CON1(info->regs));
|
||||
con &= ~ADC_CON_EN_START;
|
||||
writel(con, ADC_V2_CON1(info->regs));
|
||||
} else {
|
||||
con = readl(ADC_V1_CON(info->regs));
|
||||
con |= ADC_V1_CON_STANDBY;
|
||||
writel(con, ADC_V1_CON(info->regs));
|
||||
}
|
||||
|
||||
writel(0, info->enable_reg);
|
||||
clk_disable_unprepare(info->clk);
|
||||
if (info->data->exit_hw)
|
||||
info->data->exit_hw(info);
|
||||
exynos_adc_disable_clk(info);
|
||||
regulator_disable(info->vdd);
|
||||
|
||||
return 0;
|
||||
@@ -423,12 +586,12 @@ static int exynos_adc_resume(struct device *dev)
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = clk_prepare_enable(info->clk);
|
||||
ret = exynos_adc_enable_clk(info);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
writel(1, info->enable_reg);
|
||||
exynos_adc_hw_init(info);
|
||||
if (info->data->init_hw)
|
||||
info->data->init_hw(info);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -87,6 +87,10 @@ static const char * const iio_modifier_names[] = {
|
||||
[IIO_MOD_QUATERNION] = "quaternion",
|
||||
[IIO_MOD_TEMP_AMBIENT] = "ambient",
|
||||
[IIO_MOD_TEMP_OBJECT] = "object",
|
||||
[IIO_MOD_NORTH_MAGN] = "from_north_magnetic",
|
||||
[IIO_MOD_NORTH_TRUE] = "from_north_true",
|
||||
[IIO_MOD_NORTH_MAGN_TILT_COMP] = "from_north_magnetic_tilt_comp",
|
||||
[IIO_MOD_NORTH_TRUE_TILT_COMP] = "from_north_true_tilt_comp",
|
||||
};
|
||||
|
||||
/* relies on pairs of these shared then separate */
|
||||
|
||||
@@ -35,6 +35,10 @@ enum magn_3d_channel {
|
||||
CHANNEL_SCAN_INDEX_X,
|
||||
CHANNEL_SCAN_INDEX_Y,
|
||||
CHANNEL_SCAN_INDEX_Z,
|
||||
CHANNEL_SCAN_INDEX_NORTH_MAGN_TILT_COMP,
|
||||
CHANNEL_SCAN_INDEX_NORTH_TRUE_TILT_COMP,
|
||||
CHANNEL_SCAN_INDEX_NORTH_MAGN,
|
||||
CHANNEL_SCAN_INDEX_NORTH_TRUE,
|
||||
MAGN_3D_CHANNEL_MAX,
|
||||
};
|
||||
|
||||
@@ -42,7 +46,12 @@ struct magn_3d_state {
|
||||
struct hid_sensor_hub_callbacks callbacks;
|
||||
struct hid_sensor_common common_attributes;
|
||||
struct hid_sensor_hub_attribute_info magn[MAGN_3D_CHANNEL_MAX];
|
||||
u32 magn_val[MAGN_3D_CHANNEL_MAX];
|
||||
|
||||
/* dynamically sized array to hold sensor values */
|
||||
u32 *iio_vals;
|
||||
/* array of pointers to sensor value */
|
||||
u32 *magn_val_addr[MAGN_3D_CHANNEL_MAX];
|
||||
|
||||
int scale_pre_decml;
|
||||
int scale_post_decml;
|
||||
int scale_precision;
|
||||
@@ -52,7 +61,11 @@ struct magn_3d_state {
|
||||
static const u32 magn_3d_addresses[MAGN_3D_CHANNEL_MAX] = {
|
||||
HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_X_AXIS,
|
||||
HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Y_AXIS,
|
||||
HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Z_AXIS
|
||||
HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Z_AXIS,
|
||||
HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH,
|
||||
HID_USAGE_SENSOR_ORIENT_COMP_TRUE_NORTH,
|
||||
HID_USAGE_SENSOR_ORIENT_MAGN_NORTH,
|
||||
HID_USAGE_SENSOR_ORIENT_TRUE_NORTH,
|
||||
};
|
||||
|
||||
/* Channel definitions */
|
||||
@@ -66,7 +79,6 @@ static const struct iio_chan_spec magn_3d_channels[] = {
|
||||
BIT(IIO_CHAN_INFO_SCALE) |
|
||||
BIT(IIO_CHAN_INFO_SAMP_FREQ) |
|
||||
BIT(IIO_CHAN_INFO_HYSTERESIS),
|
||||
.scan_index = CHANNEL_SCAN_INDEX_X,
|
||||
}, {
|
||||
.type = IIO_MAGN,
|
||||
.modified = 1,
|
||||
@@ -76,7 +88,6 @@ static const struct iio_chan_spec magn_3d_channels[] = {
|
||||
BIT(IIO_CHAN_INFO_SCALE) |
|
||||
BIT(IIO_CHAN_INFO_SAMP_FREQ) |
|
||||
BIT(IIO_CHAN_INFO_HYSTERESIS),
|
||||
.scan_index = CHANNEL_SCAN_INDEX_Y,
|
||||
}, {
|
||||
.type = IIO_MAGN,
|
||||
.modified = 1,
|
||||
@@ -86,7 +97,42 @@ static const struct iio_chan_spec magn_3d_channels[] = {
|
||||
BIT(IIO_CHAN_INFO_SCALE) |
|
||||
BIT(IIO_CHAN_INFO_SAMP_FREQ) |
|
||||
BIT(IIO_CHAN_INFO_HYSTERESIS),
|
||||
.scan_index = CHANNEL_SCAN_INDEX_Z,
|
||||
}, {
|
||||
.type = IIO_ROT,
|
||||
.modified = 1,
|
||||
.channel2 = IIO_MOD_NORTH_MAGN_TILT_COMP,
|
||||
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
||||
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
|
||||
BIT(IIO_CHAN_INFO_SCALE) |
|
||||
BIT(IIO_CHAN_INFO_SAMP_FREQ) |
|
||||
BIT(IIO_CHAN_INFO_HYSTERESIS),
|
||||
}, {
|
||||
.type = IIO_ROT,
|
||||
.modified = 1,
|
||||
.channel2 = IIO_MOD_NORTH_TRUE_TILT_COMP,
|
||||
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
||||
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
|
||||
BIT(IIO_CHAN_INFO_SCALE) |
|
||||
BIT(IIO_CHAN_INFO_SAMP_FREQ) |
|
||||
BIT(IIO_CHAN_INFO_HYSTERESIS),
|
||||
}, {
|
||||
.type = IIO_ROT,
|
||||
.modified = 1,
|
||||
.channel2 = IIO_MOD_NORTH_MAGN,
|
||||
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
||||
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
|
||||
BIT(IIO_CHAN_INFO_SCALE) |
|
||||
BIT(IIO_CHAN_INFO_SAMP_FREQ) |
|
||||
BIT(IIO_CHAN_INFO_HYSTERESIS),
|
||||
}, {
|
||||
.type = IIO_ROT,
|
||||
.modified = 1,
|
||||
.channel2 = IIO_MOD_NORTH_TRUE,
|
||||
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
||||
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
|
||||
BIT(IIO_CHAN_INFO_SCALE) |
|
||||
BIT(IIO_CHAN_INFO_SAMP_FREQ) |
|
||||
BIT(IIO_CHAN_INFO_HYSTERESIS),
|
||||
}
|
||||
};
|
||||
|
||||
@@ -126,8 +172,8 @@ static int magn_3d_read_raw(struct iio_dev *indio_dev,
|
||||
msleep_interruptible(poll_value * 2);
|
||||
|
||||
report_id =
|
||||
magn_state->magn[chan->scan_index].report_id;
|
||||
address = magn_3d_addresses[chan->scan_index];
|
||||
magn_state->magn[chan->address].report_id;
|
||||
address = magn_3d_addresses[chan->address];
|
||||
if (report_id >= 0)
|
||||
*val = sensor_hub_input_attr_get_raw_value(
|
||||
magn_state->common_attributes.hsdev,
|
||||
@@ -218,8 +264,8 @@ static int magn_3d_proc_event(struct hid_sensor_hub_device *hsdev,
|
||||
dev_dbg(&indio_dev->dev, "magn_3d_proc_event\n");
|
||||
if (atomic_read(&magn_state->common_attributes.data_ready))
|
||||
hid_sensor_push_data(indio_dev,
|
||||
magn_state->magn_val,
|
||||
sizeof(magn_state->magn_val));
|
||||
magn_state->iio_vals,
|
||||
sizeof(magn_state->iio_vals));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -233,52 +279,126 @@ static int magn_3d_capture_sample(struct hid_sensor_hub_device *hsdev,
|
||||
struct iio_dev *indio_dev = platform_get_drvdata(priv);
|
||||
struct magn_3d_state *magn_state = iio_priv(indio_dev);
|
||||
int offset;
|
||||
int ret = -EINVAL;
|
||||
int ret = 0;
|
||||
u32 *iio_val = NULL;
|
||||
|
||||
switch (usage_id) {
|
||||
case HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_X_AXIS:
|
||||
case HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Y_AXIS:
|
||||
case HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Z_AXIS:
|
||||
offset = usage_id - HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_X_AXIS;
|
||||
magn_state->magn_val[CHANNEL_SCAN_INDEX_X + offset] =
|
||||
*(u32 *)raw_data;
|
||||
ret = 0;
|
||||
offset = (usage_id - HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_X_AXIS)
|
||||
+ CHANNEL_SCAN_INDEX_X;
|
||||
break;
|
||||
case HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH:
|
||||
case HID_USAGE_SENSOR_ORIENT_COMP_TRUE_NORTH:
|
||||
case HID_USAGE_SENSOR_ORIENT_MAGN_NORTH:
|
||||
case HID_USAGE_SENSOR_ORIENT_TRUE_NORTH:
|
||||
offset = (usage_id - HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH)
|
||||
+ CHANNEL_SCAN_INDEX_NORTH_MAGN_TILT_COMP;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
iio_val = magn_state->magn_val_addr[offset];
|
||||
|
||||
if (iio_val != NULL)
|
||||
*iio_val = *((u32 *)raw_data);
|
||||
else
|
||||
ret = -EINVAL;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Parse report which is specific to an usage id*/
|
||||
static int magn_3d_parse_report(struct platform_device *pdev,
|
||||
struct hid_sensor_hub_device *hsdev,
|
||||
struct iio_chan_spec *channels,
|
||||
struct iio_chan_spec **channels,
|
||||
int *chan_count,
|
||||
unsigned usage_id,
|
||||
struct magn_3d_state *st)
|
||||
{
|
||||
int ret;
|
||||
int i;
|
||||
int attr_count = 0;
|
||||
struct iio_chan_spec *_channels;
|
||||
|
||||
for (i = 0; i <= CHANNEL_SCAN_INDEX_Z; ++i) {
|
||||
ret = sensor_hub_input_get_attribute_info(hsdev,
|
||||
HID_INPUT_REPORT,
|
||||
usage_id,
|
||||
HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_X_AXIS + i,
|
||||
&st->magn[CHANNEL_SCAN_INDEX_X + i]);
|
||||
if (ret < 0)
|
||||
break;
|
||||
magn_3d_adjust_channel_bit_mask(channels,
|
||||
CHANNEL_SCAN_INDEX_X + i,
|
||||
st->magn[CHANNEL_SCAN_INDEX_X + i].size);
|
||||
/* Scan for each usage attribute supported */
|
||||
for (i = 0; i < MAGN_3D_CHANNEL_MAX; i++) {
|
||||
int status;
|
||||
u32 address = magn_3d_addresses[i];
|
||||
|
||||
/* Check if usage attribute exists in the sensor hub device */
|
||||
status = sensor_hub_input_get_attribute_info(hsdev,
|
||||
HID_INPUT_REPORT,
|
||||
usage_id,
|
||||
address,
|
||||
&(st->magn[i]));
|
||||
if (!status)
|
||||
attr_count++;
|
||||
}
|
||||
dev_dbg(&pdev->dev, "magn_3d %x:%x, %x:%x, %x:%x\n",
|
||||
|
||||
if (attr_count <= 0) {
|
||||
dev_err(&pdev->dev,
|
||||
"failed to find any supported usage attributes in report\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
dev_dbg(&pdev->dev, "magn_3d Found %d usage attributes\n",
|
||||
attr_count);
|
||||
dev_dbg(&pdev->dev, "magn_3d X: %x:%x Y: %x:%x Z: %x:%x\n",
|
||||
st->magn[0].index,
|
||||
st->magn[0].report_id,
|
||||
st->magn[1].index, st->magn[1].report_id,
|
||||
st->magn[2].index, st->magn[2].report_id);
|
||||
|
||||
/* Setup IIO channel array */
|
||||
_channels = devm_kcalloc(&pdev->dev, attr_count,
|
||||
sizeof(struct iio_chan_spec),
|
||||
GFP_KERNEL);
|
||||
if (!_channels) {
|
||||
dev_err(&pdev->dev,
|
||||
"failed to allocate space for iio channels\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
st->iio_vals = devm_kcalloc(&pdev->dev, attr_count,
|
||||
sizeof(u32),
|
||||
GFP_KERNEL);
|
||||
if (!st->iio_vals) {
|
||||
dev_err(&pdev->dev,
|
||||
"failed to allocate space for iio values array\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
for (i = 0, *chan_count = 0;
|
||||
i < MAGN_3D_CHANNEL_MAX && *chan_count < attr_count;
|
||||
i++){
|
||||
if (st->magn[i].index >= 0) {
|
||||
/* Setup IIO channel struct */
|
||||
(_channels[*chan_count]) = magn_3d_channels[i];
|
||||
(_channels[*chan_count]).scan_index = *chan_count;
|
||||
(_channels[*chan_count]).address = i;
|
||||
|
||||
/* Set magn_val_addr to iio value address */
|
||||
st->magn_val_addr[i] = &(st->iio_vals[*chan_count]);
|
||||
magn_3d_adjust_channel_bit_mask(_channels,
|
||||
*chan_count,
|
||||
st->magn[i].size);
|
||||
(*chan_count)++;
|
||||
}
|
||||
}
|
||||
|
||||
if (*chan_count <= 0) {
|
||||
dev_err(&pdev->dev,
|
||||
"failed to find any magnetic channels setup\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
*channels = _channels;
|
||||
|
||||
dev_dbg(&pdev->dev, "magn_3d Setup %d IIO channels\n",
|
||||
*chan_count);
|
||||
|
||||
st->scale_precision = hid_sensor_format_scale(
|
||||
HID_USAGE_SENSOR_COMPASS_3D,
|
||||
&st->magn[CHANNEL_SCAN_INDEX_X],
|
||||
@@ -296,7 +416,7 @@ static int magn_3d_parse_report(struct platform_device *pdev,
|
||||
st->common_attributes.sensitivity.report_id);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Function to initialize the processing for usage id */
|
||||
@@ -308,6 +428,7 @@ static int hid_magn_3d_probe(struct platform_device *pdev)
|
||||
struct magn_3d_state *magn_state;
|
||||
struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
|
||||
struct iio_chan_spec *channels;
|
||||
int chan_count = 0;
|
||||
|
||||
indio_dev = devm_iio_device_alloc(&pdev->dev,
|
||||
sizeof(struct magn_3d_state));
|
||||
@@ -328,22 +449,16 @@ static int hid_magn_3d_probe(struct platform_device *pdev)
|
||||
return ret;
|
||||
}
|
||||
|
||||
channels = kmemdup(magn_3d_channels, sizeof(magn_3d_channels),
|
||||
GFP_KERNEL);
|
||||
if (!channels) {
|
||||
dev_err(&pdev->dev, "failed to duplicate channels\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
ret = magn_3d_parse_report(pdev, hsdev, channels,
|
||||
ret = magn_3d_parse_report(pdev, hsdev,
|
||||
&channels, &chan_count,
|
||||
HID_USAGE_SENSOR_COMPASS_3D, magn_state);
|
||||
if (ret) {
|
||||
dev_err(&pdev->dev, "failed to setup attributes\n");
|
||||
goto error_free_dev_mem;
|
||||
dev_err(&pdev->dev, "failed to parse report\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
indio_dev->channels = channels;
|
||||
indio_dev->num_channels = ARRAY_SIZE(magn_3d_channels);
|
||||
indio_dev->num_channels = chan_count;
|
||||
indio_dev->dev.parent = &pdev->dev;
|
||||
indio_dev->info = &magn_3d_info;
|
||||
indio_dev->name = name;
|
||||
@@ -353,7 +468,7 @@ static int hid_magn_3d_probe(struct platform_device *pdev)
|
||||
NULL, NULL);
|
||||
if (ret) {
|
||||
dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
|
||||
goto error_free_dev_mem;
|
||||
return ret;
|
||||
}
|
||||
atomic_set(&magn_state->common_attributes.data_ready, 0);
|
||||
ret = hid_sensor_setup_trigger(indio_dev, name,
|
||||
@@ -387,8 +502,6 @@ error_remove_trigger:
|
||||
hid_sensor_remove_trigger(&magn_state->common_attributes);
|
||||
error_unreg_buffer_funcs:
|
||||
iio_triggered_buffer_cleanup(indio_dev);
|
||||
error_free_dev_mem:
|
||||
kfree(indio_dev->channels);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -403,7 +516,6 @@ static int hid_magn_3d_remove(struct platform_device *pdev)
|
||||
iio_device_unregister(indio_dev);
|
||||
hid_sensor_remove_trigger(&magn_state->common_attributes);
|
||||
iio_triggered_buffer_cleanup(indio_dev);
|
||||
kfree(indio_dev->channels);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user