2019-05-30 07:57:27 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2012-11-22 18:12:04 +08:00
|
|
|
/*
|
|
|
|
* AS3711 PMIC MFC driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Renesas Electronics Corporation
|
|
|
|
* Author: Guennadi Liakhovetski, <g.liakhovetski@gmx.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/mfd/as3711.h>
|
|
|
|
#include <linux/mfd/core.h>
|
2013-10-16 16:56:48 +08:00
|
|
|
#include <linux/of.h>
|
2012-11-22 18:12:04 +08:00
|
|
|
#include <linux/regmap.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
|
|
|
|
enum {
|
|
|
|
AS3711_REGULATOR,
|
|
|
|
AS3711_BACKLIGHT,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ok to have it static: it is only used during probing and multiple I2C devices
|
|
|
|
* cannot be probed simultaneously. Just make sure to avoid stale data.
|
|
|
|
*/
|
|
|
|
static struct mfd_cell as3711_subdevs[] = {
|
|
|
|
[AS3711_REGULATOR] = {.name = "as3711-regulator",},
|
|
|
|
[AS3711_BACKLIGHT] = {.name = "as3711-backlight",},
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool as3711_volatile_reg(struct device *dev, unsigned int reg)
|
|
|
|
{
|
|
|
|
switch (reg) {
|
|
|
|
case AS3711_GPIO_SIGNAL_IN:
|
|
|
|
case AS3711_INTERRUPT_STATUS_1:
|
|
|
|
case AS3711_INTERRUPT_STATUS_2:
|
|
|
|
case AS3711_INTERRUPT_STATUS_3:
|
|
|
|
case AS3711_CHARGER_STATUS_1:
|
|
|
|
case AS3711_CHARGER_STATUS_2:
|
|
|
|
case AS3711_REG_STATUS:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool as3711_precious_reg(struct device *dev, unsigned int reg)
|
|
|
|
{
|
|
|
|
switch (reg) {
|
|
|
|
case AS3711_INTERRUPT_STATUS_1:
|
|
|
|
case AS3711_INTERRUPT_STATUS_2:
|
|
|
|
case AS3711_INTERRUPT_STATUS_3:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool as3711_readable_reg(struct device *dev, unsigned int reg)
|
|
|
|
{
|
|
|
|
switch (reg) {
|
|
|
|
case AS3711_SD_1_VOLTAGE:
|
|
|
|
case AS3711_SD_2_VOLTAGE:
|
|
|
|
case AS3711_SD_3_VOLTAGE:
|
|
|
|
case AS3711_SD_4_VOLTAGE:
|
|
|
|
case AS3711_LDO_1_VOLTAGE:
|
|
|
|
case AS3711_LDO_2_VOLTAGE:
|
|
|
|
case AS3711_LDO_3_VOLTAGE:
|
|
|
|
case AS3711_LDO_4_VOLTAGE:
|
|
|
|
case AS3711_LDO_5_VOLTAGE:
|
|
|
|
case AS3711_LDO_6_VOLTAGE:
|
|
|
|
case AS3711_LDO_7_VOLTAGE:
|
|
|
|
case AS3711_LDO_8_VOLTAGE:
|
|
|
|
case AS3711_SD_CONTROL:
|
|
|
|
case AS3711_GPIO_SIGNAL_OUT:
|
|
|
|
case AS3711_GPIO_SIGNAL_IN:
|
|
|
|
case AS3711_SD_CONTROL_1:
|
|
|
|
case AS3711_SD_CONTROL_2:
|
|
|
|
case AS3711_CURR_CONTROL:
|
|
|
|
case AS3711_CURR1_VALUE:
|
|
|
|
case AS3711_CURR2_VALUE:
|
|
|
|
case AS3711_CURR3_VALUE:
|
|
|
|
case AS3711_STEPUP_CONTROL_1:
|
|
|
|
case AS3711_STEPUP_CONTROL_2:
|
|
|
|
case AS3711_STEPUP_CONTROL_4:
|
|
|
|
case AS3711_STEPUP_CONTROL_5:
|
|
|
|
case AS3711_REG_STATUS:
|
|
|
|
case AS3711_INTERRUPT_STATUS_1:
|
|
|
|
case AS3711_INTERRUPT_STATUS_2:
|
|
|
|
case AS3711_INTERRUPT_STATUS_3:
|
|
|
|
case AS3711_CHARGER_STATUS_1:
|
|
|
|
case AS3711_CHARGER_STATUS_2:
|
|
|
|
case AS3711_ASIC_ID_1:
|
|
|
|
case AS3711_ASIC_ID_2:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct regmap_config as3711_regmap_config = {
|
|
|
|
.reg_bits = 8,
|
|
|
|
.val_bits = 8,
|
|
|
|
.volatile_reg = as3711_volatile_reg,
|
|
|
|
.readable_reg = as3711_readable_reg,
|
|
|
|
.precious_reg = as3711_precious_reg,
|
2016-02-01 05:56:59 +08:00
|
|
|
.max_register = AS3711_MAX_REG,
|
|
|
|
.num_reg_defaults_raw = AS3711_NUM_REGS,
|
2012-11-22 18:12:04 +08:00
|
|
|
.cache_type = REGCACHE_RBTREE,
|
|
|
|
};
|
|
|
|
|
2013-03-23 00:15:47 +08:00
|
|
|
#ifdef CONFIG_OF
|
2014-05-13 18:58:50 +08:00
|
|
|
static const struct of_device_id as3711_of_match[] = {
|
2013-03-23 00:15:47 +08:00
|
|
|
{.compatible = "ams,as3711",},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2012-11-22 18:12:04 +08:00
|
|
|
static int as3711_i2c_probe(struct i2c_client *client,
|
|
|
|
const struct i2c_device_id *id)
|
|
|
|
{
|
|
|
|
struct as3711 *as3711;
|
2013-03-23 00:15:47 +08:00
|
|
|
struct as3711_platform_data *pdata;
|
2012-11-22 18:12:04 +08:00
|
|
|
unsigned int id1, id2;
|
|
|
|
int ret;
|
|
|
|
|
2013-03-23 00:15:47 +08:00
|
|
|
if (!client->dev.of_node) {
|
2013-07-30 16:10:05 +08:00
|
|
|
pdata = dev_get_platdata(&client->dev);
|
2013-03-23 00:15:47 +08:00
|
|
|
if (!pdata)
|
|
|
|
dev_dbg(&client->dev, "Platform data not found\n");
|
|
|
|
} else {
|
|
|
|
pdata = devm_kzalloc(&client->dev,
|
|
|
|
sizeof(*pdata), GFP_KERNEL);
|
2015-10-28 21:57:44 +08:00
|
|
|
if (!pdata)
|
2013-03-23 00:15:47 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2012-11-22 18:12:04 +08:00
|
|
|
|
|
|
|
as3711 = devm_kzalloc(&client->dev, sizeof(struct as3711), GFP_KERNEL);
|
2015-10-28 21:57:44 +08:00
|
|
|
if (!as3711)
|
2012-11-22 18:12:04 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
as3711->dev = &client->dev;
|
|
|
|
i2c_set_clientdata(client, as3711);
|
|
|
|
|
|
|
|
if (client->irq)
|
|
|
|
dev_notice(&client->dev, "IRQ not supported yet\n");
|
|
|
|
|
|
|
|
as3711->regmap = devm_regmap_init_i2c(client, &as3711_regmap_config);
|
|
|
|
if (IS_ERR(as3711->regmap)) {
|
|
|
|
ret = PTR_ERR(as3711->regmap);
|
2015-10-28 21:57:44 +08:00
|
|
|
dev_err(&client->dev,
|
|
|
|
"regmap initialization failed: %d\n", ret);
|
2012-11-22 18:12:04 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = regmap_read(as3711->regmap, AS3711_ASIC_ID_1, &id1);
|
|
|
|
if (!ret)
|
|
|
|
ret = regmap_read(as3711->regmap, AS3711_ASIC_ID_2, &id2);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&client->dev, "regmap_read() failed: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (id1 != 0x8b)
|
|
|
|
return -ENODEV;
|
|
|
|
dev_info(as3711->dev, "AS3711 detected: %x:%x\n", id1, id2);
|
|
|
|
|
2015-10-28 21:57:44 +08:00
|
|
|
/*
|
|
|
|
* We can reuse as3711_subdevs[],
|
|
|
|
* it will be copied in mfd_add_devices()
|
|
|
|
*/
|
2012-11-22 18:12:04 +08:00
|
|
|
if (pdata) {
|
2015-10-28 21:57:44 +08:00
|
|
|
as3711_subdevs[AS3711_REGULATOR].platform_data =
|
|
|
|
&pdata->regulator;
|
|
|
|
as3711_subdevs[AS3711_REGULATOR].pdata_size =
|
|
|
|
sizeof(pdata->regulator);
|
|
|
|
as3711_subdevs[AS3711_BACKLIGHT].platform_data =
|
|
|
|
&pdata->backlight;
|
|
|
|
as3711_subdevs[AS3711_BACKLIGHT].pdata_size =
|
|
|
|
sizeof(pdata->backlight);
|
2012-11-22 18:12:04 +08:00
|
|
|
} else {
|
|
|
|
as3711_subdevs[AS3711_REGULATOR].platform_data = NULL;
|
|
|
|
as3711_subdevs[AS3711_REGULATOR].pdata_size = 0;
|
|
|
|
as3711_subdevs[AS3711_BACKLIGHT].platform_data = NULL;
|
|
|
|
as3711_subdevs[AS3711_BACKLIGHT].pdata_size = 0;
|
|
|
|
}
|
|
|
|
|
2016-04-08 02:42:58 +08:00
|
|
|
ret = devm_mfd_add_devices(as3711->dev, -1, as3711_subdevs,
|
|
|
|
ARRAY_SIZE(as3711_subdevs), NULL, 0, NULL);
|
2012-11-22 18:12:04 +08:00
|
|
|
if (ret < 0)
|
|
|
|
dev_err(&client->dev, "add mfd devices failed: %d\n", ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct i2c_device_id as3711_i2c_id[] = {
|
|
|
|
{.name = "as3711", .driver_data = 0},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct i2c_driver as3711_i2c_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "as3711",
|
2013-03-23 00:15:47 +08:00
|
|
|
.of_match_table = of_match_ptr(as3711_of_match),
|
|
|
|
},
|
2012-11-22 18:12:04 +08:00
|
|
|
.probe = as3711_i2c_probe,
|
|
|
|
.id_table = as3711_i2c_id,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init as3711_i2c_init(void)
|
|
|
|
{
|
|
|
|
return i2c_add_driver(&as3711_i2c_driver);
|
|
|
|
}
|
|
|
|
/* Initialise early */
|
|
|
|
subsys_initcall(as3711_i2c_init);
|