static
int ti_bandgap_adc_to_mcelsius(struct ti_bandgap *bgp, int adc_val, int *t)
{
- struct ti_bandgap_data *conf = bgp->conf;
+ const struct ti_bandgap_data *conf = bgp->conf;
int ret = 0;
/* look up for temperature in the table and return the temperature */
static
int ti_bandgap_mcelsius_to_adc(struct ti_bandgap *bgp, long temp, int *adc)
{
- struct ti_bandgap_data *conf = bgp->conf;
+ const struct ti_bandgap_data *conf = bgp->conf;
const int *conv_table = bgp->conf->conv_table;
int high, low, mid, ret = 0;
if (ret)
return ret;
- bgp->conf->sensors[id].data = data;
+ bgp->regval[id].data = data;
return 0;
}
if (ret)
return ERR_PTR(ret);
- return bgp->conf->sensors[id].data;
+ return bgp->regval[id].data;
}
/*** Helper functions used during device initialization ***/
if (of_id)
bgp->conf = of_id->data;
+ /* register shadow for context save and restore */
+ bgp->regval = devm_kzalloc(&pdev->dev, sizeof(*bgp->regval) *
+ bgp->conf->sensor_count, GFP_KERNEL);
+ if (!bgp) {
+ dev_err(&pdev->dev, "Unable to allocate mem for driver ref\n");
+ return ERR_PTR(-ENOMEM);
+ }
+
i = 0;
do {
void __iomem *chunk;
struct temp_sensor_registers *tsr;
struct temp_sensor_regval *rval;
- rval = &bgp->conf->sensors[i].regval;
+ rval = &bgp->regval[i];
tsr = bgp->conf->sensors[i].registers;
if (TI_BANDGAP_HAS(bgp, MODE_CONFIG))
struct temp_sensor_regval *rval;
u32 val = 0;
- rval = &bgp->conf->sensors[i].regval;
+ rval = &bgp->regval[i];
tsr = bgp->conf->sensors[i].registers;
if (TI_BANDGAP_HAS(bgp, COUNTER))
/**
* DOC: bandgap driver data structure
* ==================================
+ *
+ * +----------+----------------+
+ * | struct temp_sensor_regval |
+ * +---------------------------+
+ * * (Array of)
+ * |
+ * |
* +-------------------+ +-----------------+
* | struct ti_bandgap |-->| struct device * |
* +----------+--------+ +-----------------+
* | | struct ti_temp_sensor |-->| struct temp_sensor_data | |
* | +-----------------------+ +------------+------------+ |
* | | |
- * | +--------------------------+ |
- * | V V |
- * | +----------+- --------------+ +----+-------------------------+ |
- * | | struct temp_sensor_regval | | struct temp_sensor_registers | |
- * | +---------------------------+ +------------------------------+ |
+ * | + |
+ * | V |
+ * | +----------+-------------------+ |
+ * | | struct temp_sensor_registers | |
+ * | +------------------------------+ |
* | |
* +-------------------------------------------------------------------+
*
struct ti_bandgap_data;
+/**
+ * struct temp_sensor_regval - temperature sensor register values and priv data
+ * @bg_mode_ctrl: temp sensor control register value
+ * @bg_ctrl: bandgap ctrl register value
+ * @bg_counter: bandgap counter value
+ * @bg_threshold: bandgap threshold register value
+ * @tshut_threshold: bandgap tshut register value
+ * @data: private data
+ *
+ * Data structure to save and restore bandgap register set context. Only
+ * required registers are shadowed, when needed.
+ */
+struct temp_sensor_regval {
+ u32 bg_mode_ctrl;
+ u32 bg_ctrl;
+ u32 bg_counter;
+ u32 bg_threshold;
+ u32 tshut_threshold;
+ void *data;
+};
+
/**
* struct ti_bandgap - bandgap device structure
* @dev: struct device pointer
* @base: io memory base address
* @conf: struct with bandgap configuration set (# sensors, conv_table, etc)
+ * @regval: temperature sensor register values
* @fclock: pointer to functional clock of temperature sensor
* @div_clk: pointer to divider clock of temperature sensor fclk
* @bg_mutex: mutex for ti_bandgap structure
struct ti_bandgap {
struct device *dev;
void __iomem *base;
- struct ti_bandgap_data *conf;
+ const struct ti_bandgap_data *conf;
+ struct temp_sensor_regval *regval;
struct clk *fclock;
struct clk *div_clk;
spinlock_t lock; /* shields this struct */
u32 clk_rate;
};
-/**
- * struct temp_sensor_regval - temperature sensor register values
- * @bg_mode_ctrl: temp sensor control register value
- * @bg_ctrl: bandgap ctrl register value
- * @bg_counter: bandgap counter value
- * @bg_threshold: bandgap threshold register value
- * @tshut_threshold: bandgap tshut register value
- *
- * Data structure to save and restore bandgap register set context. Only
- * required registers are shadowed, when needed.
- */
-struct temp_sensor_regval {
- u32 bg_mode_ctrl;
- u32 bg_ctrl;
- u32 bg_counter;
- u32 bg_threshold;
- u32 tshut_threshold;
-};
-
/**
* struct ti_temp_sensor - bandgap temperature sensor configuration data
* @ts_data: pointer to struct with thresholds, limits of temperature sensor
* @registers: pointer to the list of register offsets and bitfields
- * @regval: temperature sensor register values
* @domain: the name of the domain where the sensor is located
* @slope: sensor gradient slope info for hotspot extrapolation equation
* @const: sensor gradient const info for hotspot extrapolation equation
* with no external influence
* @constant_pcb: sensor gradient const info for hotspot extrapolation equation
* with no external influence
- * @data: private data
* @register_cooling: function to describe how this sensor is going to be cooled
* @unregister_cooling: function to release cooling data
*
struct ti_temp_sensor {
struct temp_sensor_data *ts_data;
struct temp_sensor_registers *registers;
- struct temp_sensor_regval regval;
char *domain;
/* for hotspot extrapolation */
const int slope;
const int constant;
const int slope_pcb;
const int constant_pcb;
- void *data;
int (*register_cooling)(struct ti_bandgap *bgp, int id);
int (*unregister_cooling)(struct ti_bandgap *bgp, int id);
};