2019-04-19 03:58:24 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
//
|
|
|
|
// FAN53555 Fairchild Digitally Programmable TinyBuck Regulator Driver.
|
|
|
|
//
|
|
|
|
// Supported Part Numbers:
|
|
|
|
// FAN53555UC00X/01X/03X/04X/05X
|
|
|
|
//
|
|
|
|
// Copyright (c) 2012 Marvell Technology Ltd.
|
|
|
|
// Yunfan Zhang <yfzhang@marvell.com>
|
|
|
|
|
2012-09-08 14:52:18 +04:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/param.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/regulator/driver.h>
|
|
|
|
#include <linux/regulator/machine.h>
|
2014-09-16 23:22:53 +04:00
|
|
|
#include <linux/regulator/of_regulator.h>
|
|
|
|
#include <linux/of_device.h>
|
2012-09-08 14:52:18 +04:00
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/regmap.h>
|
|
|
|
#include <linux/regulator/fan53555.h>
|
|
|
|
|
|
|
|
/* Voltage setting */
|
|
|
|
#define FAN53555_VSEL0 0x00
|
|
|
|
#define FAN53555_VSEL1 0x01
|
2021-04-22 00:03:38 +03:00
|
|
|
|
|
|
|
#define TCS4525_VSEL0 0x11
|
|
|
|
#define TCS4525_VSEL1 0x10
|
|
|
|
#define TCS4525_TIME 0x13
|
|
|
|
#define TCS4525_COMMAND 0x14
|
|
|
|
|
2012-09-08 14:52:18 +04:00
|
|
|
/* Control register */
|
|
|
|
#define FAN53555_CONTROL 0x02
|
|
|
|
/* IC Type */
|
|
|
|
#define FAN53555_ID1 0x03
|
|
|
|
/* IC mask version */
|
|
|
|
#define FAN53555_ID2 0x04
|
|
|
|
/* Monitor register */
|
|
|
|
#define FAN53555_MONITOR 0x05
|
|
|
|
|
|
|
|
/* VSEL bit definitions */
|
|
|
|
#define VSEL_BUCK_EN (1 << 7)
|
|
|
|
#define VSEL_MODE (1 << 6)
|
|
|
|
/* Chip ID and Verison */
|
|
|
|
#define DIE_ID 0x0F /* ID1 */
|
|
|
|
#define DIE_REV 0x0F /* ID2 */
|
|
|
|
/* Control bit definitions */
|
|
|
|
#define CTL_OUTPUT_DISCHG (1 << 7)
|
|
|
|
#define CTL_SLEW_MASK (0x7 << 4)
|
|
|
|
#define CTL_SLEW_SHIFT 4
|
|
|
|
#define CTL_RESET (1 << 2)
|
2019-02-21 03:43:03 +03:00
|
|
|
#define CTL_MODE_VSEL0_MODE BIT(0)
|
|
|
|
#define CTL_MODE_VSEL1_MODE BIT(1)
|
2012-09-08 14:52:18 +04:00
|
|
|
|
|
|
|
#define FAN53555_NVOLTAGES 64 /* Numbers of voltages */
|
2019-02-21 03:43:03 +03:00
|
|
|
#define FAN53526_NVOLTAGES 128
|
2021-04-22 00:03:38 +03:00
|
|
|
|
|
|
|
#define TCS_VSEL0_MODE (1 << 7)
|
|
|
|
#define TCS_VSEL1_MODE (1 << 6)
|
|
|
|
|
|
|
|
#define TCS_SLEW_SHIFT 3
|
|
|
|
#define TCS_SLEW_MASK (0x3 < 3)
|
2012-09-08 14:52:18 +04:00
|
|
|
|
2014-09-16 23:22:54 +04:00
|
|
|
enum fan53555_vendor {
|
2019-02-21 03:43:03 +03:00
|
|
|
FAN53526_VENDOR_FAIRCHILD = 0,
|
|
|
|
FAN53555_VENDOR_FAIRCHILD,
|
2014-09-16 23:22:54 +04:00
|
|
|
FAN53555_VENDOR_SILERGY,
|
2021-05-12 00:13:35 +03:00
|
|
|
FAN53526_VENDOR_TCS,
|
2014-09-16 23:22:54 +04:00
|
|
|
};
|
|
|
|
|
2019-02-21 03:43:03 +03:00
|
|
|
enum {
|
|
|
|
FAN53526_CHIP_ID_01 = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
FAN53526_CHIP_REV_08 = 8,
|
|
|
|
};
|
|
|
|
|
2012-09-08 14:52:18 +04:00
|
|
|
/* IC Type */
|
|
|
|
enum {
|
|
|
|
FAN53555_CHIP_ID_00 = 0,
|
|
|
|
FAN53555_CHIP_ID_01,
|
|
|
|
FAN53555_CHIP_ID_02,
|
|
|
|
FAN53555_CHIP_ID_03,
|
|
|
|
FAN53555_CHIP_ID_04,
|
|
|
|
FAN53555_CHIP_ID_05,
|
2016-04-20 11:01:07 +03:00
|
|
|
FAN53555_CHIP_ID_08 = 8,
|
2012-09-08 14:52:18 +04:00
|
|
|
};
|
|
|
|
|
2021-05-12 00:13:34 +03:00
|
|
|
enum {
|
|
|
|
TCS4525_CHIP_ID_12 = 12,
|
|
|
|
};
|
|
|
|
|
2021-06-02 14:29:47 +03:00
|
|
|
enum {
|
|
|
|
TCS4526_CHIP_ID_00 = 0,
|
|
|
|
};
|
|
|
|
|
2016-04-20 11:01:08 +03:00
|
|
|
/* IC mask revision */
|
|
|
|
enum {
|
|
|
|
FAN53555_CHIP_REV_00 = 0x3,
|
|
|
|
FAN53555_CHIP_REV_13 = 0xf,
|
|
|
|
};
|
|
|
|
|
2014-09-16 23:22:54 +04:00
|
|
|
enum {
|
|
|
|
SILERGY_SYR82X = 8,
|
2019-11-06 19:12:11 +03:00
|
|
|
SILERGY_SYR83X = 9,
|
2014-09-16 23:22:54 +04:00
|
|
|
};
|
|
|
|
|
2012-09-08 14:52:18 +04:00
|
|
|
struct fan53555_device_info {
|
2014-09-16 23:22:54 +04:00
|
|
|
enum fan53555_vendor vendor;
|
2012-09-08 14:52:18 +04:00
|
|
|
struct device *dev;
|
|
|
|
struct regulator_desc desc;
|
|
|
|
struct regulator_init_data *regulator;
|
|
|
|
/* IC Type and Rev */
|
|
|
|
int chip_id;
|
|
|
|
int chip_rev;
|
|
|
|
/* Voltage setting register */
|
|
|
|
unsigned int vol_reg;
|
|
|
|
unsigned int sleep_reg;
|
|
|
|
/* Voltage range and step(linear) */
|
|
|
|
unsigned int vsel_min;
|
|
|
|
unsigned int vsel_step;
|
2019-02-21 03:43:03 +03:00
|
|
|
unsigned int vsel_count;
|
|
|
|
/* Mode */
|
|
|
|
unsigned int mode_reg;
|
|
|
|
unsigned int mode_mask;
|
2012-09-08 14:52:18 +04:00
|
|
|
/* Sleep voltage cache */
|
|
|
|
unsigned int sleep_vol_cache;
|
2021-04-22 00:03:38 +03:00
|
|
|
/* Slew rate */
|
|
|
|
unsigned int slew_reg;
|
|
|
|
unsigned int slew_mask;
|
2021-05-25 15:40:17 +03:00
|
|
|
const unsigned int *ramp_delay_table;
|
|
|
|
unsigned int n_ramp_values;
|
2021-04-22 00:03:38 +03:00
|
|
|
unsigned int slew_rate;
|
2012-09-08 14:52:18 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static int fan53555_set_suspend_voltage(struct regulator_dev *rdev, int uV)
|
|
|
|
{
|
|
|
|
struct fan53555_device_info *di = rdev_get_drvdata(rdev);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (di->sleep_vol_cache == uV)
|
|
|
|
return 0;
|
|
|
|
ret = regulator_map_voltage_linear(rdev, uV, uV);
|
|
|
|
if (ret < 0)
|
2014-02-18 14:41:04 +04:00
|
|
|
return ret;
|
2019-04-19 03:58:23 +03:00
|
|
|
ret = regmap_update_bits(rdev->regmap, di->sleep_reg,
|
2019-02-21 03:43:03 +03:00
|
|
|
di->desc.vsel_mask, ret);
|
2012-09-08 14:52:18 +04:00
|
|
|
if (ret < 0)
|
2014-02-18 14:41:04 +04:00
|
|
|
return ret;
|
2012-09-08 14:52:18 +04:00
|
|
|
/* Cache the sleep voltage setting.
|
|
|
|
* Might not be the real voltage which is rounded */
|
|
|
|
di->sleep_vol_cache = uV;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-01-12 14:05:56 +03:00
|
|
|
static int fan53555_set_suspend_enable(struct regulator_dev *rdev)
|
|
|
|
{
|
|
|
|
struct fan53555_device_info *di = rdev_get_drvdata(rdev);
|
|
|
|
|
2019-04-19 03:58:23 +03:00
|
|
|
return regmap_update_bits(rdev->regmap, di->sleep_reg,
|
2016-01-12 14:05:56 +03:00
|
|
|
VSEL_BUCK_EN, VSEL_BUCK_EN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fan53555_set_suspend_disable(struct regulator_dev *rdev)
|
|
|
|
{
|
|
|
|
struct fan53555_device_info *di = rdev_get_drvdata(rdev);
|
|
|
|
|
2019-04-19 03:58:23 +03:00
|
|
|
return regmap_update_bits(rdev->regmap, di->sleep_reg,
|
2016-01-12 14:05:56 +03:00
|
|
|
VSEL_BUCK_EN, 0);
|
|
|
|
}
|
|
|
|
|
2012-09-08 14:52:18 +04:00
|
|
|
static int fan53555_set_mode(struct regulator_dev *rdev, unsigned int mode)
|
|
|
|
{
|
|
|
|
struct fan53555_device_info *di = rdev_get_drvdata(rdev);
|
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case REGULATOR_MODE_FAST:
|
2019-04-19 03:58:23 +03:00
|
|
|
regmap_update_bits(rdev->regmap, di->mode_reg,
|
2019-02-21 03:43:03 +03:00
|
|
|
di->mode_mask, di->mode_mask);
|
2012-09-08 14:52:18 +04:00
|
|
|
break;
|
|
|
|
case REGULATOR_MODE_NORMAL:
|
2019-04-19 03:58:23 +03:00
|
|
|
regmap_update_bits(rdev->regmap, di->vol_reg, di->mode_mask, 0);
|
2012-09-08 14:52:18 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int fan53555_get_mode(struct regulator_dev *rdev)
|
|
|
|
{
|
|
|
|
struct fan53555_device_info *di = rdev_get_drvdata(rdev);
|
|
|
|
unsigned int val;
|
|
|
|
int ret = 0;
|
|
|
|
|
2019-04-19 03:58:23 +03:00
|
|
|
ret = regmap_read(rdev->regmap, di->mode_reg, &val);
|
2012-09-08 14:52:18 +04:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2019-02-21 03:43:03 +03:00
|
|
|
if (val & di->mode_mask)
|
2012-09-08 14:52:18 +04:00
|
|
|
return REGULATOR_MODE_FAST;
|
|
|
|
else
|
|
|
|
return REGULATOR_MODE_NORMAL;
|
|
|
|
}
|
|
|
|
|
2021-05-25 15:40:17 +03:00
|
|
|
static const unsigned int slew_rates[] = {
|
2014-09-16 19:54:01 +04:00
|
|
|
64000,
|
|
|
|
32000,
|
|
|
|
16000,
|
|
|
|
8000,
|
|
|
|
4000,
|
|
|
|
2000,
|
|
|
|
1000,
|
|
|
|
500,
|
|
|
|
};
|
|
|
|
|
2021-05-25 15:40:17 +03:00
|
|
|
static const unsigned int tcs_slew_rates[] = {
|
2021-04-22 00:03:38 +03:00
|
|
|
18700,
|
|
|
|
9300,
|
|
|
|
4600,
|
|
|
|
2300,
|
|
|
|
};
|
|
|
|
|
2017-01-28 17:02:05 +03:00
|
|
|
static const struct regulator_ops fan53555_regulator_ops = {
|
2012-09-08 14:52:18 +04:00
|
|
|
.set_voltage_sel = regulator_set_voltage_sel_regmap,
|
|
|
|
.get_voltage_sel = regulator_get_voltage_sel_regmap,
|
2015-05-26 19:19:45 +03:00
|
|
|
.set_voltage_time_sel = regulator_set_voltage_time_sel,
|
2012-09-08 14:52:18 +04:00
|
|
|
.map_voltage = regulator_map_voltage_linear,
|
|
|
|
.list_voltage = regulator_list_voltage_linear,
|
|
|
|
.set_suspend_voltage = fan53555_set_suspend_voltage,
|
|
|
|
.enable = regulator_enable_regmap,
|
|
|
|
.disable = regulator_disable_regmap,
|
|
|
|
.is_enabled = regulator_is_enabled_regmap,
|
|
|
|
.set_mode = fan53555_set_mode,
|
|
|
|
.get_mode = fan53555_get_mode,
|
2021-05-25 15:40:17 +03:00
|
|
|
.set_ramp_delay = regulator_set_ramp_delay_regmap,
|
2016-01-12 14:05:56 +03:00
|
|
|
.set_suspend_enable = fan53555_set_suspend_enable,
|
|
|
|
.set_suspend_disable = fan53555_set_suspend_disable,
|
2012-09-08 14:52:18 +04:00
|
|
|
};
|
|
|
|
|
2019-02-21 03:43:03 +03:00
|
|
|
static int fan53526_voltages_setup_fairchild(struct fan53555_device_info *di)
|
|
|
|
{
|
|
|
|
/* Init voltage range and step */
|
|
|
|
switch (di->chip_id) {
|
|
|
|
case FAN53526_CHIP_ID_01:
|
|
|
|
switch (di->chip_rev) {
|
|
|
|
case FAN53526_CHIP_REV_08:
|
|
|
|
di->vsel_min = 600000;
|
|
|
|
di->vsel_step = 6250;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_err(di->dev,
|
|
|
|
"Chip ID %d with rev %d not supported!\n",
|
|
|
|
di->chip_id, di->chip_rev);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_err(di->dev,
|
|
|
|
"Chip ID %d not supported!\n", di->chip_id);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2021-05-25 15:40:16 +03:00
|
|
|
di->slew_reg = FAN53555_CONTROL;
|
|
|
|
di->slew_mask = CTL_SLEW_MASK;
|
2021-05-25 15:40:17 +03:00
|
|
|
di->ramp_delay_table = slew_rates;
|
|
|
|
di->n_ramp_values = ARRAY_SIZE(slew_rates);
|
2019-02-21 03:43:03 +03:00
|
|
|
di->vsel_count = FAN53526_NVOLTAGES;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-16 23:22:54 +04:00
|
|
|
static int fan53555_voltages_setup_fairchild(struct fan53555_device_info *di)
|
|
|
|
{
|
|
|
|
/* Init voltage range and step */
|
|
|
|
switch (di->chip_id) {
|
|
|
|
case FAN53555_CHIP_ID_00:
|
2016-04-20 11:01:08 +03:00
|
|
|
switch (di->chip_rev) {
|
|
|
|
case FAN53555_CHIP_REV_00:
|
|
|
|
di->vsel_min = 600000;
|
|
|
|
di->vsel_step = 10000;
|
|
|
|
break;
|
|
|
|
case FAN53555_CHIP_REV_13:
|
|
|
|
di->vsel_min = 800000;
|
|
|
|
di->vsel_step = 10000;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_err(di->dev,
|
|
|
|
"Chip ID %d with rev %d not supported!\n",
|
|
|
|
di->chip_id, di->chip_rev);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
2014-09-16 23:22:54 +04:00
|
|
|
case FAN53555_CHIP_ID_01:
|
|
|
|
case FAN53555_CHIP_ID_03:
|
|
|
|
case FAN53555_CHIP_ID_05:
|
2016-04-20 11:01:07 +03:00
|
|
|
case FAN53555_CHIP_ID_08:
|
2014-09-16 23:22:54 +04:00
|
|
|
di->vsel_min = 600000;
|
|
|
|
di->vsel_step = 10000;
|
|
|
|
break;
|
|
|
|
case FAN53555_CHIP_ID_04:
|
|
|
|
di->vsel_min = 603000;
|
|
|
|
di->vsel_step = 12826;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_err(di->dev,
|
|
|
|
"Chip ID %d not supported!\n", di->chip_id);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2021-04-22 00:03:38 +03:00
|
|
|
di->slew_reg = FAN53555_CONTROL;
|
|
|
|
di->slew_mask = CTL_SLEW_MASK;
|
2021-05-25 15:40:17 +03:00
|
|
|
di->ramp_delay_table = slew_rates;
|
|
|
|
di->n_ramp_values = ARRAY_SIZE(slew_rates);
|
2019-02-21 03:43:03 +03:00
|
|
|
di->vsel_count = FAN53555_NVOLTAGES;
|
|
|
|
|
2014-09-16 23:22:54 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fan53555_voltages_setup_silergy(struct fan53555_device_info *di)
|
|
|
|
{
|
|
|
|
/* Init voltage range and step */
|
|
|
|
switch (di->chip_id) {
|
|
|
|
case SILERGY_SYR82X:
|
2019-11-06 19:12:11 +03:00
|
|
|
case SILERGY_SYR83X:
|
2014-09-16 23:22:54 +04:00
|
|
|
di->vsel_min = 712500;
|
|
|
|
di->vsel_step = 12500;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_err(di->dev,
|
|
|
|
"Chip ID %d not supported!\n", di->chip_id);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2021-04-22 00:03:38 +03:00
|
|
|
di->slew_reg = FAN53555_CONTROL;
|
|
|
|
di->slew_mask = CTL_SLEW_MASK;
|
2021-05-25 15:40:17 +03:00
|
|
|
di->ramp_delay_table = slew_rates;
|
|
|
|
di->n_ramp_values = ARRAY_SIZE(slew_rates);
|
2019-02-21 03:43:03 +03:00
|
|
|
di->vsel_count = FAN53555_NVOLTAGES;
|
|
|
|
|
2014-09-16 23:22:54 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-05-12 00:13:35 +03:00
|
|
|
static int fan53526_voltages_setup_tcs(struct fan53555_device_info *di)
|
2021-04-22 00:03:38 +03:00
|
|
|
{
|
2021-05-12 00:13:34 +03:00
|
|
|
switch (di->chip_id) {
|
|
|
|
case TCS4525_CHIP_ID_12:
|
2021-06-02 14:29:47 +03:00
|
|
|
case TCS4526_CHIP_ID_00:
|
2021-05-12 00:13:34 +03:00
|
|
|
di->slew_reg = TCS4525_TIME;
|
|
|
|
di->slew_mask = TCS_SLEW_MASK;
|
2021-05-25 15:40:17 +03:00
|
|
|
di->ramp_delay_table = tcs_slew_rates;
|
|
|
|
di->n_ramp_values = ARRAY_SIZE(tcs_slew_rates);
|
2021-04-22 00:03:38 +03:00
|
|
|
|
2021-05-12 00:13:34 +03:00
|
|
|
/* Init voltage range and step */
|
|
|
|
di->vsel_min = 600000;
|
|
|
|
di->vsel_step = 6250;
|
|
|
|
di->vsel_count = FAN53526_NVOLTAGES;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_err(di->dev, "Chip ID %d not supported!\n", di->chip_id);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2021-04-22 00:03:38 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-08 14:52:18 +04:00
|
|
|
/* For 00,01,03,05 options:
|
|
|
|
* VOUT = 0.60V + NSELx * 10mV, from 0.60 to 1.23V.
|
|
|
|
* For 04 option:
|
|
|
|
* VOUT = 0.603V + NSELx * 12.826mV, from 0.603 to 1.411V.
|
|
|
|
* */
|
|
|
|
static int fan53555_device_setup(struct fan53555_device_info *di,
|
|
|
|
struct fan53555_platform_data *pdata)
|
|
|
|
{
|
2014-09-16 23:22:54 +04:00
|
|
|
int ret = 0;
|
|
|
|
|
2012-09-08 14:52:18 +04:00
|
|
|
/* Setup voltage control register */
|
2021-04-22 00:03:38 +03:00
|
|
|
switch (di->vendor) {
|
|
|
|
case FAN53526_VENDOR_FAIRCHILD:
|
|
|
|
case FAN53555_VENDOR_FAIRCHILD:
|
|
|
|
case FAN53555_VENDOR_SILERGY:
|
|
|
|
switch (pdata->sleep_vsel_id) {
|
|
|
|
case FAN53555_VSEL_ID_0:
|
|
|
|
di->sleep_reg = FAN53555_VSEL0;
|
|
|
|
di->vol_reg = FAN53555_VSEL1;
|
|
|
|
break;
|
|
|
|
case FAN53555_VSEL_ID_1:
|
|
|
|
di->sleep_reg = FAN53555_VSEL1;
|
|
|
|
di->vol_reg = FAN53555_VSEL0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_err(di->dev, "Invalid VSEL ID!\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2012-09-08 14:52:18 +04:00
|
|
|
break;
|
2021-05-12 00:13:35 +03:00
|
|
|
case FAN53526_VENDOR_TCS:
|
2021-04-22 00:03:38 +03:00
|
|
|
switch (pdata->sleep_vsel_id) {
|
|
|
|
case FAN53555_VSEL_ID_0:
|
|
|
|
di->sleep_reg = TCS4525_VSEL0;
|
|
|
|
di->vol_reg = TCS4525_VSEL1;
|
|
|
|
break;
|
|
|
|
case FAN53555_VSEL_ID_1:
|
|
|
|
di->sleep_reg = TCS4525_VSEL1;
|
|
|
|
di->vol_reg = TCS4525_VSEL0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_err(di->dev, "Invalid VSEL ID!\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2012-09-08 14:52:18 +04:00
|
|
|
break;
|
|
|
|
default:
|
2021-04-22 00:03:38 +03:00
|
|
|
dev_err(di->dev, "vendor %d not supported!\n", di->vendor);
|
2012-09-08 14:52:18 +04:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2014-09-16 23:22:54 +04:00
|
|
|
|
2019-02-21 03:43:03 +03:00
|
|
|
/* Setup mode control register */
|
|
|
|
switch (di->vendor) {
|
|
|
|
case FAN53526_VENDOR_FAIRCHILD:
|
|
|
|
di->mode_reg = FAN53555_CONTROL;
|
|
|
|
|
|
|
|
switch (pdata->sleep_vsel_id) {
|
|
|
|
case FAN53555_VSEL_ID_0:
|
|
|
|
di->mode_mask = CTL_MODE_VSEL1_MODE;
|
|
|
|
break;
|
|
|
|
case FAN53555_VSEL_ID_1:
|
|
|
|
di->mode_mask = CTL_MODE_VSEL0_MODE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FAN53555_VENDOR_FAIRCHILD:
|
|
|
|
case FAN53555_VENDOR_SILERGY:
|
|
|
|
di->mode_reg = di->vol_reg;
|
|
|
|
di->mode_mask = VSEL_MODE;
|
|
|
|
break;
|
2021-05-12 00:13:35 +03:00
|
|
|
case FAN53526_VENDOR_TCS:
|
2021-04-22 00:03:38 +03:00
|
|
|
di->mode_reg = TCS4525_COMMAND;
|
|
|
|
|
|
|
|
switch (pdata->sleep_vsel_id) {
|
|
|
|
case FAN53555_VSEL_ID_0:
|
|
|
|
di->mode_mask = TCS_VSEL1_MODE;
|
|
|
|
break;
|
|
|
|
case FAN53555_VSEL_ID_1:
|
|
|
|
di->mode_mask = TCS_VSEL0_MODE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2019-02-21 03:43:03 +03:00
|
|
|
default:
|
|
|
|
dev_err(di->dev, "vendor %d not supported!\n", di->vendor);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup voltage range */
|
2014-09-16 23:22:54 +04:00
|
|
|
switch (di->vendor) {
|
2019-02-21 03:43:03 +03:00
|
|
|
case FAN53526_VENDOR_FAIRCHILD:
|
|
|
|
ret = fan53526_voltages_setup_fairchild(di);
|
|
|
|
break;
|
2014-09-16 23:22:54 +04:00
|
|
|
case FAN53555_VENDOR_FAIRCHILD:
|
|
|
|
ret = fan53555_voltages_setup_fairchild(di);
|
2012-09-08 14:52:18 +04:00
|
|
|
break;
|
2014-09-16 23:22:54 +04:00
|
|
|
case FAN53555_VENDOR_SILERGY:
|
|
|
|
ret = fan53555_voltages_setup_silergy(di);
|
2012-09-08 14:52:18 +04:00
|
|
|
break;
|
2021-05-12 00:13:35 +03:00
|
|
|
case FAN53526_VENDOR_TCS:
|
|
|
|
ret = fan53526_voltages_setup_tcs(di);
|
2021-04-22 00:03:38 +03:00
|
|
|
break;
|
2012-09-08 14:52:18 +04:00
|
|
|
default:
|
2014-09-18 17:48:48 +04:00
|
|
|
dev_err(di->dev, "vendor %d not supported!\n", di->vendor);
|
2012-09-08 14:52:18 +04:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2014-09-16 19:54:01 +04:00
|
|
|
|
2014-09-16 23:22:54 +04:00
|
|
|
return ret;
|
2012-09-08 14:52:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int fan53555_regulator_register(struct fan53555_device_info *di,
|
|
|
|
struct regulator_config *config)
|
|
|
|
{
|
|
|
|
struct regulator_desc *rdesc = &di->desc;
|
2019-04-19 03:58:23 +03:00
|
|
|
struct regulator_dev *rdev;
|
2012-09-08 14:52:18 +04:00
|
|
|
|
|
|
|
rdesc->name = "fan53555-reg";
|
2014-09-14 23:23:01 +04:00
|
|
|
rdesc->supply_name = "vin";
|
2012-09-08 14:52:18 +04:00
|
|
|
rdesc->ops = &fan53555_regulator_ops;
|
|
|
|
rdesc->type = REGULATOR_VOLTAGE;
|
2019-02-21 03:43:03 +03:00
|
|
|
rdesc->n_voltages = di->vsel_count;
|
2012-09-08 14:52:18 +04:00
|
|
|
rdesc->enable_reg = di->vol_reg;
|
|
|
|
rdesc->enable_mask = VSEL_BUCK_EN;
|
|
|
|
rdesc->min_uV = di->vsel_min;
|
|
|
|
rdesc->uV_step = di->vsel_step;
|
|
|
|
rdesc->vsel_reg = di->vol_reg;
|
2019-02-21 03:43:03 +03:00
|
|
|
rdesc->vsel_mask = di->vsel_count - 1;
|
2021-05-25 15:40:17 +03:00
|
|
|
rdesc->ramp_reg = di->slew_reg;
|
|
|
|
rdesc->ramp_mask = di->slew_mask;
|
|
|
|
rdesc->ramp_delay_table = di->ramp_delay_table;
|
|
|
|
rdesc->n_ramp_values = di->n_ramp_values;
|
2012-09-08 14:52:18 +04:00
|
|
|
rdesc->owner = THIS_MODULE;
|
|
|
|
|
2019-04-19 03:58:23 +03:00
|
|
|
rdev = devm_regulator_register(di->dev, &di->desc, config);
|
|
|
|
return PTR_ERR_OR_ZERO(rdev);
|
2012-09-08 14:52:18 +04:00
|
|
|
}
|
|
|
|
|
2015-01-05 12:04:19 +03:00
|
|
|
static const struct regmap_config fan53555_regmap_config = {
|
2012-09-08 14:52:18 +04:00
|
|
|
.reg_bits = 8,
|
|
|
|
.val_bits = 8,
|
|
|
|
};
|
|
|
|
|
2014-09-16 23:22:53 +04:00
|
|
|
static struct fan53555_platform_data *fan53555_parse_dt(struct device *dev,
|
2014-11-10 16:43:53 +03:00
|
|
|
struct device_node *np,
|
|
|
|
const struct regulator_desc *desc)
|
2014-09-16 23:22:53 +04:00
|
|
|
{
|
|
|
|
struct fan53555_platform_data *pdata;
|
|
|
|
int ret;
|
|
|
|
u32 tmp;
|
|
|
|
|
|
|
|
pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
|
|
|
|
if (!pdata)
|
|
|
|
return NULL;
|
|
|
|
|
2014-11-10 16:43:53 +03:00
|
|
|
pdata->regulator = of_get_regulator_init_data(dev, np, desc);
|
2014-09-16 23:22:53 +04:00
|
|
|
|
|
|
|
ret = of_property_read_u32(np, "fcs,suspend-voltage-selector",
|
|
|
|
&tmp);
|
|
|
|
if (!ret)
|
|
|
|
pdata->sleep_vsel_id = tmp;
|
|
|
|
|
|
|
|
return pdata;
|
|
|
|
}
|
|
|
|
|
2020-08-21 06:13:24 +03:00
|
|
|
static const struct of_device_id __maybe_unused fan53555_dt_ids[] = {
|
2014-09-16 23:22:53 +04:00
|
|
|
{
|
2019-02-21 03:43:03 +03:00
|
|
|
.compatible = "fcs,fan53526",
|
|
|
|
.data = (void *)FAN53526_VENDOR_FAIRCHILD,
|
|
|
|
}, {
|
2014-09-16 23:22:53 +04:00
|
|
|
.compatible = "fcs,fan53555",
|
2014-09-16 23:22:54 +04:00
|
|
|
.data = (void *)FAN53555_VENDOR_FAIRCHILD
|
|
|
|
}, {
|
|
|
|
.compatible = "silergy,syr827",
|
|
|
|
.data = (void *)FAN53555_VENDOR_SILERGY,
|
|
|
|
}, {
|
|
|
|
.compatible = "silergy,syr828",
|
|
|
|
.data = (void *)FAN53555_VENDOR_SILERGY,
|
2021-04-22 00:03:38 +03:00
|
|
|
}, {
|
|
|
|
.compatible = "tcs,tcs4525",
|
2021-05-12 00:13:35 +03:00
|
|
|
.data = (void *)FAN53526_VENDOR_TCS
|
2021-06-02 14:29:47 +03:00
|
|
|
}, {
|
|
|
|
.compatible = "tcs,tcs4526",
|
|
|
|
.data = (void *)FAN53526_VENDOR_TCS
|
2014-09-16 23:22:53 +04:00
|
|
|
},
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, fan53555_dt_ids);
|
|
|
|
|
2012-11-19 22:22:22 +04:00
|
|
|
static int fan53555_regulator_probe(struct i2c_client *client,
|
2012-09-08 14:52:18 +04:00
|
|
|
const struct i2c_device_id *id)
|
|
|
|
{
|
2014-09-16 23:22:53 +04:00
|
|
|
struct device_node *np = client->dev.of_node;
|
2012-09-08 14:52:18 +04:00
|
|
|
struct fan53555_device_info *di;
|
|
|
|
struct fan53555_platform_data *pdata;
|
|
|
|
struct regulator_config config = { };
|
2019-04-19 03:58:23 +03:00
|
|
|
struct regmap *regmap;
|
2012-09-08 14:52:18 +04:00
|
|
|
unsigned int val;
|
|
|
|
int ret;
|
|
|
|
|
2014-11-10 16:43:53 +03:00
|
|
|
di = devm_kzalloc(&client->dev, sizeof(struct fan53555_device_info),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!di)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2013-07-30 12:20:47 +04:00
|
|
|
pdata = dev_get_platdata(&client->dev);
|
2014-09-16 23:22:53 +04:00
|
|
|
if (!pdata)
|
2014-11-10 16:43:53 +03:00
|
|
|
pdata = fan53555_parse_dt(&client->dev, np, &di->desc);
|
2014-09-16 23:22:53 +04:00
|
|
|
|
2012-09-08 14:52:18 +04:00
|
|
|
if (!pdata || !pdata->regulator) {
|
|
|
|
dev_err(&client->dev, "Platform data not found!\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2014-09-18 17:49:38 +04:00
|
|
|
di->regulator = pdata->regulator;
|
2014-09-16 23:22:54 +04:00
|
|
|
if (client->dev.of_node) {
|
2017-07-20 11:42:17 +03:00
|
|
|
di->vendor =
|
|
|
|
(unsigned long)of_device_get_match_data(&client->dev);
|
2014-09-16 23:22:54 +04:00
|
|
|
} else {
|
2014-09-16 23:22:53 +04:00
|
|
|
/* if no ramp constraint set, get the pdata ramp_delay */
|
|
|
|
if (!di->regulator->constraints.ramp_delay) {
|
2019-02-24 06:21:46 +03:00
|
|
|
if (pdata->slew_rate >= ARRAY_SIZE(slew_rates)) {
|
|
|
|
dev_err(&client->dev, "Invalid slew_rate\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2014-09-16 19:54:01 +04:00
|
|
|
|
2014-09-16 23:22:53 +04:00
|
|
|
di->regulator->constraints.ramp_delay
|
2019-02-24 06:21:46 +03:00
|
|
|
= slew_rates[pdata->slew_rate];
|
2014-09-16 23:22:53 +04:00
|
|
|
}
|
2014-09-16 23:22:54 +04:00
|
|
|
|
|
|
|
di->vendor = id->driver_data;
|
2014-09-16 19:54:01 +04:00
|
|
|
}
|
|
|
|
|
2019-04-19 03:58:23 +03:00
|
|
|
regmap = devm_regmap_init_i2c(client, &fan53555_regmap_config);
|
|
|
|
if (IS_ERR(regmap)) {
|
2012-09-08 14:52:18 +04:00
|
|
|
dev_err(&client->dev, "Failed to allocate regmap!\n");
|
2019-04-19 03:58:23 +03:00
|
|
|
return PTR_ERR(regmap);
|
2012-09-08 14:52:18 +04:00
|
|
|
}
|
|
|
|
di->dev = &client->dev;
|
|
|
|
i2c_set_clientdata(client, di);
|
|
|
|
/* Get chip ID */
|
2019-04-19 03:58:23 +03:00
|
|
|
ret = regmap_read(regmap, FAN53555_ID1, &val);
|
2012-09-08 14:52:18 +04:00
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&client->dev, "Failed to get chip ID!\n");
|
2014-02-18 14:41:04 +04:00
|
|
|
return ret;
|
2012-09-08 14:52:18 +04:00
|
|
|
}
|
|
|
|
di->chip_id = val & DIE_ID;
|
|
|
|
/* Get chip revision */
|
2019-04-19 03:58:23 +03:00
|
|
|
ret = regmap_read(regmap, FAN53555_ID2, &val);
|
2012-09-08 14:52:18 +04:00
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&client->dev, "Failed to get chip Rev!\n");
|
2014-02-18 14:41:04 +04:00
|
|
|
return ret;
|
2012-09-08 14:52:18 +04:00
|
|
|
}
|
|
|
|
di->chip_rev = val & DIE_REV;
|
|
|
|
dev_info(&client->dev, "FAN53555 Option[%d] Rev[%d] Detected!\n",
|
|
|
|
di->chip_id, di->chip_rev);
|
|
|
|
/* Device init */
|
|
|
|
ret = fan53555_device_setup(di, pdata);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&client->dev, "Failed to setup device!\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
/* Register regulator */
|
|
|
|
config.dev = di->dev;
|
|
|
|
config.init_data = di->regulator;
|
2019-04-19 03:58:23 +03:00
|
|
|
config.regmap = regmap;
|
2012-09-08 14:52:18 +04:00
|
|
|
config.driver_data = di;
|
2014-09-16 23:22:53 +04:00
|
|
|
config.of_node = np;
|
|
|
|
|
2012-09-08 14:52:18 +04:00
|
|
|
ret = fan53555_regulator_register(di, &config);
|
|
|
|
if (ret < 0)
|
|
|
|
dev_err(&client->dev, "Failed to register regulator!\n");
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct i2c_device_id fan53555_id[] = {
|
2014-09-16 23:22:54 +04:00
|
|
|
{
|
2019-02-21 03:43:03 +03:00
|
|
|
.name = "fan53526",
|
|
|
|
.driver_data = FAN53526_VENDOR_FAIRCHILD
|
|
|
|
}, {
|
2014-09-16 23:22:54 +04:00
|
|
|
.name = "fan53555",
|
|
|
|
.driver_data = FAN53555_VENDOR_FAIRCHILD
|
|
|
|
}, {
|
2017-08-21 15:47:43 +03:00
|
|
|
.name = "syr827",
|
|
|
|
.driver_data = FAN53555_VENDOR_SILERGY
|
|
|
|
}, {
|
|
|
|
.name = "syr828",
|
2014-09-16 23:22:54 +04:00
|
|
|
.driver_data = FAN53555_VENDOR_SILERGY
|
2021-04-22 00:03:38 +03:00
|
|
|
}, {
|
|
|
|
.name = "tcs4525",
|
2021-05-12 00:13:35 +03:00
|
|
|
.driver_data = FAN53526_VENDOR_TCS
|
2021-06-02 14:29:47 +03:00
|
|
|
}, {
|
|
|
|
.name = "tcs4526",
|
|
|
|
.driver_data = FAN53526_VENDOR_TCS
|
2014-09-16 23:22:54 +04:00
|
|
|
},
|
2012-09-08 14:52:18 +04:00
|
|
|
{ },
|
|
|
|
};
|
2015-07-30 19:18:40 +03:00
|
|
|
MODULE_DEVICE_TABLE(i2c, fan53555_id);
|
2012-09-08 14:52:18 +04:00
|
|
|
|
|
|
|
static struct i2c_driver fan53555_regulator_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "fan53555-regulator",
|
2014-09-16 23:22:53 +04:00
|
|
|
.of_match_table = of_match_ptr(fan53555_dt_ids),
|
2012-09-08 14:52:18 +04:00
|
|
|
},
|
|
|
|
.probe = fan53555_regulator_probe,
|
|
|
|
.id_table = fan53555_id,
|
|
|
|
};
|
|
|
|
|
|
|
|
module_i2c_driver(fan53555_regulator_driver);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Yunfan Zhang <yfzhang@marvell.com>");
|
|
|
|
MODULE_DESCRIPTION("FAN53555 regulator driver");
|
|
|
|
MODULE_LICENSE("GPL v2");
|