Source
x
/*
* Maxim MAX197 A/D Converter driver
*
* Copyright (c) 2012 Savoir-faire Linux Inc.
* Vivien Didelot <vivien.didelot@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* For further information, see the Documentation/hwmon/max197 file.
*/
/* 4V */
/* 10V */
/* 8 Analog Input Channels */
/* Control byte format */
/* Bipolarity */
/* Full range */
/* Scale coefficient for raw data */
/* List of supported chips */
enum max197_chips { max197, max199 };
/**
* struct max197_data - device instance specific data
* @pdata: Platform data.
* @hwmon_dev: The hwmon device.
* @lock: Read/Write mutex.
* @limit: Max range value (10V for MAX197, 4V for MAX199).
* @scale: Need to scale.
* @ctrl_bytes: Channels control byte.
*/
struct max197_data {
struct max197_platform_data *pdata;
struct device *hwmon_dev;
struct mutex lock;
int limit;
bool scale;
u8 ctrl_bytes[MAX197_NUM_CH];
};
static inline void max197_set_unipolarity(struct max197_data *data, int channel)
{
data->ctrl_bytes[channel] &= ~MAX197_BIP;
}
static inline void max197_set_bipolarity(struct max197_data *data, int channel)
{
data->ctrl_bytes[channel] |= MAX197_BIP;
}
static inline void max197_set_half_range(struct max197_data *data, int channel)
{
data->ctrl_bytes[channel] &= ~MAX197_RNG;
}
static inline void max197_set_full_range(struct max197_data *data, int channel)
{
data->ctrl_bytes[channel] |= MAX197_RNG;
}
static inline bool max197_is_bipolar(struct max197_data *data, int channel)
{
return data->ctrl_bytes[channel] & MAX197_BIP;
}
static inline bool max197_is_full_range(struct max197_data *data, int channel)
{
return data->ctrl_bytes[channel] & MAX197_RNG;
}
/* Function called on read access on in{0,1,2,3,4,5,6,7}_{min,max} */
static ssize_t max197_show_range(struct device *dev,
struct device_attribute *devattr, char *buf)