108ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang/* 208ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang * Regulators driver for Maxim max8925 308ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang * 408ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang * Copyright (C) 2009 Marvell International Ltd. 508ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang * Haojian Zhuang <haojian.zhuang@marvell.com> 608ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang * 708ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang * This program is free software; you can redistribute it and/or modify 808ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang * it under the terms of the GNU General Public License version 2 as 908ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang * published by the Free Software Foundation. 1008ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang */ 1108ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang#include <linux/kernel.h> 1265602c32ee9b5500e3cb617ccec2154ee2191898Paul Gortmaker#include <linux/module.h> 1308ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang#include <linux/init.h> 1408ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang#include <linux/err.h> 1508ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang#include <linux/i2c.h> 1608ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang#include <linux/platform_device.h> 1708ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang#include <linux/regulator/driver.h> 1808ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang#include <linux/regulator/machine.h> 1908ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang#include <linux/mfd/max8925.h> 2045b6f8e8fc014fe404d155a657a04b25b861001dQing Xu#include <linux/of.h> 2145b6f8e8fc014fe404d155a657a04b25b861001dQing Xu#include <linux/regulator/of_regulator.h> 2208ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 2308ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang#define SD1_DVM_VMIN 850000 2408ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang#define SD1_DVM_VMAX 1000000 2508ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang#define SD1_DVM_STEP 50000 2608ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang#define SD1_DVM_SHIFT 5 /* SDCTL1 bit5 */ 2708ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang#define SD1_DVM_EN 6 /* SDV1 bit 6 */ 2808ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 2965364e9ab958f4ad21c5c7b6cc8e2e458128dbcbKevin Liu/* bit definitions in LDO control registers */ 3065364e9ab958f4ad21c5c7b6cc8e2e458128dbcbKevin Liu#define LDO_SEQ_I2C 0x7 /* Power U/D by i2c */ 3165364e9ab958f4ad21c5c7b6cc8e2e458128dbcbKevin Liu#define LDO_SEQ_MASK 0x7 /* Power U/D sequence mask */ 3265364e9ab958f4ad21c5c7b6cc8e2e458128dbcbKevin Liu#define LDO_SEQ_SHIFT 2 /* Power U/D sequence offset */ 3365364e9ab958f4ad21c5c7b6cc8e2e458128dbcbKevin Liu#define LDO_I2C_EN 0x1 /* Enable by i2c */ 3465364e9ab958f4ad21c5c7b6cc8e2e458128dbcbKevin Liu#define LDO_I2C_EN_MASK 0x1 /* Enable mask by i2c */ 3565364e9ab958f4ad21c5c7b6cc8e2e458128dbcbKevin Liu#define LDO_I2C_EN_SHIFT 0 /* Enable offset by i2c */ 36db13c04002e0d896f89657f9b2837a8ecfbb19b6Haojian Zhuang 3708ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuangstruct max8925_regulator_info { 3808ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang struct regulator_desc desc; 3908ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang struct i2c_client *i2c; 4008ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 4108ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang int vol_reg; 4208ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang int enable_reg; 4308ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang}; 4408ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 45cd8318cb9e8dea0dcf8ccb15955b48d14ba51e52Axel Linstatic int max8925_set_voltage_sel(struct regulator_dev *rdev, 46cd8318cb9e8dea0dcf8ccb15955b48d14ba51e52Axel Lin unsigned int selector) 4708ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang{ 4808ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang struct max8925_regulator_info *info = rdev_get_drvdata(rdev); 49cd8318cb9e8dea0dcf8ccb15955b48d14ba51e52Axel Lin unsigned char mask = rdev->desc->n_voltages - 1; 5008ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 51cd8318cb9e8dea0dcf8ccb15955b48d14ba51e52Axel Lin return max8925_set_bits(info->i2c, info->vol_reg, mask, selector); 5208ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang} 5308ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 543c8983b9ac2f8bf9f23effa4f72ce814f8375397Axel Linstatic int max8925_get_voltage_sel(struct regulator_dev *rdev) 5508ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang{ 5608ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang struct max8925_regulator_info *info = rdev_get_drvdata(rdev); 5708ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang unsigned char data, mask; 5808ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang int ret; 5908ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 6008ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang ret = max8925_reg_read(info->i2c, info->vol_reg); 6108ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang if (ret < 0) 6208ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang return ret; 637f52ba7791a35a8e13a3be992fc98da66e68b77dAxel Lin mask = rdev->desc->n_voltages - 1; 647f52ba7791a35a8e13a3be992fc98da66e68b77dAxel Lin data = ret & mask; 6508ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 663c8983b9ac2f8bf9f23effa4f72ce814f8375397Axel Lin return data; 6708ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang} 6808ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 6908ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuangstatic int max8925_enable(struct regulator_dev *rdev) 7008ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang{ 7108ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang struct max8925_regulator_info *info = rdev_get_drvdata(rdev); 7208ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 7308ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang return max8925_set_bits(info->i2c, info->enable_reg, 7465364e9ab958f4ad21c5c7b6cc8e2e458128dbcbKevin Liu LDO_SEQ_MASK << LDO_SEQ_SHIFT | 7565364e9ab958f4ad21c5c7b6cc8e2e458128dbcbKevin Liu LDO_I2C_EN_MASK << LDO_I2C_EN_SHIFT, 7665364e9ab958f4ad21c5c7b6cc8e2e458128dbcbKevin Liu LDO_SEQ_I2C << LDO_SEQ_SHIFT | 7765364e9ab958f4ad21c5c7b6cc8e2e458128dbcbKevin Liu LDO_I2C_EN << LDO_I2C_EN_SHIFT); 7808ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang} 7908ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 8008ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuangstatic int max8925_disable(struct regulator_dev *rdev) 8108ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang{ 8208ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang struct max8925_regulator_info *info = rdev_get_drvdata(rdev); 8308ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 8408ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang return max8925_set_bits(info->i2c, info->enable_reg, 8565364e9ab958f4ad21c5c7b6cc8e2e458128dbcbKevin Liu LDO_SEQ_MASK << LDO_SEQ_SHIFT | 8665364e9ab958f4ad21c5c7b6cc8e2e458128dbcbKevin Liu LDO_I2C_EN_MASK << LDO_I2C_EN_SHIFT, 8765364e9ab958f4ad21c5c7b6cc8e2e458128dbcbKevin Liu LDO_SEQ_I2C << LDO_SEQ_SHIFT); 8808ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang} 8908ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 9008ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuangstatic int max8925_is_enabled(struct regulator_dev *rdev) 9108ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang{ 9208ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang struct max8925_regulator_info *info = rdev_get_drvdata(rdev); 9365364e9ab958f4ad21c5c7b6cc8e2e458128dbcbKevin Liu int ldo_seq, ret; 9408ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 954b99fef02510706a73c8400045b4c72514e581c4Haojian Zhuang ret = max8925_reg_read(info->i2c, info->enable_reg); 9608ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang if (ret < 0) 9708ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang return ret; 9865364e9ab958f4ad21c5c7b6cc8e2e458128dbcbKevin Liu ldo_seq = (ret >> LDO_SEQ_SHIFT) & LDO_SEQ_MASK; 9965364e9ab958f4ad21c5c7b6cc8e2e458128dbcbKevin Liu if (ldo_seq != LDO_SEQ_I2C) 10065364e9ab958f4ad21c5c7b6cc8e2e458128dbcbKevin Liu return 1; 10165364e9ab958f4ad21c5c7b6cc8e2e458128dbcbKevin Liu else 10265364e9ab958f4ad21c5c7b6cc8e2e458128dbcbKevin Liu return ret & (LDO_I2C_EN_MASK << LDO_I2C_EN_SHIFT); 10308ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang} 10408ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 10508ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuangstatic int max8925_set_dvm_voltage(struct regulator_dev *rdev, int uV) 10608ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang{ 10708ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang struct max8925_regulator_info *info = rdev_get_drvdata(rdev); 10808ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang unsigned char data, mask; 10908ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 11008ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang if (uV < SD1_DVM_VMIN || uV > SD1_DVM_VMAX) 11108ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang return -EINVAL; 11208ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 1135db6d09a2b4663735121dfe4222860424788a93fAxel Lin data = DIV_ROUND_UP(uV - SD1_DVM_VMIN, SD1_DVM_STEP); 11408ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang data <<= SD1_DVM_SHIFT; 11508ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang mask = 3 << SD1_DVM_SHIFT; 11608ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 11708ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang return max8925_set_bits(info->i2c, info->enable_reg, mask, data); 11808ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang} 11908ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 12008ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuangstatic int max8925_set_dvm_enable(struct regulator_dev *rdev) 12108ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang{ 12208ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang struct max8925_regulator_info *info = rdev_get_drvdata(rdev); 12308ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 12408ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang return max8925_set_bits(info->i2c, info->vol_reg, 1 << SD1_DVM_EN, 12508ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 1 << SD1_DVM_EN); 12608ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang} 12708ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 12808ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuangstatic int max8925_set_dvm_disable(struct regulator_dev *rdev) 12908ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang{ 13008ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang struct max8925_regulator_info *info = rdev_get_drvdata(rdev); 13108ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 13208ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang return max8925_set_bits(info->i2c, info->vol_reg, 1 << SD1_DVM_EN, 0); 13308ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang} 13408ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 13508ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuangstatic struct regulator_ops max8925_regulator_sdv_ops = { 136cd8318cb9e8dea0dcf8ccb15955b48d14ba51e52Axel Lin .map_voltage = regulator_map_voltage_linear, 1374093e739f76e1a17b748f9558e3a48a49507885aAxel Lin .list_voltage = regulator_list_voltage_linear, 138cd8318cb9e8dea0dcf8ccb15955b48d14ba51e52Axel Lin .set_voltage_sel = max8925_set_voltage_sel, 1393c8983b9ac2f8bf9f23effa4f72ce814f8375397Axel Lin .get_voltage_sel = max8925_get_voltage_sel, 14008ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .enable = max8925_enable, 14108ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .disable = max8925_disable, 14208ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .is_enabled = max8925_is_enabled, 14308ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .set_suspend_voltage = max8925_set_dvm_voltage, 14408ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .set_suspend_enable = max8925_set_dvm_enable, 14508ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .set_suspend_disable = max8925_set_dvm_disable, 14608ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang}; 14708ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 14808ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuangstatic struct regulator_ops max8925_regulator_ldo_ops = { 149cd8318cb9e8dea0dcf8ccb15955b48d14ba51e52Axel Lin .map_voltage = regulator_map_voltage_linear, 1504093e739f76e1a17b748f9558e3a48a49507885aAxel Lin .list_voltage = regulator_list_voltage_linear, 151cd8318cb9e8dea0dcf8ccb15955b48d14ba51e52Axel Lin .set_voltage_sel = max8925_set_voltage_sel, 1523c8983b9ac2f8bf9f23effa4f72ce814f8375397Axel Lin .get_voltage_sel = max8925_get_voltage_sel, 15308ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .enable = max8925_enable, 15408ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .disable = max8925_disable, 15508ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .is_enabled = max8925_is_enabled, 15608ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang}; 15708ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 15808ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang#define MAX8925_SDV(_id, min, max, step) \ 15908ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang{ \ 16008ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .desc = { \ 16108ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .name = "SDV" #_id, \ 16208ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .ops = &max8925_regulator_sdv_ops, \ 16308ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .type = REGULATOR_VOLTAGE, \ 16408ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .id = MAX8925_ID_SD##_id, \ 16508ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .owner = THIS_MODULE, \ 1667f52ba7791a35a8e13a3be992fc98da66e68b77dAxel Lin .n_voltages = 64, \ 1674093e739f76e1a17b748f9558e3a48a49507885aAxel Lin .min_uV = min * 1000, \ 1684093e739f76e1a17b748f9558e3a48a49507885aAxel Lin .uV_step = step * 1000, \ 16908ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang }, \ 17008ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .vol_reg = MAX8925_SDV##_id, \ 17108ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .enable_reg = MAX8925_SDCTL##_id, \ 17208ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang} 17308ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 17408ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang#define MAX8925_LDO(_id, min, max, step) \ 17508ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang{ \ 17608ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .desc = { \ 17708ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .name = "LDO" #_id, \ 17808ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .ops = &max8925_regulator_ldo_ops, \ 17908ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .type = REGULATOR_VOLTAGE, \ 18008ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .id = MAX8925_ID_LDO##_id, \ 18108ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .owner = THIS_MODULE, \ 1827f52ba7791a35a8e13a3be992fc98da66e68b77dAxel Lin .n_voltages = 64, \ 1834093e739f76e1a17b748f9558e3a48a49507885aAxel Lin .min_uV = min * 1000, \ 1844093e739f76e1a17b748f9558e3a48a49507885aAxel Lin .uV_step = step * 1000, \ 18508ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang }, \ 18608ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .vol_reg = MAX8925_LDOVOUT##_id, \ 18708ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .enable_reg = MAX8925_LDOCTL##_id, \ 18808ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang} 18908ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 19045b6f8e8fc014fe404d155a657a04b25b861001dQing Xu#ifdef CONFIG_OF 19145b6f8e8fc014fe404d155a657a04b25b861001dQing Xustatic struct of_regulator_match max8925_regulator_matches[] = { 19245b6f8e8fc014fe404d155a657a04b25b861001dQing Xu { .name = "SDV1",}, 19345b6f8e8fc014fe404d155a657a04b25b861001dQing Xu { .name = "SDV2",}, 19445b6f8e8fc014fe404d155a657a04b25b861001dQing Xu { .name = "SDV3",}, 19545b6f8e8fc014fe404d155a657a04b25b861001dQing Xu { .name = "LDO1",}, 19645b6f8e8fc014fe404d155a657a04b25b861001dQing Xu { .name = "LDO2",}, 19745b6f8e8fc014fe404d155a657a04b25b861001dQing Xu { .name = "LDO3",}, 19845b6f8e8fc014fe404d155a657a04b25b861001dQing Xu { .name = "LDO4",}, 19945b6f8e8fc014fe404d155a657a04b25b861001dQing Xu { .name = "LDO5",}, 20045b6f8e8fc014fe404d155a657a04b25b861001dQing Xu { .name = "LDO6",}, 20145b6f8e8fc014fe404d155a657a04b25b861001dQing Xu { .name = "LDO7",}, 20245b6f8e8fc014fe404d155a657a04b25b861001dQing Xu { .name = "LDO8",}, 20345b6f8e8fc014fe404d155a657a04b25b861001dQing Xu { .name = "LDO9",}, 20445b6f8e8fc014fe404d155a657a04b25b861001dQing Xu { .name = "LDO10",}, 20545b6f8e8fc014fe404d155a657a04b25b861001dQing Xu { .name = "LDO11",}, 20645b6f8e8fc014fe404d155a657a04b25b861001dQing Xu { .name = "LDO12",}, 20745b6f8e8fc014fe404d155a657a04b25b861001dQing Xu { .name = "LDO13",}, 20845b6f8e8fc014fe404d155a657a04b25b861001dQing Xu { .name = "LDO14",}, 20945b6f8e8fc014fe404d155a657a04b25b861001dQing Xu { .name = "LDO15",}, 21045b6f8e8fc014fe404d155a657a04b25b861001dQing Xu { .name = "LDO16",}, 21145b6f8e8fc014fe404d155a657a04b25b861001dQing Xu { .name = "LDO17",}, 21245b6f8e8fc014fe404d155a657a04b25b861001dQing Xu { .name = "LDO18",}, 21345b6f8e8fc014fe404d155a657a04b25b861001dQing Xu { .name = "LDO19",}, 21445b6f8e8fc014fe404d155a657a04b25b861001dQing Xu { .name = "LDO20",}, 21545b6f8e8fc014fe404d155a657a04b25b861001dQing Xu}; 21645b6f8e8fc014fe404d155a657a04b25b861001dQing Xu#endif 21745b6f8e8fc014fe404d155a657a04b25b861001dQing Xu 21808ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuangstatic struct max8925_regulator_info max8925_regulator_info[] = { 21908ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang MAX8925_SDV(1, 637.5, 1425, 12.5), 22008ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang MAX8925_SDV(2, 650, 2225, 25), 22108ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang MAX8925_SDV(3, 750, 3900, 50), 22208ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 22308ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang MAX8925_LDO(1, 750, 3900, 50), 22408ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang MAX8925_LDO(2, 650, 2250, 25), 22508ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang MAX8925_LDO(3, 650, 2250, 25), 22608ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang MAX8925_LDO(4, 750, 3900, 50), 22708ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang MAX8925_LDO(5, 750, 3900, 50), 22808ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang MAX8925_LDO(6, 750, 3900, 50), 22908ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang MAX8925_LDO(7, 750, 3900, 50), 23008ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang MAX8925_LDO(8, 750, 3900, 50), 23108ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang MAX8925_LDO(9, 750, 3900, 50), 23208ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang MAX8925_LDO(10, 750, 3900, 50), 23308ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang MAX8925_LDO(11, 750, 3900, 50), 23408ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang MAX8925_LDO(12, 750, 3900, 50), 23508ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang MAX8925_LDO(13, 750, 3900, 50), 23608ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang MAX8925_LDO(14, 750, 3900, 50), 23708ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang MAX8925_LDO(15, 750, 3900, 50), 23808ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang MAX8925_LDO(16, 750, 3900, 50), 23908ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang MAX8925_LDO(17, 650, 2250, 25), 24008ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang MAX8925_LDO(18, 650, 2250, 25), 24108ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang MAX8925_LDO(19, 750, 3900, 50), 24208ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang MAX8925_LDO(20, 750, 3900, 50), 24308ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang}; 24408ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 24545b6f8e8fc014fe404d155a657a04b25b861001dQing Xu#ifdef CONFIG_OF 24645b6f8e8fc014fe404d155a657a04b25b861001dQing Xustatic int max8925_regulator_dt_init(struct platform_device *pdev, 24745b6f8e8fc014fe404d155a657a04b25b861001dQing Xu struct regulator_config *config, 24845b6f8e8fc014fe404d155a657a04b25b861001dQing Xu int ridx) 24945b6f8e8fc014fe404d155a657a04b25b861001dQing Xu{ 25045b6f8e8fc014fe404d155a657a04b25b861001dQing Xu struct device_node *nproot, *np; 25145b6f8e8fc014fe404d155a657a04b25b861001dQing Xu int rcount; 252c74c76e8503e3f23f848a8bdf335b82bdf827d5aSachin Kamat 253b8b27a44ddf1987e9bae84b99741b0a61192e017Guodong Xu nproot = pdev->dev.parent->of_node; 25445b6f8e8fc014fe404d155a657a04b25b861001dQing Xu if (!nproot) 25545b6f8e8fc014fe404d155a657a04b25b861001dQing Xu return -ENODEV; 2561f4f88c0aef7e52bb3ae067ae802b64fc8312188Sachin Kamat np = of_get_child_by_name(nproot, "regulators"); 25745b6f8e8fc014fe404d155a657a04b25b861001dQing Xu if (!np) { 25845b6f8e8fc014fe404d155a657a04b25b861001dQing Xu dev_err(&pdev->dev, "failed to find regulators node\n"); 25945b6f8e8fc014fe404d155a657a04b25b861001dQing Xu return -ENODEV; 26045b6f8e8fc014fe404d155a657a04b25b861001dQing Xu } 26145b6f8e8fc014fe404d155a657a04b25b861001dQing Xu 26245b6f8e8fc014fe404d155a657a04b25b861001dQing Xu rcount = of_regulator_match(&pdev->dev, np, 26345b6f8e8fc014fe404d155a657a04b25b861001dQing Xu &max8925_regulator_matches[ridx], 1); 264c92f5dd2c42fa61e0ef810fad4584b184ea2d50eAxel Lin of_node_put(np); 26545b6f8e8fc014fe404d155a657a04b25b861001dQing Xu if (rcount < 0) 266e9fa1a3ac62d5103fe2b8b54968f5d0fe9cf7fdfSachin Kamat return rcount; 26745b6f8e8fc014fe404d155a657a04b25b861001dQing Xu config->init_data = max8925_regulator_matches[ridx].init_data; 26845b6f8e8fc014fe404d155a657a04b25b861001dQing Xu config->of_node = max8925_regulator_matches[ridx].of_node; 26945b6f8e8fc014fe404d155a657a04b25b861001dQing Xu 27045b6f8e8fc014fe404d155a657a04b25b861001dQing Xu return 0; 27145b6f8e8fc014fe404d155a657a04b25b861001dQing Xu} 27245b6f8e8fc014fe404d155a657a04b25b861001dQing Xu#else 273ad4928f1dc695ea822c4daaafa5e3b2db7b17964Axel Lin#define max8925_regulator_dt_init(x, y, z) (-1) 27445b6f8e8fc014fe404d155a657a04b25b861001dQing Xu#endif 27545b6f8e8fc014fe404d155a657a04b25b861001dQing Xu 276a5023574d120ca3b9337cedd4e27de90cae9aff7Bill Pembertonstatic int max8925_regulator_probe(struct platform_device *pdev) 27708ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang{ 27808ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent); 279dff91d0b721bf8f036c1071a8f16a7effaa87514Jingoo Han struct regulator_init_data *pdata = dev_get_platdata(&pdev->dev); 280c172708d38a401b2f3f841dfcd862b469fa0b670Mark Brown struct regulator_config config = { }; 2813fff6c04d81a2852821135736fad2d8386464753Dmitry Torokhov struct max8925_regulator_info *ri; 28251acdb61185e9c7579366712a415fc929929d3bbHaojian Zhuang struct resource *res; 28308ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang struct regulator_dev *rdev; 28445b6f8e8fc014fe404d155a657a04b25b861001dQing Xu int i, regulator_idx; 28508ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 28651acdb61185e9c7579366712a415fc929929d3bbHaojian Zhuang res = platform_get_resource(pdev, IORESOURCE_REG, 0); 28751acdb61185e9c7579366712a415fc929929d3bbHaojian Zhuang if (!res) { 28851acdb61185e9c7579366712a415fc929929d3bbHaojian Zhuang dev_err(&pdev->dev, "No REG resource!\n"); 28951acdb61185e9c7579366712a415fc929929d3bbHaojian Zhuang return -EINVAL; 29051acdb61185e9c7579366712a415fc929929d3bbHaojian Zhuang } 29151acdb61185e9c7579366712a415fc929929d3bbHaojian Zhuang for (i = 0; i < ARRAY_SIZE(max8925_regulator_info); i++) { 29251acdb61185e9c7579366712a415fc929929d3bbHaojian Zhuang ri = &max8925_regulator_info[i]; 29345b6f8e8fc014fe404d155a657a04b25b861001dQing Xu if (ri->vol_reg == res->start) { 29445b6f8e8fc014fe404d155a657a04b25b861001dQing Xu regulator_idx = i; 29551acdb61185e9c7579366712a415fc929929d3bbHaojian Zhuang break; 29645b6f8e8fc014fe404d155a657a04b25b861001dQing Xu } 29751acdb61185e9c7579366712a415fc929929d3bbHaojian Zhuang } 29845b6f8e8fc014fe404d155a657a04b25b861001dQing Xu 29951acdb61185e9c7579366712a415fc929929d3bbHaojian Zhuang if (i == ARRAY_SIZE(max8925_regulator_info)) { 30051acdb61185e9c7579366712a415fc929929d3bbHaojian Zhuang dev_err(&pdev->dev, "Failed to find regulator %llu\n", 30151acdb61185e9c7579366712a415fc929929d3bbHaojian Zhuang (unsigned long long)res->start); 30208ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang return -EINVAL; 30308ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang } 30408ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang ri->i2c = chip->i2c; 30508ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 306c172708d38a401b2f3f841dfcd862b469fa0b670Mark Brown config.dev = &pdev->dev; 307c172708d38a401b2f3f841dfcd862b469fa0b670Mark Brown config.driver_data = ri; 308c172708d38a401b2f3f841dfcd862b469fa0b670Mark Brown 309ad4928f1dc695ea822c4daaafa5e3b2db7b17964Axel Lin if (max8925_regulator_dt_init(pdev, &config, regulator_idx)) 31045b6f8e8fc014fe404d155a657a04b25b861001dQing Xu if (pdata) 31145b6f8e8fc014fe404d155a657a04b25b861001dQing Xu config.init_data = pdata; 31245b6f8e8fc014fe404d155a657a04b25b861001dQing Xu 31358765e24bec8940082068829a9d2c3a4431d60c0Jingoo Han rdev = devm_regulator_register(&pdev->dev, &ri->desc, &config); 31408ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang if (IS_ERR(rdev)) { 31508ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang dev_err(&pdev->dev, "failed to register regulator %s\n", 31608ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang ri->desc.name); 31708ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang return PTR_ERR(rdev); 31808ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang } 31908ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 32008ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang platform_set_drvdata(pdev, rdev); 32108ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang return 0; 32208ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang} 32308ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 32408ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuangstatic struct platform_driver max8925_regulator_driver = { 32508ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .driver = { 32608ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .name = "max8925-regulator", 32708ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .owner = THIS_MODULE, 32808ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang }, 32908ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang .probe = max8925_regulator_probe, 33008ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang}; 33108ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 33208ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuangstatic int __init max8925_regulator_init(void) 33308ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang{ 33408ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang return platform_driver_register(&max8925_regulator_driver); 33508ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang} 33608ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuangsubsys_initcall(max8925_regulator_init); 33708ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 33808ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuangstatic void __exit max8925_regulator_exit(void) 33908ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang{ 34008ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang platform_driver_unregister(&max8925_regulator_driver); 34108ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang} 34208ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuangmodule_exit(max8925_regulator_exit); 34308ff6f2a9908c87b0adffe6453291be22db3a62fHaojian Zhuang 34408ff6f2a9908c87b0adffe6453291be22db3a62fHaojian ZhuangMODULE_LICENSE("GPL"); 34508ff6f2a9908c87b0adffe6453291be22db3a62fHaojian ZhuangMODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>"); 34608ff6f2a9908c87b0adffe6453291be22db3a62fHaojian ZhuangMODULE_DESCRIPTION("Regulator Driver for Maxim 8925 PMIC"); 34708ff6f2a9908c87b0adffe6453291be22db3a62fHaojian ZhuangMODULE_ALIAS("platform:max8925-regulator"); 348