11394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy/* 21394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy * Regulator driver for TPS6524x PMIC 31394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy * 41394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy * Copyright (C) 2010 Texas Instruments 51394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy * 61394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy * This program is free software; you can redistribute it and/or 71394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy * modify it under the terms of the GNU General Public License as 81394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy * published by the Free Software Foundation version 2. 91394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy * 101394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, 111394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy * whether express or implied; without even the implied warranty of 121394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 131394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy * General Public License for more details. 141394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy */ 151394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 161394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#include <linux/kernel.h> 171394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#include <linux/module.h> 181394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#include <linux/err.h> 191394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#include <linux/errno.h> 201394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#include <linux/slab.h> 211394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#include <linux/spi/spi.h> 221394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#include <linux/regulator/driver.h> 231394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#include <linux/regulator/machine.h> 241394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 251394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define REG_LDO_SET 0x0 261394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define LDO_ILIM_MASK 1 /* 0 = 400-800, 1 = 900-1500 */ 271394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define LDO_VSEL_MASK 0x0f 281394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define LDO2_ILIM_SHIFT 12 291394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define LDO2_VSEL_SHIFT 4 301394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define LDO1_ILIM_SHIFT 8 311394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define LDO1_VSEL_SHIFT 0 321394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 331394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define REG_BLOCK_EN 0x1 341394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define BLOCK_MASK 1 351394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define BLOCK_LDO1_SHIFT 0 361394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define BLOCK_LDO2_SHIFT 1 371394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define BLOCK_LCD_SHIFT 2 381394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define BLOCK_USB_SHIFT 3 391394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 401394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define REG_DCDC_SET 0x2 411394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define DCDC_VDCDC_MASK 0x1f 421394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define DCDC_VDCDC1_SHIFT 0 431394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define DCDC_VDCDC2_SHIFT 5 441394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define DCDC_VDCDC3_SHIFT 10 451394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 461394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define REG_DCDC_EN 0x3 471394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define DCDCDCDC_EN_MASK 0x1 481394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define DCDCDCDC1_EN_SHIFT 0 491394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define DCDCDCDC1_PG_MSK BIT(1) 501394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define DCDCDCDC2_EN_SHIFT 2 511394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define DCDCDCDC2_PG_MSK BIT(3) 521394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define DCDCDCDC3_EN_SHIFT 4 531394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define DCDCDCDC3_PG_MSK BIT(5) 541394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 551394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define REG_USB 0x4 561394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define USB_ILIM_SHIFT 0 571394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define USB_ILIM_MASK 0x3 581394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define USB_TSD_SHIFT 2 591394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define USB_TSD_MASK 0x3 601394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define USB_TWARN_SHIFT 4 611394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define USB_TWARN_MASK 0x3 621394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define USB_IWARN_SD BIT(6) 631394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define USB_FAST_LOOP BIT(7) 641394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 651394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define REG_ALARM 0x5 661394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define ALARM_LDO1 BIT(0) 671394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define ALARM_DCDC1 BIT(1) 681394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define ALARM_DCDC2 BIT(2) 691394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define ALARM_DCDC3 BIT(3) 701394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define ALARM_LDO2 BIT(4) 711394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define ALARM_USB_WARN BIT(5) 721394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define ALARM_USB_ALARM BIT(6) 731394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define ALARM_LCD BIT(9) 741394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define ALARM_TEMP_WARM BIT(10) 751394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define ALARM_TEMP_HOT BIT(11) 761394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define ALARM_NRST BIT(14) 771394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define ALARM_POWERUP BIT(15) 781394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 791394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define REG_INT_ENABLE 0x6 801394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define INT_LDO1 BIT(0) 811394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define INT_DCDC1 BIT(1) 821394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define INT_DCDC2 BIT(2) 831394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define INT_DCDC3 BIT(3) 841394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define INT_LDO2 BIT(4) 851394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define INT_USB_WARN BIT(5) 861394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define INT_USB_ALARM BIT(6) 871394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define INT_LCD BIT(9) 881394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define INT_TEMP_WARM BIT(10) 891394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define INT_TEMP_HOT BIT(11) 901394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define INT_GLOBAL_EN BIT(15) 911394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 921394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define REG_INT_STATUS 0x7 931394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define STATUS_LDO1 BIT(0) 941394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define STATUS_DCDC1 BIT(1) 951394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define STATUS_DCDC2 BIT(2) 961394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define STATUS_DCDC3 BIT(3) 971394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define STATUS_LDO2 BIT(4) 981394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define STATUS_USB_WARN BIT(5) 991394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define STATUS_USB_ALARM BIT(6) 1001394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define STATUS_LCD BIT(9) 1011394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define STATUS_TEMP_WARM BIT(10) 1021394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define STATUS_TEMP_HOT BIT(11) 1031394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1041394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define REG_SOFTWARE_RESET 0xb 1051394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define REG_WRITE_ENABLE 0xd 1061394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define REG_REV_ID 0xf 1071394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1081394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define N_DCDC 3 1091394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define N_LDO 2 1101394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define N_SWITCH 2 1114d984d1cd838435cf1180ab9ffbab24cfdbf7515Axel Lin#define N_REGULATORS (N_DCDC + N_LDO + N_SWITCH) 1121394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1131394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define CMD_READ(reg) ((reg) << 6) 1141394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define CMD_WRITE(reg) (BIT(5) | (reg) << 6) 1151394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define STAT_CLK BIT(3) 1161394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define STAT_WRITE BIT(2) 1171394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define STAT_INVALID BIT(1) 1181394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define STAT_WP BIT(0) 1191394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1201394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathystruct field { 1211394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy int reg; 1221394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy int shift; 1231394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy int mask; 1241394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy}; 1251394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1261394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathystruct supply_info { 1271394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy const char *name; 1281394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy int n_voltages; 129cac87fd34ebd79a954321f78acf38abcc69e1308Axel Lin const unsigned int *voltages; 1301394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy int n_ilimsels; 1311e12dfc9681fed46fbc9fffc6aba9613908c1213Axel Lin const unsigned int *ilimsels; 1321394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy struct field enable, voltage, ilimsel; 1331394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy}; 1341394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1351394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathystruct tps6524x { 1361394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy struct device *dev; 1371394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy struct spi_device *spi; 1381394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy struct mutex lock; 1391394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy struct regulator_desc desc[N_REGULATORS]; 1401394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy struct regulator_dev *rdev[N_REGULATORS]; 1411394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy}; 1421394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1431394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathystatic int __read_reg(struct tps6524x *hw, int reg) 1441394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy{ 1451394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy int error = 0; 1461394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy u16 cmd = CMD_READ(reg), in; 1471394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy u8 status; 1481394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy struct spi_message m; 1491394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy struct spi_transfer t[3]; 1501394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1511394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy spi_message_init(&m); 1521394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy memset(t, 0, sizeof(t)); 1531394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1541394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy t[0].tx_buf = &cmd; 1551394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy t[0].len = 2; 1561394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy t[0].bits_per_word = 12; 1571394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy spi_message_add_tail(&t[0], &m); 1581394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1591394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy t[1].rx_buf = ∈ 1601394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy t[1].len = 2; 1611394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy t[1].bits_per_word = 16; 1621394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy spi_message_add_tail(&t[1], &m); 1631394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1641394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy t[2].rx_buf = &status; 1651394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy t[2].len = 1; 1661394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy t[2].bits_per_word = 4; 1671394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy spi_message_add_tail(&t[2], &m); 1681394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1691394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy error = spi_sync(hw->spi, &m); 1701394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy if (error < 0) 1711394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return error; 1721394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1731394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy dev_dbg(hw->dev, "read reg %d, data %x, status %x\n", 1741394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy reg, in, status); 1751394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1761394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy if (!(status & STAT_CLK) || (status & STAT_WRITE)) 1771394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return -EIO; 1781394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1791394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy if (status & STAT_INVALID) 1801394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return -EINVAL; 1811394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1821394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return in; 1831394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy} 1841394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1851394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathystatic int read_reg(struct tps6524x *hw, int reg) 1861394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy{ 1871394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy int ret; 1881394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1891394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy mutex_lock(&hw->lock); 1901394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy ret = __read_reg(hw, reg); 1911394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy mutex_unlock(&hw->lock); 1921394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1931394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return ret; 1941394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy} 1951394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1961394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathystatic int __write_reg(struct tps6524x *hw, int reg, int val) 1971394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy{ 1981394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy int error = 0; 1991394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy u16 cmd = CMD_WRITE(reg), out = val; 2001394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy u8 status; 2011394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy struct spi_message m; 2021394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy struct spi_transfer t[3]; 2031394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2041394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy spi_message_init(&m); 2051394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy memset(t, 0, sizeof(t)); 2061394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2071394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy t[0].tx_buf = &cmd; 2081394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy t[0].len = 2; 2091394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy t[0].bits_per_word = 12; 2101394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy spi_message_add_tail(&t[0], &m); 2111394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2121394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy t[1].tx_buf = &out; 2131394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy t[1].len = 2; 2141394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy t[1].bits_per_word = 16; 2151394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy spi_message_add_tail(&t[1], &m); 2161394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2171394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy t[2].rx_buf = &status; 2181394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy t[2].len = 1; 2191394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy t[2].bits_per_word = 4; 2201394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy spi_message_add_tail(&t[2], &m); 2211394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2221394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy error = spi_sync(hw->spi, &m); 2231394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy if (error < 0) 2241394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return error; 2251394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2261394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy dev_dbg(hw->dev, "wrote reg %d, data %x, status %x\n", 2271394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy reg, out, status); 2281394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2291394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy if (!(status & STAT_CLK) || !(status & STAT_WRITE)) 2301394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return -EIO; 2311394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2321394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy if (status & (STAT_INVALID | STAT_WP)) 2331394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return -EINVAL; 2341394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2351394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return error; 2361394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy} 2371394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2381394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathystatic int __rmw_reg(struct tps6524x *hw, int reg, int mask, int val) 2391394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy{ 2401394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy int ret; 2411394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2421394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy ret = __read_reg(hw, reg); 2431394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy if (ret < 0) 2441394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return ret; 2451394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2461394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy ret &= ~mask; 2471394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy ret |= val; 2481394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2491394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy ret = __write_reg(hw, reg, ret); 2501394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2511394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return (ret < 0) ? ret : 0; 2521394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy} 2531394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2541394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathystatic int rmw_protect(struct tps6524x *hw, int reg, int mask, int val) 2551394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy{ 2561394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy int ret; 2571394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2581394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy mutex_lock(&hw->lock); 2591394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2601394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy ret = __write_reg(hw, REG_WRITE_ENABLE, 1); 2611394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy if (ret) { 2621394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy dev_err(hw->dev, "failed to set write enable\n"); 2631394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy goto error; 2641394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy } 2651394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2661394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy ret = __rmw_reg(hw, reg, mask, val); 2671394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy if (ret) 2681394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy dev_err(hw->dev, "failed to rmw register %d\n", reg); 2691394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2701394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy ret = __write_reg(hw, REG_WRITE_ENABLE, 0); 2711394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy if (ret) { 2721394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy dev_err(hw->dev, "failed to clear write enable\n"); 2731394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy goto error; 2741394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy } 2751394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2761394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathyerror: 2771394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy mutex_unlock(&hw->lock); 2781394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2791394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return ret; 2801394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy} 2811394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2821394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathystatic int read_field(struct tps6524x *hw, const struct field *field) 2831394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy{ 2841394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy int tmp; 2851394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2861394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy tmp = read_reg(hw, field->reg); 2871394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy if (tmp < 0) 2881394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return tmp; 2891394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2901394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return (tmp >> field->shift) & field->mask; 2911394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy} 2921394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2931394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathystatic int write_field(struct tps6524x *hw, const struct field *field, 2941394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy int val) 2951394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy{ 2961394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy if (val & ~field->mask) 2971394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return -EOVERFLOW; 2981394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2991394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return rmw_protect(hw, field->reg, 3001394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy field->mask << field->shift, 3011394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy val << field->shift); 3021394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy} 3031394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 304cac87fd34ebd79a954321f78acf38abcc69e1308Axel Linstatic const unsigned int dcdc1_voltages[] = { 3051394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 800000, 825000, 850000, 875000, 3061394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 900000, 925000, 950000, 975000, 3071394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1000000, 1025000, 1050000, 1075000, 3081394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1100000, 1125000, 1150000, 1175000, 3091394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1200000, 1225000, 1250000, 1275000, 3101394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1300000, 1325000, 1350000, 1375000, 3111394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1400000, 1425000, 1450000, 1475000, 3121394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1500000, 1525000, 1550000, 1575000, 3131394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy}; 3141394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 315cac87fd34ebd79a954321f78acf38abcc69e1308Axel Linstatic const unsigned int dcdc2_voltages[] = { 3161394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1400000, 1450000, 1500000, 1550000, 3171394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1600000, 1650000, 1700000, 1750000, 3181394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1800000, 1850000, 1900000, 1950000, 3191394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2000000, 2050000, 2100000, 2150000, 3201394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2200000, 2250000, 2300000, 2350000, 3211394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2400000, 2450000, 2500000, 2550000, 3221394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2600000, 2650000, 2700000, 2750000, 3231394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2800000, 2850000, 2900000, 2950000, 3241394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy}; 3251394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 326cac87fd34ebd79a954321f78acf38abcc69e1308Axel Linstatic const unsigned int dcdc3_voltages[] = { 3271394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2400000, 2450000, 2500000, 2550000, 2600000, 3281394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2650000, 2700000, 2750000, 2800000, 2850000, 3291394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 2900000, 2950000, 3000000, 3050000, 3100000, 3301394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 3150000, 3200000, 3250000, 3300000, 3350000, 3311394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 3400000, 3450000, 3500000, 3550000, 3600000, 3321394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy}; 3331394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 334cac87fd34ebd79a954321f78acf38abcc69e1308Axel Linstatic const unsigned int ldo1_voltages[] = { 3351394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 4300000, 4350000, 4400000, 4450000, 3361394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 4500000, 4550000, 4600000, 4650000, 3371394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 4700000, 4750000, 4800000, 4850000, 3381394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 4900000, 4950000, 5000000, 5050000, 3391394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy}; 3401394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 341cac87fd34ebd79a954321f78acf38abcc69e1308Axel Linstatic const unsigned int ldo2_voltages[] = { 3421394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1100000, 1150000, 1200000, 1250000, 3431394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1300000, 1700000, 1750000, 1800000, 3441394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 1850000, 1900000, 3150000, 3200000, 3451394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 3250000, 3300000, 3350000, 3400000, 3461394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy}; 3471394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 348cac87fd34ebd79a954321f78acf38abcc69e1308Axel Linstatic const unsigned int fixed_5000000_voltage[] = { 349cac87fd34ebd79a954321f78acf38abcc69e1308Axel Lin 5000000 350cac87fd34ebd79a954321f78acf38abcc69e1308Axel Lin}; 351cac87fd34ebd79a954321f78acf38abcc69e1308Axel Lin 3521e12dfc9681fed46fbc9fffc6aba9613908c1213Axel Linstatic const unsigned int ldo_ilimsel[] = { 3531394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 400000, 1500000 3541394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy}; 3551394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 3561e12dfc9681fed46fbc9fffc6aba9613908c1213Axel Linstatic const unsigned int usb_ilimsel[] = { 3571394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 200000, 400000, 800000, 1000000 3581394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy}; 3591394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 3601e12dfc9681fed46fbc9fffc6aba9613908c1213Axel Linstatic const unsigned int fixed_2400000_ilimsel[] = { 3611e12dfc9681fed46fbc9fffc6aba9613908c1213Axel Lin 2400000 3621e12dfc9681fed46fbc9fffc6aba9613908c1213Axel Lin}; 3631e12dfc9681fed46fbc9fffc6aba9613908c1213Axel Lin 3641e12dfc9681fed46fbc9fffc6aba9613908c1213Axel Linstatic const unsigned int fixed_1200000_ilimsel[] = { 3651e12dfc9681fed46fbc9fffc6aba9613908c1213Axel Lin 1200000 3661e12dfc9681fed46fbc9fffc6aba9613908c1213Axel Lin}; 3671e12dfc9681fed46fbc9fffc6aba9613908c1213Axel Lin 3681e12dfc9681fed46fbc9fffc6aba9613908c1213Axel Linstatic const unsigned int fixed_400000_ilimsel[] = { 3691e12dfc9681fed46fbc9fffc6aba9613908c1213Axel Lin 400000 3701e12dfc9681fed46fbc9fffc6aba9613908c1213Axel Lin}; 3711e12dfc9681fed46fbc9fffc6aba9613908c1213Axel Lin 3721394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy#define __MK_FIELD(_reg, _mask, _shift) \ 3731394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy { .reg = (_reg), .mask = (_mask), .shift = (_shift), } 3741394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 3751394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathystatic const struct supply_info supply_info[N_REGULATORS] = { 3761394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy { 3771394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .name = "DCDC1", 3781394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .n_voltages = ARRAY_SIZE(dcdc1_voltages), 3791394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .voltages = dcdc1_voltages, 3801e12dfc9681fed46fbc9fffc6aba9613908c1213Axel Lin .n_ilimsels = ARRAY_SIZE(fixed_2400000_ilimsel), 3811e12dfc9681fed46fbc9fffc6aba9613908c1213Axel Lin .ilimsels = fixed_2400000_ilimsel, 3821394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK, 3831394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy DCDCDCDC1_EN_SHIFT), 3841394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK, 3851394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy DCDC_VDCDC1_SHIFT), 3861394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy }, 3871394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy { 3881394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .name = "DCDC2", 3891394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .n_voltages = ARRAY_SIZE(dcdc2_voltages), 3901394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .voltages = dcdc2_voltages, 3911e12dfc9681fed46fbc9fffc6aba9613908c1213Axel Lin .n_ilimsels = ARRAY_SIZE(fixed_1200000_ilimsel), 3921e12dfc9681fed46fbc9fffc6aba9613908c1213Axel Lin .ilimsels = fixed_1200000_ilimsel, 3931394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK, 3941394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy DCDCDCDC2_EN_SHIFT), 3951394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK, 3961394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy DCDC_VDCDC2_SHIFT), 3971394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy }, 3981394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy { 3991394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .name = "DCDC3", 4001394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .n_voltages = ARRAY_SIZE(dcdc3_voltages), 4011394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .voltages = dcdc3_voltages, 4021e12dfc9681fed46fbc9fffc6aba9613908c1213Axel Lin .n_ilimsels = ARRAY_SIZE(fixed_1200000_ilimsel), 4031e12dfc9681fed46fbc9fffc6aba9613908c1213Axel Lin .ilimsels = fixed_1200000_ilimsel, 4041394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK, 4051394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy DCDCDCDC3_EN_SHIFT), 4061394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK, 4071394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy DCDC_VDCDC3_SHIFT), 4081394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy }, 4091394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy { 4101394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .name = "LDO1", 4111394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .n_voltages = ARRAY_SIZE(ldo1_voltages), 4121394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .voltages = ldo1_voltages, 4131394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .n_ilimsels = ARRAY_SIZE(ldo_ilimsel), 4141394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .ilimsels = ldo_ilimsel, 4151394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .enable = __MK_FIELD(REG_BLOCK_EN, BLOCK_MASK, 4161394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy BLOCK_LDO1_SHIFT), 4171394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .voltage = __MK_FIELD(REG_LDO_SET, LDO_VSEL_MASK, 4181394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy LDO1_VSEL_SHIFT), 4191394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .ilimsel = __MK_FIELD(REG_LDO_SET, LDO_ILIM_MASK, 4201394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy LDO1_ILIM_SHIFT), 4211394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy }, 4221394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy { 4231394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .name = "LDO2", 4241394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .n_voltages = ARRAY_SIZE(ldo2_voltages), 4251394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .voltages = ldo2_voltages, 4261394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .n_ilimsels = ARRAY_SIZE(ldo_ilimsel), 4271394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .ilimsels = ldo_ilimsel, 4281394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .enable = __MK_FIELD(REG_BLOCK_EN, BLOCK_MASK, 4291394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy BLOCK_LDO2_SHIFT), 4301394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .voltage = __MK_FIELD(REG_LDO_SET, LDO_VSEL_MASK, 4311394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy LDO2_VSEL_SHIFT), 4321394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .ilimsel = __MK_FIELD(REG_LDO_SET, LDO_ILIM_MASK, 4331394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy LDO2_ILIM_SHIFT), 4341394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy }, 4351394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy { 4361394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .name = "USB", 437cac87fd34ebd79a954321f78acf38abcc69e1308Axel Lin .n_voltages = ARRAY_SIZE(fixed_5000000_voltage), 438cac87fd34ebd79a954321f78acf38abcc69e1308Axel Lin .voltages = fixed_5000000_voltage, 4391394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .n_ilimsels = ARRAY_SIZE(usb_ilimsel), 4401394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .ilimsels = usb_ilimsel, 4411394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .enable = __MK_FIELD(REG_BLOCK_EN, BLOCK_MASK, 4421394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy BLOCK_USB_SHIFT), 4431394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .ilimsel = __MK_FIELD(REG_USB, USB_ILIM_MASK, 4441394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy USB_ILIM_SHIFT), 4451394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy }, 4461394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy { 4471394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .name = "LCD", 448cac87fd34ebd79a954321f78acf38abcc69e1308Axel Lin .n_voltages = ARRAY_SIZE(fixed_5000000_voltage), 449cac87fd34ebd79a954321f78acf38abcc69e1308Axel Lin .voltages = fixed_5000000_voltage, 4501e12dfc9681fed46fbc9fffc6aba9613908c1213Axel Lin .n_ilimsels = ARRAY_SIZE(fixed_400000_ilimsel), 4511e12dfc9681fed46fbc9fffc6aba9613908c1213Axel Lin .ilimsels = fixed_400000_ilimsel, 4521394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .enable = __MK_FIELD(REG_BLOCK_EN, BLOCK_MASK, 4531394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy BLOCK_LCD_SHIFT), 4541394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy }, 4551394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy}; 4561394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 457f8ee33936f07d49b8e902920e7a5950ac2118d6aAxel Linstatic int set_voltage_sel(struct regulator_dev *rdev, unsigned selector) 4581394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy{ 4591394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy const struct supply_info *info; 4601394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy struct tps6524x *hw; 4611394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 4621394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy hw = rdev_get_drvdata(rdev); 4631394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy info = &supply_info[rdev_get_id(rdev)]; 4641394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 465cac87fd34ebd79a954321f78acf38abcc69e1308Axel Lin if (rdev->desc->n_voltages == 1) 4661394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return -EINVAL; 4671394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 468f8ee33936f07d49b8e902920e7a5950ac2118d6aAxel Lin return write_field(hw, &info->voltage, selector); 4691394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy} 4701394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 4714af7c1d313a085268d071da6729c4ed055be934fAxel Linstatic int get_voltage_sel(struct regulator_dev *rdev) 4721394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy{ 4731394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy const struct supply_info *info; 4741394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy struct tps6524x *hw; 4751394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy int ret; 4761394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 4771394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy hw = rdev_get_drvdata(rdev); 4781394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy info = &supply_info[rdev_get_id(rdev)]; 4791394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 480cac87fd34ebd79a954321f78acf38abcc69e1308Axel Lin if (rdev->desc->n_voltages == 1) 4818386a00f1443f676e8b614f654e2e324fdc0b3b3Axel Lin return 0; 4821394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 4831394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy ret = read_field(hw, &info->voltage); 4841394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy if (ret < 0) 4851394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return ret; 4861394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy if (WARN_ON(ret >= info->n_voltages)) 4871394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return -EIO; 4881394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 4894af7c1d313a085268d071da6729c4ed055be934fAxel Lin return ret; 4901394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy} 4911394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 4921394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathystatic int set_current_limit(struct regulator_dev *rdev, int min_uA, 4931394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy int max_uA) 4941394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy{ 4951394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy const struct supply_info *info; 4961394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy struct tps6524x *hw; 4971394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy int i; 4981394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 4991394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy hw = rdev_get_drvdata(rdev); 5001394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy info = &supply_info[rdev_get_id(rdev)]; 5011394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 5021e12dfc9681fed46fbc9fffc6aba9613908c1213Axel Lin if (info->n_ilimsels == 1) 5031394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return -EINVAL; 5041394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 50573f4f3d37604ff7084e6157745610c8fb07d27b6Axel Lin for (i = info->n_ilimsels - 1; i >= 0; i--) { 5061394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy if (min_uA <= info->ilimsels[i] && 5071394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy max_uA >= info->ilimsels[i]) 50873f4f3d37604ff7084e6157745610c8fb07d27b6Axel Lin return write_field(hw, &info->ilimsel, i); 50973f4f3d37604ff7084e6157745610c8fb07d27b6Axel Lin } 5101394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 51173f4f3d37604ff7084e6157745610c8fb07d27b6Axel Lin return -EINVAL; 5121394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy} 5131394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 5141394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathystatic int get_current_limit(struct regulator_dev *rdev) 5151394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy{ 5161394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy const struct supply_info *info; 5171394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy struct tps6524x *hw; 5181394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy int ret; 5191394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 5201394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy hw = rdev_get_drvdata(rdev); 5211394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy info = &supply_info[rdev_get_id(rdev)]; 5221394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 5231e12dfc9681fed46fbc9fffc6aba9613908c1213Axel Lin if (info->n_ilimsels == 1) 5241e12dfc9681fed46fbc9fffc6aba9613908c1213Axel Lin return info->ilimsels[0]; 5251394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 5261394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy ret = read_field(hw, &info->ilimsel); 5271394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy if (ret < 0) 5281394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return ret; 5291394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy if (WARN_ON(ret >= info->n_ilimsels)) 5301394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return -EIO; 5311394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 5321394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return info->ilimsels[ret]; 5331394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy} 5341394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 5351394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathystatic int enable_supply(struct regulator_dev *rdev) 5361394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy{ 5371394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy const struct supply_info *info; 5381394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy struct tps6524x *hw; 5391394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 5401394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy hw = rdev_get_drvdata(rdev); 5411394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy info = &supply_info[rdev_get_id(rdev)]; 5421394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 5431394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return write_field(hw, &info->enable, 1); 5441394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy} 5451394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 5461394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathystatic int disable_supply(struct regulator_dev *rdev) 5471394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy{ 5481394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy const struct supply_info *info; 5491394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy struct tps6524x *hw; 5501394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 5511394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy hw = rdev_get_drvdata(rdev); 5521394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy info = &supply_info[rdev_get_id(rdev)]; 5531394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 5541394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return write_field(hw, &info->enable, 0); 5551394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy} 5561394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 5571394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathystatic int is_supply_enabled(struct regulator_dev *rdev) 5581394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy{ 5591394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy const struct supply_info *info; 5601394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy struct tps6524x *hw; 5611394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 5621394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy hw = rdev_get_drvdata(rdev); 5631394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy info = &supply_info[rdev_get_id(rdev)]; 5641394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 5651394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return read_field(hw, &info->enable); 5661394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy} 5671394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 5681394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathystatic struct regulator_ops regulator_ops = { 5691394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .is_enabled = is_supply_enabled, 5701394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .enable = enable_supply, 5711394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .disable = disable_supply, 5724af7c1d313a085268d071da6729c4ed055be934fAxel Lin .get_voltage_sel = get_voltage_sel, 573f8ee33936f07d49b8e902920e7a5950ac2118d6aAxel Lin .set_voltage_sel = set_voltage_sel, 574cac87fd34ebd79a954321f78acf38abcc69e1308Axel Lin .list_voltage = regulator_list_voltage_table, 575b92f567deb51d2ee312e02e59f60021778e657aeAxel Lin .map_voltage = regulator_map_voltage_ascend, 5761394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .set_current_limit = set_current_limit, 5771394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .get_current_limit = get_current_limit, 5781394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy}; 5791394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 580a5023574d120ca3b9337cedd4e27de90cae9aff7Bill Pembertonstatic int pmic_probe(struct spi_device *spi) 5811394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy{ 5821394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy struct tps6524x *hw; 5831394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy struct device *dev = &spi->dev; 5841394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy const struct supply_info *info = supply_info; 5851394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy struct regulator_init_data *init_data; 586c172708d38a401b2f3f841dfcd862b469fa0b670Mark Brown struct regulator_config config = { }; 5875e0855759ca621bba454747fc1b5b76a7290f50fJingoo Han int i; 5881394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 589dff91d0b721bf8f036c1071a8f16a7effaa87514Jingoo Han init_data = dev_get_platdata(dev); 5901394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy if (!init_data) { 5911394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy dev_err(dev, "could not find regulator platform data\n"); 5921394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return -EINVAL; 5931394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy } 5941394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 5959eb0c4218aa444f863e7f54909351d5b4f0fac06Axel Lin hw = devm_kzalloc(&spi->dev, sizeof(struct tps6524x), GFP_KERNEL); 596516add1d9d504c5345c7ffb32f99d9343609fddfSachin Kamat if (!hw) 5971394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return -ENOMEM; 598516add1d9d504c5345c7ffb32f99d9343609fddfSachin Kamat 5991394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy spi_set_drvdata(spi, hw); 6001394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 6011394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy memset(hw, 0, sizeof(struct tps6524x)); 6021394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy hw->dev = dev; 6031394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy hw->spi = spi_dev_get(spi); 6041394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy mutex_init(&hw->lock); 6051394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 6061394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy for (i = 0; i < N_REGULATORS; i++, info++, init_data++) { 6071394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy hw->desc[i].name = info->name; 6081394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy hw->desc[i].id = i; 6091394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy hw->desc[i].n_voltages = info->n_voltages; 610cac87fd34ebd79a954321f78acf38abcc69e1308Axel Lin hw->desc[i].volt_table = info->voltages; 6111394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy hw->desc[i].ops = ®ulator_ops; 6121394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy hw->desc[i].type = REGULATOR_VOLTAGE; 6131394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy hw->desc[i].owner = THIS_MODULE; 6141394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 615c172708d38a401b2f3f841dfcd862b469fa0b670Mark Brown config.dev = dev; 616c172708d38a401b2f3f841dfcd862b469fa0b670Mark Brown config.init_data = init_data; 617c172708d38a401b2f3f841dfcd862b469fa0b670Mark Brown config.driver_data = hw; 618c172708d38a401b2f3f841dfcd862b469fa0b670Mark Brown 6195e0855759ca621bba454747fc1b5b76a7290f50fJingoo Han hw->rdev[i] = devm_regulator_register(dev, &hw->desc[i], 6205e0855759ca621bba454747fc1b5b76a7290f50fJingoo Han &config); 6215e0855759ca621bba454747fc1b5b76a7290f50fJingoo Han if (IS_ERR(hw->rdev[i])) 6225e0855759ca621bba454747fc1b5b76a7290f50fJingoo Han return PTR_ERR(hw->rdev[i]); 6231394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy } 6241394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 6251394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy return 0; 6261394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy} 6271394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 6281394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathystatic struct spi_driver pmic_driver = { 6291394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .probe = pmic_probe, 6301394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .driver = { 6311394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .name = "tps6524x", 6321394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy .owner = THIS_MODULE, 6331394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy }, 6341394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy}; 6351394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 636173f24d1ffe23f46b689159ee9d6b6aa402ff2e9Mark Brownmodule_spi_driver(pmic_driver); 6371394fd2826afb2adf7f6c4833d36a0feba22e665Cyril Chemparathy 6381394fd2826afb2adf7f6c4833d36a0feba22e665Cyril ChemparathyMODULE_DESCRIPTION("TPS6524X PMIC Driver"); 6391394fd2826afb2adf7f6c4833d36a0feba22e665Cyril ChemparathyMODULE_AUTHOR("Cyril Chemparathy"); 6401394fd2826afb2adf7f6c4833d36a0feba22e665Cyril ChemparathyMODULE_LICENSE("GPL"); 6411394fd2826afb2adf7f6c4833d36a0feba22e665Cyril ChemparathyMODULE_ALIAS("spi:tps6524x"); 642