Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1 | /* |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 2 | * TI Bandgap temperature sensor driver |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2011-2012 Texas Instruments Incorporated - http://www.ti.com/ |
| 5 | * Author: J Keerthy <j-keerthy@ti.com> |
| 6 | * Author: Moiz Sonasath <m-sonasath@ti.com> |
| 7 | * Couple of fixes, DT and MFD adaptation: |
| 8 | * Eduardo Valentin <eduardo.valentin@ti.com> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License |
| 12 | * version 2 as published by the Free Software Foundation. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 22 | * 02110-1301 USA |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/export.h> |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/kernel.h> |
| 30 | #include <linux/interrupt.h> |
| 31 | #include <linux/clk.h> |
| 32 | #include <linux/gpio.h> |
| 33 | #include <linux/platform_device.h> |
| 34 | #include <linux/err.h> |
| 35 | #include <linux/types.h> |
Eduardo Valentin | ebf0bd5 | 2013-03-15 09:00:35 -0400 | [diff] [blame] | 36 | #include <linux/spinlock.h> |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 37 | #include <linux/reboot.h> |
| 38 | #include <linux/of_device.h> |
| 39 | #include <linux/of_platform.h> |
| 40 | #include <linux/of_irq.h> |
Eduardo Valentin | 2aeeb8a | 2012-11-13 14:10:00 -0400 | [diff] [blame] | 41 | #include <linux/io.h> |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 42 | |
Eduardo Valentin | 7372add | 2013-03-19 10:54:19 -0400 | [diff] [blame] | 43 | #include "ti-bandgap.h" |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 44 | |
Eduardo Valentin | 8abbe71 | 2013-03-15 09:00:05 -0400 | [diff] [blame] | 45 | /*** Helper functions to access registers and their bitfields ***/ |
| 46 | |
Eduardo Valentin | 9c468aa | 2013-03-15 08:59:56 -0400 | [diff] [blame] | 47 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 48 | * ti_bandgap_readl() - simple read helper function |
| 49 | * @bgp: pointer to ti_bandgap structure |
Eduardo Valentin | 9c468aa | 2013-03-15 08:59:56 -0400 | [diff] [blame] | 50 | * @reg: desired register (offset) to be read |
| 51 | * |
| 52 | * Helper function to read bandgap registers. It uses the io remapped area. |
| 53 | * Returns the register value. |
| 54 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 55 | static u32 ti_bandgap_readl(struct ti_bandgap *bgp, u32 reg) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 56 | { |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 57 | return readl(bgp->base + reg); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 58 | } |
| 59 | |
Eduardo Valentin | 9c468aa | 2013-03-15 08:59:56 -0400 | [diff] [blame] | 60 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 61 | * ti_bandgap_writel() - simple write helper function |
| 62 | * @bgp: pointer to ti_bandgap structure |
Eduardo Valentin | 9c468aa | 2013-03-15 08:59:56 -0400 | [diff] [blame] | 63 | * @val: desired register value to be written |
| 64 | * @reg: desired register (offset) to be written |
| 65 | * |
| 66 | * Helper function to write bandgap registers. It uses the io remapped area. |
| 67 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 68 | static void ti_bandgap_writel(struct ti_bandgap *bgp, u32 val, u32 reg) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 69 | { |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 70 | writel(val, bgp->base + reg); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 71 | } |
| 72 | |
Eduardo Valentin | 9c468aa | 2013-03-15 08:59:56 -0400 | [diff] [blame] | 73 | /** |
| 74 | * DOC: macro to update bits. |
| 75 | * |
| 76 | * RMW_BITS() - used to read, modify and update bandgap bitfields. |
| 77 | * The value passed will be shifted. |
| 78 | */ |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 79 | #define RMW_BITS(bgp, id, reg, mask, val) \ |
Eduardo Valentin | d3c291a | 2013-03-15 08:59:55 -0400 | [diff] [blame] | 80 | do { \ |
| 81 | struct temp_sensor_registers *t; \ |
| 82 | u32 r; \ |
| 83 | \ |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 84 | t = bgp->conf->sensors[(id)].registers; \ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 85 | r = ti_bandgap_readl(bgp, t->reg); \ |
Eduardo Valentin | d3c291a | 2013-03-15 08:59:55 -0400 | [diff] [blame] | 86 | r &= ~t->mask; \ |
| 87 | r |= (val) << __ffs(t->mask); \ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 88 | ti_bandgap_writel(bgp, r, t->reg); \ |
Eduardo Valentin | d3c291a | 2013-03-15 08:59:55 -0400 | [diff] [blame] | 89 | } while (0) |
| 90 | |
Eduardo Valentin | 6ab5240 | 2013-03-15 09:00:06 -0400 | [diff] [blame] | 91 | /*** Basic helper functions ***/ |
| 92 | |
Eduardo Valentin | 7a556e6 | 2013-03-15 08:59:58 -0400 | [diff] [blame] | 93 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 94 | * ti_bandgap_power() - controls the power state of a bandgap device |
| 95 | * @bgp: pointer to ti_bandgap structure |
Eduardo Valentin | 7a556e6 | 2013-03-15 08:59:58 -0400 | [diff] [blame] | 96 | * @on: desired power state (1 - on, 0 - off) |
| 97 | * |
| 98 | * Used to power on/off a bandgap device instance. Only used on those |
| 99 | * that features tempsoff bit. |
| 100 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 101 | static int ti_bandgap_power(struct ti_bandgap *bgp, bool on) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 102 | { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 103 | int i; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 104 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 105 | if (!TI_BANDGAP_HAS(bgp, POWER_SWITCH)) |
Eduardo Valentin | 3d84e52 | 2013-03-15 08:59:57 -0400 | [diff] [blame] | 106 | goto exit; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 107 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 108 | for (i = 0; i < bgp->conf->sensor_count; i++) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 109 | /* active on 0 */ |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 110 | RMW_BITS(bgp, i, temp_sensor_ctrl, bgap_tempsoff_mask, !on); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 111 | |
Eduardo Valentin | 3d84e52 | 2013-03-15 08:59:57 -0400 | [diff] [blame] | 112 | exit: |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 113 | return 0; |
| 114 | } |
| 115 | |
Eduardo Valentin | 4a6554e | 2013-03-15 08:59:59 -0400 | [diff] [blame] | 116 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 117 | * ti_bandgap_read_temp() - helper function to read sensor temperature |
| 118 | * @bgp: pointer to ti_bandgap structure |
Eduardo Valentin | 4a6554e | 2013-03-15 08:59:59 -0400 | [diff] [blame] | 119 | * @id: bandgap sensor id |
| 120 | * |
| 121 | * Function to concentrate the steps to read sensor temperature register. |
| 122 | * This function is desired because, depending on bandgap device version, |
| 123 | * it might be needed to freeze the bandgap state machine, before fetching |
| 124 | * the register value. |
| 125 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 126 | static u32 ti_bandgap_read_temp(struct ti_bandgap *bgp, int id) |
Eduardo Valentin | 194a54f | 2013-02-26 18:53:33 -0400 | [diff] [blame] | 127 | { |
| 128 | struct temp_sensor_registers *tsr; |
Eduardo Valentin | d3c291a | 2013-03-15 08:59:55 -0400 | [diff] [blame] | 129 | u32 temp, reg; |
Eduardo Valentin | 194a54f | 2013-02-26 18:53:33 -0400 | [diff] [blame] | 130 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 131 | tsr = bgp->conf->sensors[id].registers; |
Eduardo Valentin | 194a54f | 2013-02-26 18:53:33 -0400 | [diff] [blame] | 132 | reg = tsr->temp_sensor_ctrl; |
| 133 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 134 | if (TI_BANDGAP_HAS(bgp, FREEZE_BIT)) { |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 135 | RMW_BITS(bgp, id, bgap_mask_ctrl, mask_freeze_mask, 1); |
Eduardo Valentin | 194a54f | 2013-02-26 18:53:33 -0400 | [diff] [blame] | 136 | /* |
| 137 | * In case we cannot read from cur_dtemp / dtemp_0, |
| 138 | * then we read from the last valid temp read |
| 139 | */ |
| 140 | reg = tsr->ctrl_dtemp_1; |
| 141 | } |
| 142 | |
| 143 | /* read temperature */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 144 | temp = ti_bandgap_readl(bgp, reg); |
Eduardo Valentin | 194a54f | 2013-02-26 18:53:33 -0400 | [diff] [blame] | 145 | temp &= tsr->bgap_dtemp_mask; |
| 146 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 147 | if (TI_BANDGAP_HAS(bgp, FREEZE_BIT)) |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 148 | RMW_BITS(bgp, id, bgap_mask_ctrl, mask_freeze_mask, 0); |
Eduardo Valentin | 194a54f | 2013-02-26 18:53:33 -0400 | [diff] [blame] | 149 | |
| 150 | return temp; |
| 151 | } |
| 152 | |
Eduardo Valentin | fb65b88 | 2013-03-15 09:00:07 -0400 | [diff] [blame] | 153 | /*** IRQ handlers ***/ |
| 154 | |
Eduardo Valentin | ee07d55 | 2013-03-15 09:00:01 -0400 | [diff] [blame] | 155 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 156 | * ti_bandgap_talert_irq_handler() - handles Temperature alert IRQs |
Eduardo Valentin | ee07d55 | 2013-03-15 09:00:01 -0400 | [diff] [blame] | 157 | * @irq: IRQ number |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 158 | * @data: private data (struct ti_bandgap *) |
Eduardo Valentin | ee07d55 | 2013-03-15 09:00:01 -0400 | [diff] [blame] | 159 | * |
| 160 | * This is the Talert handler. Use it only if bandgap device features |
| 161 | * HAS(TALERT). This handler goes over all sensors and checks their |
| 162 | * conditions and acts accordingly. In case there are events pending, |
| 163 | * it will reset the event mask to wait for the opposite event (next event). |
| 164 | * Every time there is a new event, it will be reported to thermal layer. |
| 165 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 166 | static irqreturn_t ti_bandgap_talert_irq_handler(int irq, void *data) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 167 | { |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 168 | struct ti_bandgap *bgp = data; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 169 | struct temp_sensor_registers *tsr; |
Eduardo Valentin | 194a54f | 2013-02-26 18:53:33 -0400 | [diff] [blame] | 170 | u32 t_hot = 0, t_cold = 0, ctrl; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 171 | int i; |
| 172 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 173 | spin_lock(&bgp->lock); |
| 174 | for (i = 0; i < bgp->conf->sensor_count; i++) { |
| 175 | tsr = bgp->conf->sensors[i].registers; |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 176 | ctrl = ti_bandgap_readl(bgp, tsr->bgap_status); |
Eduardo Valentin | e555c95 | 2013-03-15 09:00:04 -0400 | [diff] [blame] | 177 | |
| 178 | /* Read the status of t_hot */ |
| 179 | t_hot = ctrl & tsr->status_hot_mask; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 180 | |
| 181 | /* Read the status of t_cold */ |
Eduardo Valentin | e555c95 | 2013-03-15 09:00:04 -0400 | [diff] [blame] | 182 | t_cold = ctrl & tsr->status_cold_mask; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 183 | |
| 184 | if (!t_cold && !t_hot) |
| 185 | continue; |
| 186 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 187 | ctrl = ti_bandgap_readl(bgp, tsr->bgap_mask_ctrl); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 188 | /* |
| 189 | * One TALERT interrupt: Two sources |
| 190 | * If the interrupt is due to t_hot then mask t_hot and |
| 191 | * and unmask t_cold else mask t_cold and unmask t_hot |
| 192 | */ |
| 193 | if (t_hot) { |
| 194 | ctrl &= ~tsr->mask_hot_mask; |
| 195 | ctrl |= tsr->mask_cold_mask; |
| 196 | } else if (t_cold) { |
| 197 | ctrl &= ~tsr->mask_cold_mask; |
| 198 | ctrl |= tsr->mask_hot_mask; |
| 199 | } |
| 200 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 201 | ti_bandgap_writel(bgp, ctrl, tsr->bgap_mask_ctrl); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 202 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 203 | dev_dbg(bgp->dev, |
Eduardo Valentin | 71e303f | 2012-11-13 14:10:03 -0400 | [diff] [blame] | 204 | "%s: IRQ from %s sensor: hotevent %d coldevent %d\n", |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 205 | __func__, bgp->conf->sensors[i].domain, |
Eduardo Valentin | 71e303f | 2012-11-13 14:10:03 -0400 | [diff] [blame] | 206 | t_hot, t_cold); |
| 207 | |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 208 | /* report temperature to whom may concern */ |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 209 | if (bgp->conf->report_temperature) |
| 210 | bgp->conf->report_temperature(bgp, i); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 211 | } |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 212 | spin_unlock(&bgp->lock); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 213 | |
| 214 | return IRQ_HANDLED; |
| 215 | } |
| 216 | |
Eduardo Valentin | 79857cd2 | 2013-03-15 09:00:02 -0400 | [diff] [blame] | 217 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 218 | * ti_bandgap_tshut_irq_handler() - handles Temperature shutdown signal |
Eduardo Valentin | 79857cd2 | 2013-03-15 09:00:02 -0400 | [diff] [blame] | 219 | * @irq: IRQ number |
| 220 | * @data: private data (unused) |
| 221 | * |
| 222 | * This is the Tshut handler. Use it only if bandgap device features |
| 223 | * HAS(TSHUT). If any sensor fires the Tshut signal, we simply shutdown |
| 224 | * the system. |
| 225 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 226 | static irqreturn_t ti_bandgap_tshut_irq_handler(int irq, void *data) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 227 | { |
Ruslan Ruslichenko | b3bf0e9 | 2013-02-26 18:53:24 -0400 | [diff] [blame] | 228 | pr_emerg("%s: TSHUT temperature reached. Needs shut down...\n", |
| 229 | __func__); |
| 230 | |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 231 | orderly_poweroff(true); |
| 232 | |
| 233 | return IRQ_HANDLED; |
| 234 | } |
| 235 | |
Eduardo Valentin | 2f6af4b | 2013-03-15 09:00:08 -0400 | [diff] [blame] | 236 | /*** Helper functions which manipulate conversion ADC <-> mi Celsius ***/ |
| 237 | |
Eduardo Valentin | 2577e93 | 2013-03-15 09:00:11 -0400 | [diff] [blame] | 238 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 239 | * ti_bandgap_adc_to_mcelsius() - converts an ADC value to mCelsius scale |
| 240 | * @bgp: struct ti_bandgap pointer |
Eduardo Valentin | 2577e93 | 2013-03-15 09:00:11 -0400 | [diff] [blame] | 241 | * @adc_val: value in ADC representation |
| 242 | * @t: address where to write the resulting temperature in mCelsius |
| 243 | * |
| 244 | * Simple conversion from ADC representation to mCelsius. In case the ADC value |
| 245 | * is out of the ADC conv table range, it returns -ERANGE, 0 on success. |
| 246 | * The conversion table is indexed by the ADC values. |
| 247 | */ |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 248 | static |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 249 | int ti_bandgap_adc_to_mcelsius(struct ti_bandgap *bgp, int adc_val, int *t) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 250 | { |
Eduardo Valentin | 9879b2c | 2013-03-19 10:54:23 -0400 | [diff] [blame] | 251 | const struct ti_bandgap_data *conf = bgp->conf; |
Eduardo Valentin | 2047059 | 2013-03-15 09:00:10 -0400 | [diff] [blame] | 252 | int ret = 0; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 253 | |
| 254 | /* look up for temperature in the table and return the temperature */ |
Eduardo Valentin | 26a70ed | 2013-03-15 09:00:14 -0400 | [diff] [blame] | 255 | if (adc_val < conf->adc_start_val || adc_val > conf->adc_end_val) { |
Eduardo Valentin | 2047059 | 2013-03-15 09:00:10 -0400 | [diff] [blame] | 256 | ret = -ERANGE; |
| 257 | goto exit; |
| 258 | } |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 259 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 260 | *t = bgp->conf->conv_table[adc_val - conf->adc_start_val]; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 261 | |
Eduardo Valentin | 2047059 | 2013-03-15 09:00:10 -0400 | [diff] [blame] | 262 | exit: |
| 263 | return ret; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 264 | } |
| 265 | |
Eduardo Valentin | e7f60b5 | 2013-03-15 09:00:15 -0400 | [diff] [blame] | 266 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 267 | * ti_bandgap_mcelsius_to_adc() - converts a mCelsius value to ADC scale |
| 268 | * @bgp: struct ti_bandgap pointer |
Eduardo Valentin | e7f60b5 | 2013-03-15 09:00:15 -0400 | [diff] [blame] | 269 | * @temp: value in mCelsius |
| 270 | * @adc: address where to write the resulting temperature in ADC representation |
| 271 | * |
| 272 | * Simple conversion from mCelsius to ADC values. In case the temp value |
| 273 | * is out of the ADC conv table range, it returns -ERANGE, 0 on success. |
| 274 | * The conversion table is indexed by the ADC values. |
| 275 | */ |
Eduardo Valentin | e16f072 | 2013-03-15 09:00:12 -0400 | [diff] [blame] | 276 | static |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 277 | int ti_bandgap_mcelsius_to_adc(struct ti_bandgap *bgp, long temp, int *adc) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 278 | { |
Eduardo Valentin | 9879b2c | 2013-03-19 10:54:23 -0400 | [diff] [blame] | 279 | const struct ti_bandgap_data *conf = bgp->conf; |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 280 | const int *conv_table = bgp->conf->conv_table; |
Eduardo Valentin | a619477 | 2013-03-15 09:00:13 -0400 | [diff] [blame] | 281 | int high, low, mid, ret = 0; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 282 | |
| 283 | low = 0; |
Eduardo Valentin | 26a70ed | 2013-03-15 09:00:14 -0400 | [diff] [blame] | 284 | high = conf->adc_end_val - conf->adc_start_val; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 285 | mid = (high + low) / 2; |
| 286 | |
Eduardo Valentin | a619477 | 2013-03-15 09:00:13 -0400 | [diff] [blame] | 287 | if (temp < conv_table[low] || temp > conv_table[high]) { |
| 288 | ret = -ERANGE; |
| 289 | goto exit; |
| 290 | } |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 291 | |
| 292 | while (low < high) { |
Eduardo Valentin | c8a8f84 | 2013-02-26 18:53:36 -0400 | [diff] [blame] | 293 | if (temp < conv_table[mid]) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 294 | high = mid - 1; |
| 295 | else |
| 296 | low = mid + 1; |
| 297 | mid = (low + high) / 2; |
| 298 | } |
| 299 | |
Eduardo Valentin | 26a70ed | 2013-03-15 09:00:14 -0400 | [diff] [blame] | 300 | *adc = conf->adc_start_val + low; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 301 | |
Eduardo Valentin | a619477 | 2013-03-15 09:00:13 -0400 | [diff] [blame] | 302 | exit: |
| 303 | return ret; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 304 | } |
| 305 | |
Eduardo Valentin | 8a1cefe | 2013-03-15 09:00:17 -0400 | [diff] [blame] | 306 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 307 | * ti_bandgap_add_hyst() - add hysteresis (in mCelsius) to an ADC value |
| 308 | * @bgp: struct ti_bandgap pointer |
Eduardo Valentin | 8a1cefe | 2013-03-15 09:00:17 -0400 | [diff] [blame] | 309 | * @adc_val: temperature value in ADC representation |
| 310 | * @hyst_val: hysteresis value in mCelsius |
| 311 | * @sum: address where to write the resulting temperature (in ADC scale) |
| 312 | * |
| 313 | * Adds an hysteresis value (in mCelsius) to a ADC temperature value. |
| 314 | * Returns 0 on success, -ERANGE otherwise. |
| 315 | */ |
Eduardo Valentin | 0f0ed7d | 2013-03-15 09:00:16 -0400 | [diff] [blame] | 316 | static |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 317 | int ti_bandgap_add_hyst(struct ti_bandgap *bgp, int adc_val, int hyst_val, |
| 318 | u32 *sum) |
Eduardo Valentin | 0f0ed7d | 2013-03-15 09:00:16 -0400 | [diff] [blame] | 319 | { |
| 320 | int temp, ret; |
| 321 | |
| 322 | /* |
| 323 | * Need to add in the mcelsius domain, so we have a temperature |
| 324 | * the conv_table range |
| 325 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 326 | ret = ti_bandgap_adc_to_mcelsius(bgp, adc_val, &temp); |
Eduardo Valentin | 0f0ed7d | 2013-03-15 09:00:16 -0400 | [diff] [blame] | 327 | if (ret < 0) |
| 328 | goto exit; |
| 329 | |
| 330 | temp += hyst_val; |
| 331 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 332 | ret = ti_bandgap_mcelsius_to_adc(bgp, temp, sum); |
Eduardo Valentin | 0f0ed7d | 2013-03-15 09:00:16 -0400 | [diff] [blame] | 333 | |
| 334 | exit: |
| 335 | return ret; |
| 336 | } |
| 337 | |
Eduardo Valentin | f8ccce2 | 2013-03-15 09:00:18 -0400 | [diff] [blame] | 338 | /*** Helper functions handling device Alert/Shutdown signals ***/ |
| 339 | |
Eduardo Valentin | f47f6d3 | 2013-03-15 09:00:20 -0400 | [diff] [blame] | 340 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 341 | * ti_bandgap_unmask_interrupts() - unmasks the events of thot & tcold |
| 342 | * @bgp: struct ti_bandgap pointer |
Eduardo Valentin | f47f6d3 | 2013-03-15 09:00:20 -0400 | [diff] [blame] | 343 | * @t_hot: hot temperature value to trigger alert signal |
| 344 | * @t_cold: cold temperature value to trigger alert signal |
| 345 | * |
| 346 | * Checks the requested t_hot and t_cold values and configures the IRQ event |
| 347 | * masks accordingly. Call this function only if bandgap features HAS(TALERT). |
| 348 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 349 | static void ti_bandgap_unmask_interrupts(struct ti_bandgap *bgp, int id, |
| 350 | u32 t_hot, u32 t_cold) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 351 | { |
| 352 | struct temp_sensor_registers *tsr; |
| 353 | u32 temp, reg_val; |
| 354 | |
| 355 | /* Read the current on die temperature */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 356 | temp = ti_bandgap_read_temp(bgp, id); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 357 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 358 | tsr = bgp->conf->sensors[id].registers; |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 359 | reg_val = ti_bandgap_readl(bgp, tsr->bgap_mask_ctrl); |
Eduardo Valentin | 194a54f | 2013-02-26 18:53:33 -0400 | [diff] [blame] | 360 | |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 361 | if (temp < t_hot) |
| 362 | reg_val |= tsr->mask_hot_mask; |
| 363 | else |
| 364 | reg_val &= ~tsr->mask_hot_mask; |
| 365 | |
| 366 | if (t_cold < temp) |
| 367 | reg_val |= tsr->mask_cold_mask; |
| 368 | else |
| 369 | reg_val &= ~tsr->mask_cold_mask; |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 370 | ti_bandgap_writel(bgp, reg_val, tsr->bgap_mask_ctrl); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 371 | } |
| 372 | |
Eduardo Valentin | 38d99e8 | 2013-03-15 09:00:27 -0400 | [diff] [blame] | 373 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 374 | * ti_bandgap_update_alert_threshold() - sequence to update thresholds |
| 375 | * @bgp: struct ti_bandgap pointer |
Eduardo Valentin | 38d99e8 | 2013-03-15 09:00:27 -0400 | [diff] [blame] | 376 | * @id: bandgap sensor id |
| 377 | * @val: value (ADC) of a new threshold |
| 378 | * @hot: desired threshold to be updated. true if threshold hot, false if |
| 379 | * threshold cold |
| 380 | * |
| 381 | * It will program the required thresholds (hot and cold) for TALERT signal. |
| 382 | * This function can be used to update t_hot or t_cold, depending on @hot value. |
| 383 | * It checks the resulting t_hot and t_cold values, based on the new passed @val |
| 384 | * and configures the thresholds so that t_hot is always greater than t_cold. |
| 385 | * Call this function only if bandgap features HAS(TALERT). |
| 386 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 387 | static int ti_bandgap_update_alert_threshold(struct ti_bandgap *bgp, int id, |
| 388 | int val, bool hot) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 389 | { |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 390 | struct temp_sensor_data *ts_data = bgp->conf->sensors[id].ts_data; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 391 | struct temp_sensor_registers *tsr; |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 392 | u32 thresh_val, reg_val, t_hot, t_cold; |
| 393 | int err = 0; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 394 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 395 | tsr = bgp->conf->sensors[id].registers; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 396 | |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 397 | /* obtain the current value */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 398 | thresh_val = ti_bandgap_readl(bgp, tsr->bgap_threshold); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 399 | t_cold = (thresh_val & tsr->threshold_tcold_mask) >> |
| 400 | __ffs(tsr->threshold_tcold_mask); |
| 401 | t_hot = (thresh_val & tsr->threshold_thot_mask) >> |
| 402 | __ffs(tsr->threshold_thot_mask); |
| 403 | if (hot) |
| 404 | t_hot = val; |
| 405 | else |
| 406 | t_cold = val; |
| 407 | |
| 408 | if (t_cold < t_hot) { |
| 409 | if (hot) |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 410 | err = ti_bandgap_add_hyst(bgp, t_hot, |
| 411 | -ts_data->hyst_val, |
| 412 | &t_cold); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 413 | else |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 414 | err = ti_bandgap_add_hyst(bgp, t_cold, |
| 415 | ts_data->hyst_val, |
| 416 | &t_hot); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 417 | } |
| 418 | |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 419 | /* write the new threshold values */ |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 420 | reg_val = thresh_val & ~tsr->threshold_thot_mask; |
| 421 | reg_val |= (t_hot << __ffs(tsr->threshold_thot_mask)); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 422 | reg_val |= thresh_val & ~tsr->threshold_tcold_mask; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 423 | reg_val |= (t_cold << __ffs(tsr->threshold_tcold_mask)); |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 424 | ti_bandgap_writel(bgp, reg_val, tsr->bgap_threshold); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 425 | |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 426 | if (err) { |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 427 | dev_err(bgp->dev, "failed to reprogram thot threshold\n"); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 428 | err = -EIO; |
| 429 | goto exit; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 430 | } |
| 431 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 432 | ti_bandgap_unmask_interrupts(bgp, id, t_hot, t_cold); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 433 | exit: |
| 434 | return err; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 435 | } |
| 436 | |
Eduardo Valentin | e72b7bb | 2013-03-15 09:00:38 -0400 | [diff] [blame] | 437 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 438 | * ti_bandgap_validate() - helper to check the sanity of a struct ti_bandgap |
| 439 | * @bgp: struct ti_bandgap pointer |
Eduardo Valentin | e72b7bb | 2013-03-15 09:00:38 -0400 | [diff] [blame] | 440 | * @id: bandgap sensor id |
| 441 | * |
| 442 | * Checks if the bandgap pointer is valid and if the sensor id is also |
| 443 | * applicable. |
| 444 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 445 | static inline int ti_bandgap_validate(struct ti_bandgap *bgp, int id) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 446 | { |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 447 | int ret = 0; |
| 448 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 449 | if (IS_ERR_OR_NULL(bgp)) { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 450 | pr_err("%s: invalid bandgap pointer\n", __func__); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 451 | ret = -EINVAL; |
| 452 | goto exit; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 453 | } |
| 454 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 455 | if ((id < 0) || (id >= bgp->conf->sensor_count)) { |
| 456 | dev_err(bgp->dev, "%s: sensor id out of range (%d)\n", |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 457 | __func__, id); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 458 | ret = -ERANGE; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 459 | } |
| 460 | |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 461 | exit: |
| 462 | return ret; |
| 463 | } |
| 464 | |
Eduardo Valentin | 9efa93b | 2013-03-15 09:00:28 -0400 | [diff] [blame] | 465 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 466 | * _ti_bandgap_write_threshold() - helper to update TALERT t_cold or t_hot |
| 467 | * @bgp: struct ti_bandgap pointer |
Eduardo Valentin | 9efa93b | 2013-03-15 09:00:28 -0400 | [diff] [blame] | 468 | * @id: bandgap sensor id |
| 469 | * @val: value (mCelsius) of a new threshold |
| 470 | * @hot: desired threshold to be updated. true if threshold hot, false if |
| 471 | * threshold cold |
| 472 | * |
| 473 | * It will update the required thresholds (hot and cold) for TALERT signal. |
| 474 | * This function can be used to update t_hot or t_cold, depending on @hot value. |
| 475 | * Validates the mCelsius range and update the requested threshold. |
| 476 | * Call this function only if bandgap features HAS(TALERT). |
| 477 | */ |
Eduardo Valentin | 2f8ec2a | 2013-03-19 10:54:22 -0400 | [diff] [blame] | 478 | static int _ti_bandgap_write_threshold(struct ti_bandgap *bgp, int id, int val, |
| 479 | bool hot) |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 480 | { |
| 481 | struct temp_sensor_data *ts_data; |
| 482 | struct temp_sensor_registers *tsr; |
| 483 | u32 adc_val; |
| 484 | int ret; |
| 485 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 486 | ret = ti_bandgap_validate(bgp, id); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 487 | if (ret) |
| 488 | goto exit; |
| 489 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 490 | if (!TI_BANDGAP_HAS(bgp, TALERT)) { |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 491 | ret = -ENOTSUPP; |
| 492 | goto exit; |
| 493 | } |
| 494 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 495 | ts_data = bgp->conf->sensors[id].ts_data; |
| 496 | tsr = bgp->conf->sensors[id].registers; |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 497 | if (hot) { |
| 498 | if (val < ts_data->min_temp + ts_data->hyst_val) |
| 499 | ret = -EINVAL; |
| 500 | } else { |
| 501 | if (val > ts_data->max_temp + ts_data->hyst_val) |
| 502 | ret = -EINVAL; |
| 503 | } |
| 504 | |
| 505 | if (ret) |
| 506 | goto exit; |
| 507 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 508 | ret = ti_bandgap_mcelsius_to_adc(bgp, val, &adc_val); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 509 | if (ret < 0) |
| 510 | goto exit; |
| 511 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 512 | spin_lock(&bgp->lock); |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 513 | ti_bandgap_update_alert_threshold(bgp, id, adc_val, hot); |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 514 | spin_unlock(&bgp->lock); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 515 | |
| 516 | exit: |
| 517 | return ret; |
| 518 | } |
| 519 | |
Eduardo Valentin | 7a681a5 | 2013-03-15 09:00:29 -0400 | [diff] [blame] | 520 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 521 | * _ti_bandgap_read_threshold() - helper to read TALERT t_cold or t_hot |
| 522 | * @bgp: struct ti_bandgap pointer |
Eduardo Valentin | 7a681a5 | 2013-03-15 09:00:29 -0400 | [diff] [blame] | 523 | * @id: bandgap sensor id |
| 524 | * @val: value (mCelsius) of a threshold |
| 525 | * @hot: desired threshold to be read. true if threshold hot, false if |
| 526 | * threshold cold |
| 527 | * |
| 528 | * It will fetch the required thresholds (hot and cold) for TALERT signal. |
| 529 | * This function can be used to read t_hot or t_cold, depending on @hot value. |
| 530 | * Call this function only if bandgap features HAS(TALERT). |
| 531 | */ |
Eduardo Valentin | 2f8ec2a | 2013-03-19 10:54:22 -0400 | [diff] [blame] | 532 | static int _ti_bandgap_read_threshold(struct ti_bandgap *bgp, int id, |
| 533 | int *val, bool hot) |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 534 | { |
| 535 | struct temp_sensor_registers *tsr; |
| 536 | u32 temp, mask; |
| 537 | int ret = 0; |
| 538 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 539 | ret = ti_bandgap_validate(bgp, id); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 540 | if (ret) |
| 541 | goto exit; |
| 542 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 543 | if (!TI_BANDGAP_HAS(bgp, TALERT)) { |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 544 | ret = -ENOTSUPP; |
| 545 | goto exit; |
| 546 | } |
| 547 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 548 | tsr = bgp->conf->sensors[id].registers; |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 549 | if (hot) |
| 550 | mask = tsr->threshold_thot_mask; |
| 551 | else |
| 552 | mask = tsr->threshold_tcold_mask; |
| 553 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 554 | temp = ti_bandgap_readl(bgp, tsr->bgap_threshold); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 555 | temp = (temp & mask) >> __ffs(mask); |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 556 | ret |= ti_bandgap_adc_to_mcelsius(bgp, temp, &temp); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 557 | if (ret) { |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 558 | dev_err(bgp->dev, "failed to read thot\n"); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 559 | ret = -EIO; |
| 560 | goto exit; |
| 561 | } |
| 562 | |
| 563 | *val = temp; |
| 564 | |
| 565 | exit: |
Eduardo Valentin | 648b4c6 | 2013-03-19 10:54:17 -0400 | [diff] [blame] | 566 | return ret; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 567 | } |
| 568 | |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 569 | /*** Exposed APIs ***/ |
| 570 | |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 571 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 572 | * ti_bandgap_read_thot() - reads sensor current thot |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 573 | * @bgp - pointer to bandgap instance |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 574 | * @id - sensor id |
| 575 | * @thot - resulting current thot value |
| 576 | * |
| 577 | * returns 0 on success or the proper error code |
| 578 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 579 | int ti_bandgap_read_thot(struct ti_bandgap *bgp, int id, int *thot) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 580 | { |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 581 | return _ti_bandgap_read_threshold(bgp, id, thot, true); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 585 | * ti_bandgap_write_thot() - sets sensor current thot |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 586 | * @bgp - pointer to bandgap instance |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 587 | * @id - sensor id |
| 588 | * @val - desired thot value |
| 589 | * |
| 590 | * returns 0 on success or the proper error code |
| 591 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 592 | int ti_bandgap_write_thot(struct ti_bandgap *bgp, int id, int val) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 593 | { |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 594 | return _ti_bandgap_write_threshold(bgp, id, val, true); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 598 | * ti_bandgap_read_tcold() - reads sensor current tcold |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 599 | * @bgp - pointer to bandgap instance |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 600 | * @id - sensor id |
| 601 | * @tcold - resulting current tcold value |
| 602 | * |
| 603 | * returns 0 on success or the proper error code |
| 604 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 605 | int ti_bandgap_read_tcold(struct ti_bandgap *bgp, int id, int *tcold) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 606 | { |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 607 | return _ti_bandgap_read_threshold(bgp, id, tcold, false); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 611 | * ti_bandgap_write_tcold() - sets the sensor tcold |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 612 | * @bgp - pointer to bandgap instance |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 613 | * @id - sensor id |
| 614 | * @val - desired tcold value |
| 615 | * |
| 616 | * returns 0 on success or the proper error code |
| 617 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 618 | int ti_bandgap_write_tcold(struct ti_bandgap *bgp, int id, int val) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 619 | { |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 620 | return _ti_bandgap_write_threshold(bgp, id, val, false); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 624 | * ti_bandgap_read_update_interval() - read the sensor update interval |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 625 | * @bgp - pointer to bandgap instance |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 626 | * @id - sensor id |
| 627 | * @interval - resulting update interval in miliseconds |
| 628 | * |
| 629 | * returns 0 on success or the proper error code |
| 630 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 631 | int ti_bandgap_read_update_interval(struct ti_bandgap *bgp, int id, |
| 632 | int *interval) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 633 | { |
| 634 | struct temp_sensor_registers *tsr; |
| 635 | u32 time; |
| 636 | int ret; |
| 637 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 638 | ret = ti_bandgap_validate(bgp, id); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 639 | if (ret) |
| 640 | return ret; |
| 641 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 642 | if (!TI_BANDGAP_HAS(bgp, COUNTER)) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 643 | return -ENOTSUPP; |
| 644 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 645 | tsr = bgp->conf->sensors[id].registers; |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 646 | time = ti_bandgap_readl(bgp, tsr->bgap_counter); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 647 | time = (time & tsr->counter_mask) >> __ffs(tsr->counter_mask); |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 648 | time = time * 1000 / bgp->clk_rate; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 649 | |
| 650 | *interval = time; |
| 651 | |
| 652 | return 0; |
| 653 | } |
| 654 | |
| 655 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 656 | * ti_bandgap_write_update_interval() - set the update interval |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 657 | * @bgp - pointer to bandgap instance |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 658 | * @id - sensor id |
| 659 | * @interval - desired update interval in miliseconds |
| 660 | * |
| 661 | * returns 0 on success or the proper error code |
| 662 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 663 | int ti_bandgap_write_update_interval(struct ti_bandgap *bgp, |
| 664 | int id, u32 interval) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 665 | { |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 666 | int ret = ti_bandgap_validate(bgp, id); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 667 | if (ret) |
| 668 | return ret; |
| 669 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 670 | if (!TI_BANDGAP_HAS(bgp, COUNTER)) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 671 | return -ENOTSUPP; |
| 672 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 673 | interval = interval * bgp->clk_rate / 1000; |
| 674 | spin_lock(&bgp->lock); |
| 675 | RMW_BITS(bgp, id, bgap_counter, counter_mask, interval); |
| 676 | spin_unlock(&bgp->lock); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 677 | |
| 678 | return 0; |
| 679 | } |
| 680 | |
| 681 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 682 | * ti_bandgap_read_temperature() - report current temperature |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 683 | * @bgp - pointer to bandgap instance |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 684 | * @id - sensor id |
| 685 | * @temperature - resulting temperature |
| 686 | * |
| 687 | * returns 0 on success or the proper error code |
| 688 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 689 | int ti_bandgap_read_temperature(struct ti_bandgap *bgp, int id, |
| 690 | int *temperature) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 691 | { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 692 | u32 temp; |
| 693 | int ret; |
| 694 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 695 | ret = ti_bandgap_validate(bgp, id); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 696 | if (ret) |
| 697 | return ret; |
| 698 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 699 | spin_lock(&bgp->lock); |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 700 | temp = ti_bandgap_read_temp(bgp, id); |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 701 | spin_unlock(&bgp->lock); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 702 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 703 | ret |= ti_bandgap_adc_to_mcelsius(bgp, temp, &temp); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 704 | if (ret) |
| 705 | return -EIO; |
| 706 | |
| 707 | *temperature = temp; |
| 708 | |
| 709 | return 0; |
| 710 | } |
| 711 | |
| 712 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 713 | * ti_bandgap_set_sensor_data() - helper function to store thermal |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 714 | * framework related data. |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 715 | * @bgp - pointer to bandgap instance |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 716 | * @id - sensor id |
| 717 | * @data - thermal framework related data to be stored |
| 718 | * |
| 719 | * returns 0 on success or the proper error code |
| 720 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 721 | int ti_bandgap_set_sensor_data(struct ti_bandgap *bgp, int id, void *data) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 722 | { |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 723 | int ret = ti_bandgap_validate(bgp, id); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 724 | if (ret) |
| 725 | return ret; |
| 726 | |
Eduardo Valentin | 9879b2c | 2013-03-19 10:54:23 -0400 | [diff] [blame] | 727 | bgp->regval[id].data = data; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 728 | |
| 729 | return 0; |
| 730 | } |
| 731 | |
| 732 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 733 | * ti_bandgap_get_sensor_data() - helper function to get thermal |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 734 | * framework related data. |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 735 | * @bgp - pointer to bandgap instance |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 736 | * @id - sensor id |
| 737 | * |
| 738 | * returns data stored by set function with sensor id on success or NULL |
| 739 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 740 | void *ti_bandgap_get_sensor_data(struct ti_bandgap *bgp, int id) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 741 | { |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 742 | int ret = ti_bandgap_validate(bgp, id); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 743 | if (ret) |
| 744 | return ERR_PTR(ret); |
| 745 | |
Eduardo Valentin | 9879b2c | 2013-03-19 10:54:23 -0400 | [diff] [blame] | 746 | return bgp->regval[id].data; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 747 | } |
| 748 | |
Eduardo Valentin | e195aba | 2013-03-15 09:00:22 -0400 | [diff] [blame] | 749 | /*** Helper functions used during device initialization ***/ |
| 750 | |
Eduardo Valentin | 31102a7 | 2013-03-15 09:00:26 -0400 | [diff] [blame] | 751 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 752 | * ti_bandgap_force_single_read() - executes 1 single ADC conversion |
| 753 | * @bgp: pointer to struct ti_bandgap |
Eduardo Valentin | 31102a7 | 2013-03-15 09:00:26 -0400 | [diff] [blame] | 754 | * @id: sensor id which it is desired to read 1 temperature |
| 755 | * |
| 756 | * Used to initialize the conversion state machine and set it to a valid |
| 757 | * state. Called during device initialization and context restore events. |
| 758 | */ |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 759 | static int |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 760 | ti_bandgap_force_single_read(struct ti_bandgap *bgp, int id) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 761 | { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 762 | u32 temp = 0, counter = 1000; |
| 763 | |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 764 | /* Select single conversion mode */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 765 | if (TI_BANDGAP_HAS(bgp, MODE_CONFIG)) |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 766 | RMW_BITS(bgp, id, bgap_mode_ctrl, mode_ctrl_mask, 0); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 767 | |
| 768 | /* Start of Conversion = 1 */ |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 769 | RMW_BITS(bgp, id, temp_sensor_ctrl, bgap_soc_mask, 1); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 770 | /* Wait until DTEMP is updated */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 771 | temp = ti_bandgap_read_temp(bgp, id); |
Eduardo Valentin | 194a54f | 2013-02-26 18:53:33 -0400 | [diff] [blame] | 772 | |
| 773 | while ((temp == 0) && --counter) |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 774 | temp = ti_bandgap_read_temp(bgp, id); |
Eduardo Valentin | d3c291a | 2013-03-15 08:59:55 -0400 | [diff] [blame] | 775 | /* REVISIT: Check correct condition for end of conversion */ |
Eduardo Valentin | 194a54f | 2013-02-26 18:53:33 -0400 | [diff] [blame] | 776 | |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 777 | /* Start of Conversion = 0 */ |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 778 | RMW_BITS(bgp, id, temp_sensor_ctrl, bgap_soc_mask, 0); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 779 | |
| 780 | return 0; |
| 781 | } |
| 782 | |
| 783 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 784 | * ti_bandgap_set_continous_mode() - One time enabling of continuous mode |
| 785 | * @bgp: pointer to struct ti_bandgap |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 786 | * |
Eduardo Valentin | a84b6f4 | 2013-03-15 09:00:25 -0400 | [diff] [blame] | 787 | * Call this function only if HAS(MODE_CONFIG) is set. As this driver may |
| 788 | * be used for junction temperature monitoring, it is desirable that the |
| 789 | * sensors are operational all the time, so that alerts are generated |
| 790 | * properly. |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 791 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 792 | static int ti_bandgap_set_continuous_mode(struct ti_bandgap *bgp) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 793 | { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 794 | int i; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 795 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 796 | for (i = 0; i < bgp->conf->sensor_count; i++) { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 797 | /* Perform a single read just before enabling continuous */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 798 | ti_bandgap_force_single_read(bgp, i); |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 799 | RMW_BITS(bgp, i, bgap_mode_ctrl, mode_ctrl_mask, 1); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | return 0; |
| 803 | } |
| 804 | |
Eduardo Valentin | d3790b3 | 2013-03-15 09:00:30 -0400 | [diff] [blame] | 805 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 806 | * ti_bandgap_tshut_init() - setup and initialize tshut handling |
| 807 | * @bgp: pointer to struct ti_bandgap |
Eduardo Valentin | d3790b3 | 2013-03-15 09:00:30 -0400 | [diff] [blame] | 808 | * @pdev: pointer to device struct platform_device |
| 809 | * |
| 810 | * Call this function only in case the bandgap features HAS(TSHUT). |
| 811 | * In this case, the driver needs to handle the TSHUT signal as an IRQ. |
| 812 | * The IRQ is wired as a GPIO, and for this purpose, it is required |
| 813 | * to specify which GPIO line is used. TSHUT IRQ is fired anytime |
| 814 | * one of the bandgap sensors violates the TSHUT high/hot threshold. |
| 815 | * And in that case, the system must go off. |
| 816 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 817 | static int ti_bandgap_tshut_init(struct ti_bandgap *bgp, |
| 818 | struct platform_device *pdev) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 819 | { |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 820 | int gpio_nr = bgp->tshut_gpio; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 821 | int status; |
| 822 | |
| 823 | /* Request for gpio_86 line */ |
| 824 | status = gpio_request(gpio_nr, "tshut"); |
| 825 | if (status < 0) { |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 826 | dev_err(bgp->dev, "Could not request for TSHUT GPIO:%i\n", 86); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 827 | return status; |
| 828 | } |
| 829 | status = gpio_direction_input(gpio_nr); |
| 830 | if (status) { |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 831 | dev_err(bgp->dev, "Cannot set input TSHUT GPIO %d\n", gpio_nr); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 832 | return status; |
| 833 | } |
| 834 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 835 | status = request_irq(gpio_to_irq(gpio_nr), ti_bandgap_tshut_irq_handler, |
| 836 | IRQF_TRIGGER_RISING, "tshut", NULL); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 837 | if (status) { |
| 838 | gpio_free(gpio_nr); |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 839 | dev_err(bgp->dev, "request irq failed for TSHUT"); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | return 0; |
| 843 | } |
| 844 | |
Eduardo Valentin | 094b8ac | 2013-03-15 09:00:31 -0400 | [diff] [blame] | 845 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 846 | * ti_bandgap_alert_init() - setup and initialize talert handling |
| 847 | * @bgp: pointer to struct ti_bandgap |
Eduardo Valentin | 094b8ac | 2013-03-15 09:00:31 -0400 | [diff] [blame] | 848 | * @pdev: pointer to device struct platform_device |
| 849 | * |
| 850 | * Call this function only in case the bandgap features HAS(TALERT). |
| 851 | * In this case, the driver needs to handle the TALERT signals as an IRQs. |
| 852 | * TALERT is a normal IRQ and it is fired any time thresholds (hot or cold) |
| 853 | * are violated. In these situation, the driver must reprogram the thresholds, |
| 854 | * accordingly to specified policy. |
| 855 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 856 | static int ti_bandgap_talert_init(struct ti_bandgap *bgp, |
| 857 | struct platform_device *pdev) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 858 | { |
| 859 | int ret; |
| 860 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 861 | bgp->irq = platform_get_irq(pdev, 0); |
| 862 | if (bgp->irq < 0) { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 863 | dev_err(&pdev->dev, "get_irq failed\n"); |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 864 | return bgp->irq; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 865 | } |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 866 | ret = request_threaded_irq(bgp->irq, NULL, |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 867 | ti_bandgap_talert_irq_handler, |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 868 | IRQF_TRIGGER_HIGH | IRQF_ONESHOT, |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 869 | "talert", bgp); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 870 | if (ret) { |
| 871 | dev_err(&pdev->dev, "Request threaded irq failed.\n"); |
| 872 | return ret; |
| 873 | } |
| 874 | |
| 875 | return 0; |
| 876 | } |
| 877 | |
Eduardo Valentin | e9b6f8c | 2013-03-15 09:00:32 -0400 | [diff] [blame] | 878 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 879 | * ti_bandgap_build() - parse DT and setup a struct ti_bandgap |
| 880 | * @bgp: pointer to struct ti_bandgap |
Eduardo Valentin | e9b6f8c | 2013-03-15 09:00:32 -0400 | [diff] [blame] | 881 | * @pdev: pointer to device struct platform_device |
| 882 | * |
| 883 | * Used to read the device tree properties accordingly to the bandgap |
| 884 | * matching version. Based on bandgap version and its capabilities it |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 885 | * will build a struct ti_bandgap out of the required DT entries. |
Eduardo Valentin | e9b6f8c | 2013-03-15 09:00:32 -0400 | [diff] [blame] | 886 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 887 | static const struct of_device_id of_ti_bandgap_match[]; |
| 888 | static struct ti_bandgap *ti_bandgap_build(struct platform_device *pdev) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 889 | { |
| 890 | struct device_node *node = pdev->dev.of_node; |
| 891 | const struct of_device_id *of_id; |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 892 | struct ti_bandgap *bgp; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 893 | struct resource *res; |
| 894 | u32 prop; |
| 895 | int i; |
| 896 | |
| 897 | /* just for the sake */ |
| 898 | if (!node) { |
| 899 | dev_err(&pdev->dev, "no platform information available\n"); |
| 900 | return ERR_PTR(-EINVAL); |
| 901 | } |
| 902 | |
Eduardo Valentin | f684356 | 2013-03-19 10:54:24 -0400 | [diff] [blame^] | 903 | bgp = devm_kzalloc(&pdev->dev, sizeof(*bgp), GFP_KERNEL); |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 904 | if (!bgp) { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 905 | dev_err(&pdev->dev, "Unable to allocate mem for driver ref\n"); |
| 906 | return ERR_PTR(-ENOMEM); |
| 907 | } |
| 908 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 909 | of_id = of_match_device(of_ti_bandgap_match, &pdev->dev); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 910 | if (of_id) |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 911 | bgp->conf = of_id->data; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 912 | |
Eduardo Valentin | 9879b2c | 2013-03-19 10:54:23 -0400 | [diff] [blame] | 913 | /* register shadow for context save and restore */ |
| 914 | bgp->regval = devm_kzalloc(&pdev->dev, sizeof(*bgp->regval) * |
| 915 | bgp->conf->sensor_count, GFP_KERNEL); |
| 916 | if (!bgp) { |
| 917 | dev_err(&pdev->dev, "Unable to allocate mem for driver ref\n"); |
| 918 | return ERR_PTR(-ENOMEM); |
| 919 | } |
| 920 | |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 921 | i = 0; |
| 922 | do { |
| 923 | void __iomem *chunk; |
| 924 | |
| 925 | res = platform_get_resource(pdev, IORESOURCE_MEM, i); |
| 926 | if (!res) |
| 927 | break; |
Thierry Reding | 97f4be60 | 2013-01-21 11:09:19 +0100 | [diff] [blame] | 928 | chunk = devm_ioremap_resource(&pdev->dev, res); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 929 | if (i == 0) |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 930 | bgp->base = chunk; |
Thierry Reding | 97f4be60 | 2013-01-21 11:09:19 +0100 | [diff] [blame] | 931 | if (IS_ERR(chunk)) |
| 932 | return ERR_CAST(chunk); |
Eduardo Valentin | 24796e1 | 2013-03-15 08:59:53 -0400 | [diff] [blame] | 933 | |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 934 | i++; |
| 935 | } while (res); |
| 936 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 937 | if (TI_BANDGAP_HAS(bgp, TSHUT)) { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 938 | if (of_property_read_u32(node, "ti,tshut-gpio", &prop) < 0) { |
| 939 | dev_err(&pdev->dev, "missing tshut gpio in device tree\n"); |
| 940 | return ERR_PTR(-EINVAL); |
| 941 | } |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 942 | bgp->tshut_gpio = prop; |
| 943 | if (!gpio_is_valid(bgp->tshut_gpio)) { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 944 | dev_err(&pdev->dev, "invalid gpio for tshut (%d)\n", |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 945 | bgp->tshut_gpio); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 946 | return ERR_PTR(-EINVAL); |
| 947 | } |
| 948 | } |
| 949 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 950 | return bgp; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 951 | } |
| 952 | |
Eduardo Valentin | f91ddfe | 2013-03-15 09:00:23 -0400 | [diff] [blame] | 953 | /*** Device driver call backs ***/ |
| 954 | |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 955 | static |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 956 | int ti_bandgap_probe(struct platform_device *pdev) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 957 | { |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 958 | struct ti_bandgap *bgp; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 959 | int clk_rate, ret = 0, i; |
| 960 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 961 | bgp = ti_bandgap_build(pdev); |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 962 | if (IS_ERR_OR_NULL(bgp)) { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 963 | dev_err(&pdev->dev, "failed to fetch platform data\n"); |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 964 | return PTR_ERR(bgp); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 965 | } |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 966 | bgp->dev = &pdev->dev; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 967 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 968 | if (TI_BANDGAP_HAS(bgp, TSHUT)) { |
| 969 | ret = ti_bandgap_tshut_init(bgp, pdev); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 970 | if (ret) { |
| 971 | dev_err(&pdev->dev, |
| 972 | "failed to initialize system tshut IRQ\n"); |
| 973 | return ret; |
| 974 | } |
| 975 | } |
| 976 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 977 | bgp->fclock = clk_get(NULL, bgp->conf->fclock_name); |
| 978 | ret = IS_ERR_OR_NULL(bgp->fclock); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 979 | if (ret) { |
| 980 | dev_err(&pdev->dev, "failed to request fclock reference\n"); |
| 981 | goto free_irqs; |
| 982 | } |
| 983 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 984 | bgp->div_clk = clk_get(NULL, bgp->conf->div_ck_name); |
| 985 | ret = IS_ERR_OR_NULL(bgp->div_clk); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 986 | if (ret) { |
| 987 | dev_err(&pdev->dev, |
| 988 | "failed to request div_ts_ck clock ref\n"); |
| 989 | goto free_irqs; |
| 990 | } |
| 991 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 992 | for (i = 0; i < bgp->conf->sensor_count; i++) { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 993 | struct temp_sensor_registers *tsr; |
| 994 | u32 val; |
| 995 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 996 | tsr = bgp->conf->sensors[i].registers; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 997 | /* |
| 998 | * check if the efuse has a non-zero value if not |
| 999 | * it is an untrimmed sample and the temperatures |
| 1000 | * may not be accurate |
| 1001 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1002 | val = ti_bandgap_readl(bgp, tsr->bgap_efuse); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1003 | if (ret || !val) |
| 1004 | dev_info(&pdev->dev, |
| 1005 | "Non-trimmed BGAP, Temp not accurate\n"); |
| 1006 | } |
| 1007 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1008 | clk_rate = clk_round_rate(bgp->div_clk, |
| 1009 | bgp->conf->sensors[0].ts_data->max_freq); |
| 1010 | if (clk_rate < bgp->conf->sensors[0].ts_data->min_freq || |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1011 | clk_rate == 0xffffffff) { |
| 1012 | ret = -ENODEV; |
| 1013 | dev_err(&pdev->dev, "wrong clock rate (%d)\n", clk_rate); |
| 1014 | goto put_clks; |
| 1015 | } |
| 1016 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1017 | ret = clk_set_rate(bgp->div_clk, clk_rate); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1018 | if (ret) |
| 1019 | dev_err(&pdev->dev, "Cannot re-set clock rate. Continuing\n"); |
| 1020 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1021 | bgp->clk_rate = clk_rate; |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1022 | if (TI_BANDGAP_HAS(bgp, CLK_CTRL)) |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1023 | clk_prepare_enable(bgp->fclock); |
Radhesh Fadnis | 6c9c1d6 | 2013-02-26 18:53:25 -0400 | [diff] [blame] | 1024 | |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1025 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1026 | spin_lock_init(&bgp->lock); |
| 1027 | bgp->dev = &pdev->dev; |
| 1028 | platform_set_drvdata(pdev, bgp); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1029 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1030 | ti_bandgap_power(bgp, true); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1031 | |
| 1032 | /* Set default counter to 1 for now */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1033 | if (TI_BANDGAP_HAS(bgp, COUNTER)) |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1034 | for (i = 0; i < bgp->conf->sensor_count; i++) |
| 1035 | RMW_BITS(bgp, i, bgap_counter, counter_mask, 1); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1036 | |
Eduardo Valentin | d3c291a | 2013-03-15 08:59:55 -0400 | [diff] [blame] | 1037 | /* Set default thresholds for alert and shutdown */ |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1038 | for (i = 0; i < bgp->conf->sensor_count; i++) { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1039 | struct temp_sensor_data *ts_data; |
| 1040 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1041 | ts_data = bgp->conf->sensors[i].ts_data; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1042 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1043 | if (TI_BANDGAP_HAS(bgp, TALERT)) { |
Eduardo Valentin | d3c291a | 2013-03-15 08:59:55 -0400 | [diff] [blame] | 1044 | /* Set initial Talert thresholds */ |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1045 | RMW_BITS(bgp, i, bgap_threshold, |
Eduardo Valentin | d3c291a | 2013-03-15 08:59:55 -0400 | [diff] [blame] | 1046 | threshold_tcold_mask, ts_data->t_cold); |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1047 | RMW_BITS(bgp, i, bgap_threshold, |
Eduardo Valentin | d3c291a | 2013-03-15 08:59:55 -0400 | [diff] [blame] | 1048 | threshold_thot_mask, ts_data->t_hot); |
| 1049 | /* Enable the alert events */ |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1050 | RMW_BITS(bgp, i, bgap_mask_ctrl, mask_hot_mask, 1); |
| 1051 | RMW_BITS(bgp, i, bgap_mask_ctrl, mask_cold_mask, 1); |
Eduardo Valentin | d3c291a | 2013-03-15 08:59:55 -0400 | [diff] [blame] | 1052 | } |
| 1053 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1054 | if (TI_BANDGAP_HAS(bgp, TSHUT_CONFIG)) { |
Eduardo Valentin | d3c291a | 2013-03-15 08:59:55 -0400 | [diff] [blame] | 1055 | /* Set initial Tshut thresholds */ |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1056 | RMW_BITS(bgp, i, tshut_threshold, |
Eduardo Valentin | d3c291a | 2013-03-15 08:59:55 -0400 | [diff] [blame] | 1057 | tshut_hot_mask, ts_data->tshut_hot); |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1058 | RMW_BITS(bgp, i, tshut_threshold, |
Eduardo Valentin | d3c291a | 2013-03-15 08:59:55 -0400 | [diff] [blame] | 1059 | tshut_cold_mask, ts_data->tshut_cold); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1060 | } |
| 1061 | } |
| 1062 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1063 | if (TI_BANDGAP_HAS(bgp, MODE_CONFIG)) |
| 1064 | ti_bandgap_set_continuous_mode(bgp); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1065 | |
| 1066 | /* Set .250 seconds time as default counter */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1067 | if (TI_BANDGAP_HAS(bgp, COUNTER)) |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1068 | for (i = 0; i < bgp->conf->sensor_count; i++) |
| 1069 | RMW_BITS(bgp, i, bgap_counter, counter_mask, |
| 1070 | bgp->clk_rate / 4); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1071 | |
| 1072 | /* Every thing is good? Then expose the sensors */ |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1073 | for (i = 0; i < bgp->conf->sensor_count; i++) { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1074 | char *domain; |
| 1075 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1076 | if (bgp->conf->sensors[i].register_cooling) |
| 1077 | bgp->conf->sensors[i].register_cooling(bgp, i); |
Eduardo Valentin | 04a4d10 | 2012-09-11 19:06:55 +0300 | [diff] [blame] | 1078 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1079 | domain = bgp->conf->sensors[i].domain; |
| 1080 | if (bgp->conf->expose_sensor) |
| 1081 | bgp->conf->expose_sensor(bgp, i, domain); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | /* |
| 1085 | * Enable the Interrupts once everything is set. Otherwise irq handler |
| 1086 | * might be called as soon as it is enabled where as rest of framework |
| 1087 | * is still getting initialised. |
| 1088 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1089 | if (TI_BANDGAP_HAS(bgp, TALERT)) { |
| 1090 | ret = ti_bandgap_talert_init(bgp, pdev); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1091 | if (ret) { |
| 1092 | dev_err(&pdev->dev, "failed to initialize Talert IRQ\n"); |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1093 | i = bgp->conf->sensor_count; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1094 | goto disable_clk; |
| 1095 | } |
| 1096 | } |
| 1097 | |
| 1098 | return 0; |
| 1099 | |
| 1100 | disable_clk: |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1101 | if (TI_BANDGAP_HAS(bgp, CLK_CTRL)) |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1102 | clk_disable_unprepare(bgp->fclock); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1103 | put_clks: |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1104 | clk_put(bgp->fclock); |
| 1105 | clk_put(bgp->div_clk); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1106 | free_irqs: |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1107 | if (TI_BANDGAP_HAS(bgp, TSHUT)) { |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1108 | free_irq(gpio_to_irq(bgp->tshut_gpio), NULL); |
| 1109 | gpio_free(bgp->tshut_gpio); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | return ret; |
| 1113 | } |
| 1114 | |
| 1115 | static |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1116 | int ti_bandgap_remove(struct platform_device *pdev) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1117 | { |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1118 | struct ti_bandgap *bgp = platform_get_drvdata(pdev); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1119 | int i; |
| 1120 | |
| 1121 | /* First thing is to remove sensor interfaces */ |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1122 | for (i = 0; i < bgp->conf->sensor_count; i++) { |
| 1123 | if (bgp->conf->sensors[i].register_cooling) |
| 1124 | bgp->conf->sensors[i].unregister_cooling(bgp, i); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1125 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1126 | if (bgp->conf->remove_sensor) |
| 1127 | bgp->conf->remove_sensor(bgp, i); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1128 | } |
| 1129 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1130 | ti_bandgap_power(bgp, false); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1131 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1132 | if (TI_BANDGAP_HAS(bgp, CLK_CTRL)) |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1133 | clk_disable_unprepare(bgp->fclock); |
| 1134 | clk_put(bgp->fclock); |
| 1135 | clk_put(bgp->div_clk); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1136 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1137 | if (TI_BANDGAP_HAS(bgp, TALERT)) |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1138 | free_irq(bgp->irq, bgp); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1139 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1140 | if (TI_BANDGAP_HAS(bgp, TSHUT)) { |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1141 | free_irq(gpio_to_irq(bgp->tshut_gpio), NULL); |
| 1142 | gpio_free(bgp->tshut_gpio); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | return 0; |
| 1146 | } |
| 1147 | |
| 1148 | #ifdef CONFIG_PM |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1149 | static int ti_bandgap_save_ctxt(struct ti_bandgap *bgp) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1150 | { |
| 1151 | int i; |
| 1152 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1153 | for (i = 0; i < bgp->conf->sensor_count; i++) { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1154 | struct temp_sensor_registers *tsr; |
| 1155 | struct temp_sensor_regval *rval; |
| 1156 | |
Eduardo Valentin | 9879b2c | 2013-03-19 10:54:23 -0400 | [diff] [blame] | 1157 | rval = &bgp->regval[i]; |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1158 | tsr = bgp->conf->sensors[i].registers; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1159 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1160 | if (TI_BANDGAP_HAS(bgp, MODE_CONFIG)) |
| 1161 | rval->bg_mode_ctrl = ti_bandgap_readl(bgp, |
J Keerthy | 76d2cd3 | 2012-09-11 19:06:52 +0300 | [diff] [blame] | 1162 | tsr->bgap_mode_ctrl); |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1163 | if (TI_BANDGAP_HAS(bgp, COUNTER)) |
| 1164 | rval->bg_counter = ti_bandgap_readl(bgp, |
J Keerthy | 76d2cd3 | 2012-09-11 19:06:52 +0300 | [diff] [blame] | 1165 | tsr->bgap_counter); |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1166 | if (TI_BANDGAP_HAS(bgp, TALERT)) { |
| 1167 | rval->bg_threshold = ti_bandgap_readl(bgp, |
J Keerthy | 76d2cd3 | 2012-09-11 19:06:52 +0300 | [diff] [blame] | 1168 | tsr->bgap_threshold); |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1169 | rval->bg_ctrl = ti_bandgap_readl(bgp, |
J Keerthy | 76d2cd3 | 2012-09-11 19:06:52 +0300 | [diff] [blame] | 1170 | tsr->bgap_mask_ctrl); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1171 | } |
| 1172 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1173 | if (TI_BANDGAP_HAS(bgp, TSHUT_CONFIG)) |
| 1174 | rval->tshut_threshold = ti_bandgap_readl(bgp, |
J Keerthy | 76d2cd3 | 2012-09-11 19:06:52 +0300 | [diff] [blame] | 1175 | tsr->tshut_threshold); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | return 0; |
| 1179 | } |
| 1180 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1181 | static int ti_bandgap_restore_ctxt(struct ti_bandgap *bgp) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1182 | { |
| 1183 | int i; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1184 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1185 | for (i = 0; i < bgp->conf->sensor_count; i++) { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1186 | struct temp_sensor_registers *tsr; |
| 1187 | struct temp_sensor_regval *rval; |
| 1188 | u32 val = 0; |
| 1189 | |
Eduardo Valentin | 9879b2c | 2013-03-19 10:54:23 -0400 | [diff] [blame] | 1190 | rval = &bgp->regval[i]; |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1191 | tsr = bgp->conf->sensors[i].registers; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1192 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1193 | if (TI_BANDGAP_HAS(bgp, COUNTER)) |
| 1194 | val = ti_bandgap_readl(bgp, tsr->bgap_counter); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1195 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1196 | if (TI_BANDGAP_HAS(bgp, TSHUT_CONFIG)) |
| 1197 | ti_bandgap_writel(bgp, rval->tshut_threshold, |
| 1198 | tsr->tshut_threshold); |
Radhesh Fadnis | b87ea75 | 2012-11-13 14:10:04 -0400 | [diff] [blame] | 1199 | /* Force immediate temperature measurement and update |
| 1200 | * of the DTEMP field |
| 1201 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1202 | ti_bandgap_force_single_read(bgp, i); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1203 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1204 | if (TI_BANDGAP_HAS(bgp, COUNTER)) |
| 1205 | ti_bandgap_writel(bgp, rval->bg_counter, |
| 1206 | tsr->bgap_counter); |
| 1207 | if (TI_BANDGAP_HAS(bgp, MODE_CONFIG)) |
| 1208 | ti_bandgap_writel(bgp, rval->bg_mode_ctrl, |
| 1209 | tsr->bgap_mode_ctrl); |
| 1210 | if (TI_BANDGAP_HAS(bgp, TALERT)) { |
| 1211 | ti_bandgap_writel(bgp, rval->bg_threshold, |
| 1212 | tsr->bgap_threshold); |
| 1213 | ti_bandgap_writel(bgp, rval->bg_ctrl, |
| 1214 | tsr->bgap_mask_ctrl); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1215 | } |
| 1216 | } |
| 1217 | |
| 1218 | return 0; |
| 1219 | } |
| 1220 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1221 | static int ti_bandgap_suspend(struct device *dev) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1222 | { |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1223 | struct ti_bandgap *bgp = dev_get_drvdata(dev); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1224 | int err; |
| 1225 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1226 | err = ti_bandgap_save_ctxt(bgp); |
| 1227 | ti_bandgap_power(bgp, false); |
Radhesh Fadnis | 6c9c1d6 | 2013-02-26 18:53:25 -0400 | [diff] [blame] | 1228 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1229 | if (TI_BANDGAP_HAS(bgp, CLK_CTRL)) |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1230 | clk_disable_unprepare(bgp->fclock); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1231 | |
| 1232 | return err; |
| 1233 | } |
| 1234 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1235 | static int ti_bandgap_resume(struct device *dev) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1236 | { |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1237 | struct ti_bandgap *bgp = dev_get_drvdata(dev); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1238 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1239 | if (TI_BANDGAP_HAS(bgp, CLK_CTRL)) |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1240 | clk_prepare_enable(bgp->fclock); |
Radhesh Fadnis | 6c9c1d6 | 2013-02-26 18:53:25 -0400 | [diff] [blame] | 1241 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1242 | ti_bandgap_power(bgp, true); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1243 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1244 | return ti_bandgap_restore_ctxt(bgp); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1245 | } |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1246 | static const struct dev_pm_ops ti_bandgap_dev_pm_ops = { |
| 1247 | SET_SYSTEM_SLEEP_PM_OPS(ti_bandgap_suspend, |
| 1248 | ti_bandgap_resume) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1249 | }; |
| 1250 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1251 | #define DEV_PM_OPS (&ti_bandgap_dev_pm_ops) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1252 | #else |
| 1253 | #define DEV_PM_OPS NULL |
| 1254 | #endif |
| 1255 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1256 | static const struct of_device_id of_ti_bandgap_match[] = { |
Eduardo Valentin | 1a31270 | 2012-07-12 19:02:31 +0300 | [diff] [blame] | 1257 | #ifdef CONFIG_OMAP4_THERMAL |
| 1258 | { |
| 1259 | .compatible = "ti,omap4430-bandgap", |
| 1260 | .data = (void *)&omap4430_data, |
| 1261 | }, |
| 1262 | { |
| 1263 | .compatible = "ti,omap4460-bandgap", |
| 1264 | .data = (void *)&omap4460_data, |
| 1265 | }, |
| 1266 | { |
| 1267 | .compatible = "ti,omap4470-bandgap", |
| 1268 | .data = (void *)&omap4470_data, |
| 1269 | }, |
| 1270 | #endif |
Eduardo Valentin | 949f5a5 | 2012-07-12 19:02:32 +0300 | [diff] [blame] | 1271 | #ifdef CONFIG_OMAP5_THERMAL |
| 1272 | { |
| 1273 | .compatible = "ti,omap5430-bandgap", |
| 1274 | .data = (void *)&omap5430_data, |
| 1275 | }, |
| 1276 | #endif |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1277 | /* Sentinel */ |
| 1278 | { }, |
| 1279 | }; |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1280 | MODULE_DEVICE_TABLE(of, of_ti_bandgap_match); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1281 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1282 | static struct platform_driver ti_bandgap_sensor_driver = { |
| 1283 | .probe = ti_bandgap_probe, |
| 1284 | .remove = ti_bandgap_remove, |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1285 | .driver = { |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1286 | .name = "ti-soc-thermal", |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1287 | .pm = DEV_PM_OPS, |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1288 | .of_match_table = of_ti_bandgap_match, |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1289 | }, |
| 1290 | }; |
| 1291 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1292 | module_platform_driver(ti_bandgap_sensor_driver); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1293 | |
| 1294 | MODULE_DESCRIPTION("OMAP4+ bandgap temperature sensor driver"); |
| 1295 | MODULE_LICENSE("GPL v2"); |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1296 | MODULE_ALIAS("platform:ti-soc-thermal"); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1297 | MODULE_AUTHOR("Texas Instrument Inc."); |