Commit 873357b1 authored by Lee Jones's avatar Lee Jones

Merge branches 'ib-mfd-iio-input-5.7' and 'ib-mfd-iio-rtc-5.7' into ibs-for-mfd-merged

parents 189c3c49 7858658c
......@@ -15,6 +15,8 @@ Required properties:
- reg: the I2C slave address of the device
Optional properties:
- interrupts: interrupt mapping for IRQ
See Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
- system-power-controller:
See Documentation/devicetree/bindings/power/power-controller.txt
......@@ -32,6 +34,8 @@ Example:
pmic@32 {
compatible = "ricoh,rn5t618";
reg = <0x32>;
interrupt-parent = <&gpio5>;
interrupts = <11 IRQ_TYPE_EDGE_FALLING>;
system-power-controller;
regulators {
......
......@@ -783,6 +783,16 @@ config RCAR_GYRO_ADC
To compile this driver as a module, choose M here: the
module will be called rcar-gyroadc.
config RN5T618_ADC
tristate "ADC for the RN5T618/RC5T619 family of chips"
depends on MFD_RN5T618
help
Say yes here to build support for the integrated ADC inside the
RN5T618/619 series PMICs:
This driver can also be built as a module. If so, the module
will be called rn5t618-adc.
config ROCKCHIP_SARADC
tristate "Rockchip SARADC driver"
depends on ARCH_ROCKCHIP || (ARM && COMPILE_TEST)
......
......@@ -74,6 +74,7 @@ obj-$(CONFIG_QCOM_VADC_COMMON) += qcom-vadc-common.o
obj-$(CONFIG_QCOM_SPMI_VADC) += qcom-spmi-vadc.o
obj-$(CONFIG_QCOM_PM8XXX_XOADC) += qcom-pm8xxx-xoadc.o
obj-$(CONFIG_RCAR_GYRO_ADC) += rcar-gyroadc.o
obj-$(CONFIG_RN5T618_ADC) += rn5t618-adc.o
obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o
obj-$(CONFIG_SC27XX_ADC) += sc27xx_adc.o
obj-$(CONFIG_SPEAR_ADC) += spear_adc.o
......
// SPDX-License-Identifier: GPL-2.0+
/*
* ADC driver for the RICOH RN5T618 power management chip family
*
* Copyright (C) 2019 Andreas Kemnade
*/
#include <linux/kernel.h>
#include <linux/device.h>
#include <linux/errno.h>
#include <linux/interrupt.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/mfd/rn5t618.h>
#include <linux/platform_device.h>
#include <linux/completion.h>
#include <linux/regmap.h>
#include <linux/iio/iio.h>
#include <linux/slab.h>
#define RN5T618_ADC_CONVERSION_TIMEOUT (msecs_to_jiffies(500))
#define RN5T618_REFERENCE_VOLT 2500
/* mask for selecting channels for single conversion */
#define RN5T618_ADCCNT3_CHANNEL_MASK 0x7
/* average 4-time conversion mode */
#define RN5T618_ADCCNT3_AVG BIT(3)
/* set for starting a single conversion, gets cleared by hw when done */
#define RN5T618_ADCCNT3_GODONE BIT(4)
/* automatic conversion, period is in ADCCNT2, selected channels are
* in ADCCNT1
*/
#define RN5T618_ADCCNT3_AUTO BIT(5)
#define RN5T618_ADCEND_IRQ BIT(0)
struct rn5t618_adc_data {
struct device *dev;
struct rn5t618 *rn5t618;
struct completion conv_completion;
int irq;
};
struct rn5t618_channel_ratios {
u16 numerator;
u16 denominator;
};
enum rn5t618_channels {
LIMMON = 0,
VBAT,
VADP,
VUSB,
VSYS,
VTHM,
AIN1,
AIN0
};
static const struct rn5t618_channel_ratios rn5t618_ratios[8] = {
[LIMMON] = {50, 32}, /* measured across 20mOhm, amplified by 32 */
[VBAT] = {2, 1},
[VADP] = {3, 1},
[VUSB] = {3, 1},
[VSYS] = {3, 1},
[VTHM] = {1, 1},
[AIN1] = {1, 1},
[AIN0] = {1, 1},
};
static int rn5t618_read_adc_reg(struct rn5t618 *rn5t618, int reg, u16 *val)
{
u8 data[2];
int ret;
ret = regmap_bulk_read(rn5t618->regmap, reg, data, sizeof(data));
if (ret < 0)
return ret;
*val = (data[0] << 4) | (data[1] & 0xF);
return 0;
}
static irqreturn_t rn5t618_adc_irq(int irq, void *data)
{
struct rn5t618_adc_data *adc = data;
unsigned int r = 0;
int ret;
/* clear low & high threshold irqs */
regmap_write(adc->rn5t618->regmap, RN5T618_IR_ADC1, 0);
regmap_write(adc->rn5t618->regmap, RN5T618_IR_ADC2, 0);
ret = regmap_read(adc->rn5t618->regmap, RN5T618_IR_ADC3, &r);
if (ret < 0)
dev_err(adc->dev, "failed to read IRQ status: %d\n", ret);
regmap_write(adc->rn5t618->regmap, RN5T618_IR_ADC3, 0);
if (r & RN5T618_ADCEND_IRQ)
complete(&adc->conv_completion);
return IRQ_HANDLED;
}
static int rn5t618_adc_read(struct iio_dev *iio_dev,
const struct iio_chan_spec *chan,
int *val, int *val2, long mask)
{
struct rn5t618_adc_data *adc = iio_priv(iio_dev);
u16 raw;
int ret;
if (mask == IIO_CHAN_INFO_SCALE) {
*val = RN5T618_REFERENCE_VOLT *
rn5t618_ratios[chan->channel].numerator;
*val2 = rn5t618_ratios[chan->channel].denominator * 4095;
return IIO_VAL_FRACTIONAL;
}
/* select channel */
ret = regmap_update_bits(adc->rn5t618->regmap, RN5T618_ADCCNT3,
RN5T618_ADCCNT3_CHANNEL_MASK,
chan->channel);
if (ret < 0)
return ret;
ret = regmap_write(adc->rn5t618->regmap, RN5T618_EN_ADCIR3,
RN5T618_ADCEND_IRQ);
if (ret < 0)
return ret;
ret = regmap_update_bits(adc->rn5t618->regmap, RN5T618_ADCCNT3,
RN5T618_ADCCNT3_AVG,
mask == IIO_CHAN_INFO_AVERAGE_RAW ?
RN5T618_ADCCNT3_AVG : 0);
if (ret < 0)
return ret;
init_completion(&adc->conv_completion);
/* single conversion */
ret = regmap_update_bits(adc->rn5t618->regmap, RN5T618_ADCCNT3,
RN5T618_ADCCNT3_GODONE,
RN5T618_ADCCNT3_GODONE);
if (ret < 0)
return ret;
ret = wait_for_completion_timeout(&adc->conv_completion,
RN5T618_ADC_CONVERSION_TIMEOUT);
if (ret == 0) {
dev_warn(adc->dev, "timeout waiting for adc result\n");
return -ETIMEDOUT;
}
ret = rn5t618_read_adc_reg(adc->rn5t618,
RN5T618_ILIMDATAH + 2 * chan->channel,
&raw);
if (ret < 0)
return ret;
*val = raw;
return IIO_VAL_INT;
}
static const struct iio_info rn5t618_adc_iio_info = {
.read_raw = &rn5t618_adc_read,
};
#define RN5T618_ADC_CHANNEL(_channel, _type, _name) { \
.type = _type, \
.channel = _channel, \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
BIT(IIO_CHAN_INFO_AVERAGE_RAW) | \
BIT(IIO_CHAN_INFO_SCALE), \
.datasheet_name = _name, \
.indexed = 1. \
}
static const struct iio_chan_spec rn5t618_adc_iio_channels[] = {
RN5T618_ADC_CHANNEL(LIMMON, IIO_CURRENT, "LIMMON"),
RN5T618_ADC_CHANNEL(VBAT, IIO_VOLTAGE, "VBAT"),
RN5T618_ADC_CHANNEL(VADP, IIO_VOLTAGE, "VADP"),
RN5T618_ADC_CHANNEL(VUSB, IIO_VOLTAGE, "VUSB"),
RN5T618_ADC_CHANNEL(VSYS, IIO_VOLTAGE, "VSYS"),
RN5T618_ADC_CHANNEL(VTHM, IIO_VOLTAGE, "VTHM"),
RN5T618_ADC_CHANNEL(AIN1, IIO_VOLTAGE, "AIN1"),
RN5T618_ADC_CHANNEL(AIN0, IIO_VOLTAGE, "AIN0")
};
static int rn5t618_adc_probe(struct platform_device *pdev)
{
int ret;
struct iio_dev *iio_dev;
struct rn5t618_adc_data *adc;
struct rn5t618 *rn5t618 = dev_get_drvdata(pdev->dev.parent);
iio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*adc));
if (!iio_dev) {
dev_err(&pdev->dev, "failed allocating iio device\n");
return -ENOMEM;
}
adc = iio_priv(iio_dev);
adc->dev = &pdev->dev;
adc->rn5t618 = rn5t618;
if (rn5t618->irq_data)
adc->irq = regmap_irq_get_virq(rn5t618->irq_data,
RN5T618_IRQ_ADC);
if (adc->irq <= 0) {
dev_err(&pdev->dev, "get virq failed\n");
return -EINVAL;
}
init_completion(&adc->conv_completion);
iio_dev->name = dev_name(&pdev->dev);
iio_dev->dev.parent = &pdev->dev;
iio_dev->info = &rn5t618_adc_iio_info;
iio_dev->modes = INDIO_DIRECT_MODE;
iio_dev->channels = rn5t618_adc_iio_channels;
iio_dev->num_channels = ARRAY_SIZE(rn5t618_adc_iio_channels);
/* stop any auto-conversion */
ret = regmap_write(rn5t618->regmap, RN5T618_ADCCNT3, 0);
if (ret < 0)
return ret;
platform_set_drvdata(pdev, iio_dev);
ret = devm_request_threaded_irq(adc->dev, adc->irq, NULL,
rn5t618_adc_irq,
IRQF_ONESHOT, dev_name(adc->dev),
adc);
if (ret < 0) {
dev_err(adc->dev, "request irq %d failed: %d\n", adc->irq, ret);
return ret;
}
return devm_iio_device_register(adc->dev, iio_dev);
}
static struct platform_driver rn5t618_adc_driver = {
.driver = {
.name = "rn5t618-adc",
},
.probe = rn5t618_adc_probe,
};
module_platform_driver(rn5t618_adc_driver);
MODULE_ALIAS("platform:rn5t618-adc");
MODULE_DESCRIPTION("RICOH RN5T618 ADC driver");
MODULE_LICENSE("GPL");
......@@ -1071,6 +1071,7 @@ config MFD_RN5T618
depends on OF
select MFD_CORE
select REGMAP_I2C
select REGMAP_IRQ
help
Say yes here to add support for the Ricoh RN5T567,
RN5T618, RC5T619 PMIC.
......
......@@ -8,10 +8,13 @@
#include <linux/delay.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/mfd/core.h>
#include <linux/mfd/rn5t618.h>
#include <linux/module.h>
#include <linux/of_device.h>
#include <linux/platform_device.h>
#include <linux/reboot.h>
#include <linux/regmap.h>
......@@ -20,6 +23,13 @@ static const struct mfd_cell rn5t618_cells[] = {
{ .name = "rn5t618-wdt" },
};
static const struct mfd_cell rc5t619_cells[] = {
{ .name = "rn5t618-adc" },
{ .name = "rn5t618-regulator" },
{ .name = "rc5t619-rtc" },
{ .name = "rn5t618-wdt" },
};
static bool rn5t618_volatile_reg(struct device *dev, unsigned int reg)
{
switch (reg) {
......@@ -32,6 +42,8 @@ static bool rn5t618_volatile_reg(struct device *dev, unsigned int reg)
case RN5T618_IR_GPF:
case RN5T618_MON_IOIN:
case RN5T618_INTMON:
case RN5T618_RTC_CTRL1 ... RN5T618_RTC_CTRL2:
case RN5T618_RTC_SECONDS ... RN5T618_RTC_YEAR:
return true;
default:
return false;
......@@ -46,9 +58,56 @@ static const struct regmap_config rn5t618_regmap_config = {
.cache_type = REGCACHE_RBTREE,
};
static const struct regmap_irq rc5t619_irqs[] = {
REGMAP_IRQ_REG(RN5T618_IRQ_SYS, 0, BIT(0)),
REGMAP_IRQ_REG(RN5T618_IRQ_DCDC, 0, BIT(1)),
REGMAP_IRQ_REG(RN5T618_IRQ_RTC, 0, BIT(2)),
REGMAP_IRQ_REG(RN5T618_IRQ_ADC, 0, BIT(3)),
REGMAP_IRQ_REG(RN5T618_IRQ_GPIO, 0, BIT(4)),
REGMAP_IRQ_REG(RN5T618_IRQ_CHG, 0, BIT(6)),
};
static const struct regmap_irq_chip rc5t619_irq_chip = {
.name = "rc5t619",
.irqs = rc5t619_irqs,
.num_irqs = ARRAY_SIZE(rc5t619_irqs),
.num_regs = 1,
.status_base = RN5T618_INTMON,
.mask_base = RN5T618_INTEN,
.mask_invert = true,
};
static struct rn5t618 *rn5t618_pm_power_off;
static struct notifier_block rn5t618_restart_handler;
static int rn5t618_irq_init(struct rn5t618 *rn5t618)
{
const struct regmap_irq_chip *irq_chip = NULL;
int ret;
if (!rn5t618->irq)
return 0;
switch (rn5t618->variant) {
case RC5T619:
irq_chip = &rc5t619_irq_chip;
break;
default:
dev_err(rn5t618->dev, "Currently no IRQ support for variant %d\n",
(int)rn5t618->variant);
return -ENOENT;
}
ret = devm_regmap_add_irq_chip(rn5t618->dev, rn5t618->regmap,
rn5t618->irq,
IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
0, irq_chip, &rn5t618->irq_data);
if (ret)
dev_err(rn5t618->dev, "Failed to register IRQ chip\n");
return ret;
}
static void rn5t618_trigger_poweroff_sequence(bool repower)
{
/* disable automatic repower-on */
......@@ -87,8 +146,7 @@ static const struct of_device_id rn5t618_of_match[] = {
};
MODULE_DEVICE_TABLE(of, rn5t618_of_match);
static int rn5t618_i2c_probe(struct i2c_client *i2c,
const struct i2c_device_id *id)
static int rn5t618_i2c_probe(struct i2c_client *i2c)
{
const struct of_device_id *of_id;
struct rn5t618 *priv;
......@@ -106,6 +164,8 @@ static int rn5t618_i2c_probe(struct i2c_client *i2c,
i2c_set_clientdata(i2c, priv);
priv->variant = (long)of_id->data;
priv->irq = i2c->irq;
priv->dev = &i2c->dev;
priv->regmap = devm_regmap_init_i2c(i2c, &rn5t618_regmap_config);
if (IS_ERR(priv->regmap)) {
......@@ -114,8 +174,16 @@ static int rn5t618_i2c_probe(struct i2c_client *i2c,
return ret;
}
ret = devm_mfd_add_devices(&i2c->dev, -1, rn5t618_cells,
ARRAY_SIZE(rn5t618_cells), NULL, 0, NULL);
if (priv->variant == RC5T619)
ret = devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_NONE,
rc5t619_cells,
ARRAY_SIZE(rc5t619_cells),
NULL, 0, NULL);
else
ret = devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_NONE,
rn5t618_cells,
ARRAY_SIZE(rn5t618_cells),
NULL, 0, NULL);
if (ret) {
dev_err(&i2c->dev, "failed to add sub-devices: %d\n", ret);
return ret;
......@@ -138,7 +206,7 @@ static int rn5t618_i2c_probe(struct i2c_client *i2c,
return ret;
}
return 0;
return rn5t618_irq_init(priv);
}
static int rn5t618_i2c_remove(struct i2c_client *i2c)
......@@ -155,19 +223,38 @@ static int rn5t618_i2c_remove(struct i2c_client *i2c)
return 0;
}
static const struct i2c_device_id rn5t618_i2c_id[] = {
{ }
};
MODULE_DEVICE_TABLE(i2c, rn5t618_i2c_id);
static int __maybe_unused rn5t618_i2c_suspend(struct device *dev)
{
struct rn5t618 *priv = dev_get_drvdata(dev);
if (priv->irq)
disable_irq(priv->irq);
return 0;
}
static int __maybe_unused rn5t618_i2c_resume(struct device *dev)
{
struct rn5t618 *priv = dev_get_drvdata(dev);
if (priv->irq)
enable_irq(priv->irq);
return 0;
}
static SIMPLE_DEV_PM_OPS(rn5t618_i2c_dev_pm_ops,
rn5t618_i2c_suspend,
rn5t618_i2c_resume);
static struct i2c_driver rn5t618_i2c_driver = {
.driver = {
.name = "rn5t618",
.of_match_table = of_match_ptr(rn5t618_of_match),
.pm = &rn5t618_i2c_dev_pm_ops,
},
.probe = rn5t618_i2c_probe,
.probe_new = rn5t618_i2c_probe,
.remove = rn5t618_i2c_remove,
.id_table = rn5t618_i2c_id,
};
module_i2c_driver(rn5t618_i2c_driver);
......
......@@ -591,6 +591,16 @@ config RTC_DRV_RC5T583
This driver can also be built as a module. If so, the module
will be called rtc-rc5t583.
config RTC_DRV_RC5T619
tristate "RICOH RC5T619 RTC driver"
depends on MFD_RN5T618
help
If you say yes here you get support for the RTC on the
RICOH RC5T619 chips.
This driver can also be built as a module. If so, the module
will be called rtc-rc5t619.
config RTC_DRV_S35390A
tristate "Seiko Instruments S-35390A"
select BITREVERSE
......
......@@ -137,6 +137,7 @@ obj-$(CONFIG_RTC_DRV_PXA) += rtc-pxa.o
obj-$(CONFIG_RTC_DRV_R7301) += rtc-r7301.o
obj-$(CONFIG_RTC_DRV_R9701) += rtc-r9701.o
obj-$(CONFIG_RTC_DRV_RC5T583) += rtc-rc5t583.o
obj-$(CONFIG_RTC_DRV_RC5T619) += rtc-rc5t619.o
obj-$(CONFIG_RTC_DRV_RK808) += rtc-rk808.o
obj-$(CONFIG_RTC_DRV_RP5C01) += rtc-rp5c01.o
obj-$(CONFIG_RTC_DRV_RS5C313) += rtc-rs5c313.o
......
This diff is collapsed.
......@@ -139,6 +139,17 @@
#define RN5T618_INTPOL 0x9c
#define RN5T618_INTEN 0x9d
#define RN5T618_INTMON 0x9e
#define RN5T618_RTC_SECONDS 0xA0
#define RN5T618_RTC_MDAY 0xA4
#define RN5T618_RTC_MONTH 0xA5
#define RN5T618_RTC_YEAR 0xA6
#define RN5T618_RTC_ADJUST 0xA7
#define RN5T618_RTC_ALARM_Y_SEC 0xA8
#define RN5T618_RTC_DAL_MONTH 0xAC
#define RN5T618_RTC_CTRL1 0xAE
#define RN5T618_RTC_CTRL2 0xAF
#define RN5T618_PREVINDAC 0xb0
#define RN5T618_BATDAC 0xb1
#define RN5T618_CHGCTL1 0xb3
......@@ -242,9 +253,24 @@ enum {
RC5T619,
};
/* RN5T618 IRQ definitions */
enum {
RN5T618_IRQ_SYS = 0,
RN5T618_IRQ_DCDC,
RN5T618_IRQ_RTC,
RN5T618_IRQ_ADC,
RN5T618_IRQ_GPIO,
RN5T618_IRQ_CHG,
RN5T618_NR_IRQS,
};
struct rn5t618 {
struct regmap *regmap;
struct device *dev;
long variant;
int irq;
struct regmap_irq_chip_data *irq_data;
};
#endif /* __LINUX_MFD_RN5T618_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment