Source
/*
* Driver for Linear Technology LTC4261 I2C Negative Voltage Hot Swap Controller
*
* Copyright (C) 2010 Ericsson AB.
*
* Derived from:
*
* Driver for Linear Technology LTC4245 I2C Multiple Supply Hot Swap Controller
* Copyright (C) 2008 Ira W. Snyder <iws@ovro.caltech.edu>
*
* Datasheet: http://cds.linear.com/docs/Datasheet/42612fb.pdf
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* chip registers */
/* readonly */
/*
* Fault register bits
*/
struct ltc4261_data {
struct i2c_client *client;
struct mutex update_lock;
bool valid;
unsigned long last_updated; /* in jiffies */
/* Registers */
u8 regs[10];
};
static struct ltc4261_data *ltc4261_update_device(struct device *dev)
{
struct ltc4261_data *data = dev_get_drvdata(dev);
struct i2c_client *client = data->client;
struct ltc4261_data *ret = data;
mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ / 4) || !data->valid) {
int i;
/* Read registers -- 0x00 to 0x09 */
for (i = 0; i < ARRAY_SIZE(data->regs); i++) {
int val;
val = i2c_smbus_read_byte_data(client, i);
if (unlikely(val < 0)) {
dev_dbg(dev,
"Failed to read ADC value: error %d\n",
val);
ret = ERR_PTR(val);
data->valid = 0;
goto abort;
}
data->regs[i] = val;