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 | 57d1617 | 2013-06-07 11:11:53 -0400 | [diff] [blame] | 41 | #include <linux/of_gpio.h> |
Eduardo Valentin | 2aeeb8a | 2012-11-13 14:10:00 -0400 | [diff] [blame] | 42 | #include <linux/io.h> |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 43 | |
Eduardo Valentin | 7372add | 2013-03-19 10:54:19 -0400 | [diff] [blame] | 44 | #include "ti-bandgap.h" |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 45 | |
Eduardo Valentin | 8abbe71 | 2013-03-15 09:00:05 -0400 | [diff] [blame] | 46 | /*** Helper functions to access registers and their bitfields ***/ |
| 47 | |
Eduardo Valentin | 9c468aa | 2013-03-15 08:59:56 -0400 | [diff] [blame] | 48 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 49 | * ti_bandgap_readl() - simple read helper function |
| 50 | * @bgp: pointer to ti_bandgap structure |
Eduardo Valentin | 9c468aa | 2013-03-15 08:59:56 -0400 | [diff] [blame] | 51 | * @reg: desired register (offset) to be read |
| 52 | * |
| 53 | * Helper function to read bandgap registers. It uses the io remapped area. |
Nishanth Menon | 169e8d0 | 2013-04-01 12:04:34 -0400 | [diff] [blame] | 54 | * Return: the register value. |
Eduardo Valentin | 9c468aa | 2013-03-15 08:59:56 -0400 | [diff] [blame] | 55 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 56 | static u32 ti_bandgap_readl(struct ti_bandgap *bgp, u32 reg) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 57 | { |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 58 | return readl(bgp->base + reg); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 59 | } |
| 60 | |
Eduardo Valentin | 9c468aa | 2013-03-15 08:59:56 -0400 | [diff] [blame] | 61 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 62 | * ti_bandgap_writel() - simple write helper function |
| 63 | * @bgp: pointer to ti_bandgap structure |
Eduardo Valentin | 9c468aa | 2013-03-15 08:59:56 -0400 | [diff] [blame] | 64 | * @val: desired register value to be written |
| 65 | * @reg: desired register (offset) to be written |
| 66 | * |
| 67 | * Helper function to write bandgap registers. It uses the io remapped area. |
| 68 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 69 | 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] | 70 | { |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 71 | writel(val, bgp->base + reg); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 72 | } |
| 73 | |
Eduardo Valentin | 9c468aa | 2013-03-15 08:59:56 -0400 | [diff] [blame] | 74 | /** |
| 75 | * DOC: macro to update bits. |
| 76 | * |
| 77 | * RMW_BITS() - used to read, modify and update bandgap bitfields. |
| 78 | * The value passed will be shifted. |
| 79 | */ |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 80 | #define RMW_BITS(bgp, id, reg, mask, val) \ |
Eduardo Valentin | d3c291a | 2013-03-15 08:59:55 -0400 | [diff] [blame] | 81 | do { \ |
| 82 | struct temp_sensor_registers *t; \ |
| 83 | u32 r; \ |
| 84 | \ |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 85 | t = bgp->conf->sensors[(id)].registers; \ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 86 | r = ti_bandgap_readl(bgp, t->reg); \ |
Eduardo Valentin | d3c291a | 2013-03-15 08:59:55 -0400 | [diff] [blame] | 87 | r &= ~t->mask; \ |
| 88 | r |= (val) << __ffs(t->mask); \ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 89 | ti_bandgap_writel(bgp, r, t->reg); \ |
Eduardo Valentin | d3c291a | 2013-03-15 08:59:55 -0400 | [diff] [blame] | 90 | } while (0) |
| 91 | |
Eduardo Valentin | 6ab5240 | 2013-03-15 09:00:06 -0400 | [diff] [blame] | 92 | /*** Basic helper functions ***/ |
| 93 | |
Eduardo Valentin | 7a556e6 | 2013-03-15 08:59:58 -0400 | [diff] [blame] | 94 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 95 | * ti_bandgap_power() - controls the power state of a bandgap device |
| 96 | * @bgp: pointer to ti_bandgap structure |
Eduardo Valentin | 7a556e6 | 2013-03-15 08:59:58 -0400 | [diff] [blame] | 97 | * @on: desired power state (1 - on, 0 - off) |
| 98 | * |
| 99 | * Used to power on/off a bandgap device instance. Only used on those |
| 100 | * that features tempsoff bit. |
Nishanth Menon | 169e8d0 | 2013-04-01 12:04:34 -0400 | [diff] [blame] | 101 | * |
| 102 | * Return: 0 on success, -ENOTSUPP if tempsoff is not supported. |
Eduardo Valentin | 7a556e6 | 2013-03-15 08:59:58 -0400 | [diff] [blame] | 103 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 104 | static int ti_bandgap_power(struct ti_bandgap *bgp, bool on) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 105 | { |
Eduardo Valentin | 422a306 | 2013-04-01 12:04:33 -0400 | [diff] [blame] | 106 | int i, ret = 0; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 107 | |
Eduardo Valentin | 422a306 | 2013-04-01 12:04:33 -0400 | [diff] [blame] | 108 | if (!TI_BANDGAP_HAS(bgp, POWER_SWITCH)) { |
| 109 | ret = -ENOTSUPP; |
Eduardo Valentin | 3d84e52 | 2013-03-15 08:59:57 -0400 | [diff] [blame] | 110 | goto exit; |
Eduardo Valentin | 422a306 | 2013-04-01 12:04:33 -0400 | [diff] [blame] | 111 | } |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 112 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 113 | for (i = 0; i < bgp->conf->sensor_count; i++) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 114 | /* active on 0 */ |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 115 | RMW_BITS(bgp, i, temp_sensor_ctrl, bgap_tempsoff_mask, !on); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 116 | |
Eduardo Valentin | 3d84e52 | 2013-03-15 08:59:57 -0400 | [diff] [blame] | 117 | exit: |
Eduardo Valentin | 422a306 | 2013-04-01 12:04:33 -0400 | [diff] [blame] | 118 | return ret; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 119 | } |
| 120 | |
Eduardo Valentin | 4a6554e | 2013-03-15 08:59:59 -0400 | [diff] [blame] | 121 | /** |
Keerthy | 7901063 | 2015-04-22 18:21:41 +0530 | [diff] [blame] | 122 | * ti_errata814_bandgap_read_temp() - helper function to read dra7 sensor temperature |
| 123 | * @bgp: pointer to ti_bandgap structure |
| 124 | * @reg: desired register (offset) to be read |
| 125 | * |
| 126 | * Function to read dra7 bandgap sensor temperature. This is done separately |
| 127 | * so as to workaround the errata "Bandgap Temperature read Dtemp can be |
| 128 | * corrupted" - Errata ID: i814". |
| 129 | * Read accesses to registers listed below can be corrupted due to incorrect |
| 130 | * resynchronization between clock domains. |
| 131 | * Read access to registers below can be corrupted : |
| 132 | * CTRL_CORE_DTEMP_MPU/GPU/CORE/DSPEVE/IVA_n (n = 0 to 4) |
| 133 | * CTRL_CORE_TEMP_SENSOR_MPU/GPU/CORE/DSPEVE/IVA_n |
| 134 | * |
| 135 | * Return: the register value. |
| 136 | */ |
| 137 | static u32 ti_errata814_bandgap_read_temp(struct ti_bandgap *bgp, u32 reg) |
| 138 | { |
| 139 | u32 val1, val2; |
| 140 | |
| 141 | val1 = ti_bandgap_readl(bgp, reg); |
| 142 | val2 = ti_bandgap_readl(bgp, reg); |
| 143 | |
| 144 | /* If both times we read the same value then that is right */ |
| 145 | if (val1 == val2) |
| 146 | return val1; |
| 147 | |
| 148 | /* if val1 and val2 are different read it third time */ |
| 149 | return ti_bandgap_readl(bgp, reg); |
| 150 | } |
| 151 | |
| 152 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 153 | * ti_bandgap_read_temp() - helper function to read sensor temperature |
| 154 | * @bgp: pointer to ti_bandgap structure |
Eduardo Valentin | 4a6554e | 2013-03-15 08:59:59 -0400 | [diff] [blame] | 155 | * @id: bandgap sensor id |
| 156 | * |
| 157 | * Function to concentrate the steps to read sensor temperature register. |
| 158 | * This function is desired because, depending on bandgap device version, |
| 159 | * it might be needed to freeze the bandgap state machine, before fetching |
| 160 | * the register value. |
Nishanth Menon | 169e8d0 | 2013-04-01 12:04:34 -0400 | [diff] [blame] | 161 | * |
| 162 | * Return: temperature in ADC values. |
Eduardo Valentin | 4a6554e | 2013-03-15 08:59:59 -0400 | [diff] [blame] | 163 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 164 | static u32 ti_bandgap_read_temp(struct ti_bandgap *bgp, int id) |
Eduardo Valentin | 194a54f | 2013-02-26 18:53:33 -0400 | [diff] [blame] | 165 | { |
| 166 | struct temp_sensor_registers *tsr; |
Eduardo Valentin | d3c291a | 2013-03-15 08:59:55 -0400 | [diff] [blame] | 167 | u32 temp, reg; |
Eduardo Valentin | 194a54f | 2013-02-26 18:53:33 -0400 | [diff] [blame] | 168 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 169 | tsr = bgp->conf->sensors[id].registers; |
Eduardo Valentin | 194a54f | 2013-02-26 18:53:33 -0400 | [diff] [blame] | 170 | reg = tsr->temp_sensor_ctrl; |
| 171 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 172 | if (TI_BANDGAP_HAS(bgp, FREEZE_BIT)) { |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 173 | RMW_BITS(bgp, id, bgap_mask_ctrl, mask_freeze_mask, 1); |
Eduardo Valentin | 194a54f | 2013-02-26 18:53:33 -0400 | [diff] [blame] | 174 | /* |
| 175 | * In case we cannot read from cur_dtemp / dtemp_0, |
| 176 | * then we read from the last valid temp read |
| 177 | */ |
| 178 | reg = tsr->ctrl_dtemp_1; |
| 179 | } |
| 180 | |
| 181 | /* read temperature */ |
Keerthy | 7901063 | 2015-04-22 18:21:41 +0530 | [diff] [blame] | 182 | if (TI_BANDGAP_HAS(bgp, ERRATA_814)) |
| 183 | temp = ti_errata814_bandgap_read_temp(bgp, reg); |
| 184 | else |
| 185 | temp = ti_bandgap_readl(bgp, reg); |
| 186 | |
Eduardo Valentin | 194a54f | 2013-02-26 18:53:33 -0400 | [diff] [blame] | 187 | temp &= tsr->bgap_dtemp_mask; |
| 188 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 189 | if (TI_BANDGAP_HAS(bgp, FREEZE_BIT)) |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 190 | RMW_BITS(bgp, id, bgap_mask_ctrl, mask_freeze_mask, 0); |
Eduardo Valentin | 194a54f | 2013-02-26 18:53:33 -0400 | [diff] [blame] | 191 | |
| 192 | return temp; |
| 193 | } |
| 194 | |
Eduardo Valentin | fb65b88 | 2013-03-15 09:00:07 -0400 | [diff] [blame] | 195 | /*** IRQ handlers ***/ |
| 196 | |
Eduardo Valentin | ee07d55 | 2013-03-15 09:00:01 -0400 | [diff] [blame] | 197 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 198 | * ti_bandgap_talert_irq_handler() - handles Temperature alert IRQs |
Eduardo Valentin | ee07d55 | 2013-03-15 09:00:01 -0400 | [diff] [blame] | 199 | * @irq: IRQ number |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 200 | * @data: private data (struct ti_bandgap *) |
Eduardo Valentin | ee07d55 | 2013-03-15 09:00:01 -0400 | [diff] [blame] | 201 | * |
| 202 | * This is the Talert handler. Use it only if bandgap device features |
| 203 | * HAS(TALERT). This handler goes over all sensors and checks their |
| 204 | * conditions and acts accordingly. In case there are events pending, |
| 205 | * it will reset the event mask to wait for the opposite event (next event). |
| 206 | * Every time there is a new event, it will be reported to thermal layer. |
Nishanth Menon | 169e8d0 | 2013-04-01 12:04:34 -0400 | [diff] [blame] | 207 | * |
| 208 | * Return: IRQ_HANDLED |
Eduardo Valentin | ee07d55 | 2013-03-15 09:00:01 -0400 | [diff] [blame] | 209 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 210 | static irqreturn_t ti_bandgap_talert_irq_handler(int irq, void *data) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 211 | { |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 212 | struct ti_bandgap *bgp = data; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 213 | struct temp_sensor_registers *tsr; |
Eduardo Valentin | 194a54f | 2013-02-26 18:53:33 -0400 | [diff] [blame] | 214 | u32 t_hot = 0, t_cold = 0, ctrl; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 215 | int i; |
| 216 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 217 | spin_lock(&bgp->lock); |
| 218 | for (i = 0; i < bgp->conf->sensor_count; i++) { |
| 219 | tsr = bgp->conf->sensors[i].registers; |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 220 | ctrl = ti_bandgap_readl(bgp, tsr->bgap_status); |
Eduardo Valentin | e555c95 | 2013-03-15 09:00:04 -0400 | [diff] [blame] | 221 | |
| 222 | /* Read the status of t_hot */ |
| 223 | t_hot = ctrl & tsr->status_hot_mask; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 224 | |
| 225 | /* Read the status of t_cold */ |
Eduardo Valentin | e555c95 | 2013-03-15 09:00:04 -0400 | [diff] [blame] | 226 | t_cold = ctrl & tsr->status_cold_mask; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 227 | |
| 228 | if (!t_cold && !t_hot) |
| 229 | continue; |
| 230 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 231 | ctrl = ti_bandgap_readl(bgp, tsr->bgap_mask_ctrl); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 232 | /* |
| 233 | * One TALERT interrupt: Two sources |
| 234 | * If the interrupt is due to t_hot then mask t_hot and |
| 235 | * and unmask t_cold else mask t_cold and unmask t_hot |
| 236 | */ |
| 237 | if (t_hot) { |
| 238 | ctrl &= ~tsr->mask_hot_mask; |
| 239 | ctrl |= tsr->mask_cold_mask; |
| 240 | } else if (t_cold) { |
| 241 | ctrl &= ~tsr->mask_cold_mask; |
| 242 | ctrl |= tsr->mask_hot_mask; |
| 243 | } |
| 244 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 245 | ti_bandgap_writel(bgp, ctrl, tsr->bgap_mask_ctrl); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 246 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 247 | dev_dbg(bgp->dev, |
Eduardo Valentin | 71e303f | 2012-11-13 14:10:03 -0400 | [diff] [blame] | 248 | "%s: IRQ from %s sensor: hotevent %d coldevent %d\n", |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 249 | __func__, bgp->conf->sensors[i].domain, |
Eduardo Valentin | 71e303f | 2012-11-13 14:10:03 -0400 | [diff] [blame] | 250 | t_hot, t_cold); |
| 251 | |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 252 | /* report temperature to whom may concern */ |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 253 | if (bgp->conf->report_temperature) |
| 254 | bgp->conf->report_temperature(bgp, i); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 255 | } |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 256 | spin_unlock(&bgp->lock); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 257 | |
| 258 | return IRQ_HANDLED; |
| 259 | } |
| 260 | |
Eduardo Valentin | 79857cd2 | 2013-03-15 09:00:02 -0400 | [diff] [blame] | 261 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 262 | * ti_bandgap_tshut_irq_handler() - handles Temperature shutdown signal |
Eduardo Valentin | 79857cd2 | 2013-03-15 09:00:02 -0400 | [diff] [blame] | 263 | * @irq: IRQ number |
| 264 | * @data: private data (unused) |
| 265 | * |
| 266 | * This is the Tshut handler. Use it only if bandgap device features |
| 267 | * HAS(TSHUT). If any sensor fires the Tshut signal, we simply shutdown |
| 268 | * the system. |
Nishanth Menon | 169e8d0 | 2013-04-01 12:04:34 -0400 | [diff] [blame] | 269 | * |
| 270 | * Return: IRQ_HANDLED |
Eduardo Valentin | 79857cd2 | 2013-03-15 09:00:02 -0400 | [diff] [blame] | 271 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 272 | static irqreturn_t ti_bandgap_tshut_irq_handler(int irq, void *data) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 273 | { |
Ruslan Ruslichenko | b3bf0e9 | 2013-02-26 18:53:24 -0400 | [diff] [blame] | 274 | pr_emerg("%s: TSHUT temperature reached. Needs shut down...\n", |
| 275 | __func__); |
| 276 | |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 277 | orderly_poweroff(true); |
| 278 | |
| 279 | return IRQ_HANDLED; |
| 280 | } |
| 281 | |
Eduardo Valentin | 2f6af4b | 2013-03-15 09:00:08 -0400 | [diff] [blame] | 282 | /*** Helper functions which manipulate conversion ADC <-> mi Celsius ***/ |
| 283 | |
Eduardo Valentin | 2577e93 | 2013-03-15 09:00:11 -0400 | [diff] [blame] | 284 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 285 | * ti_bandgap_adc_to_mcelsius() - converts an ADC value to mCelsius scale |
| 286 | * @bgp: struct ti_bandgap pointer |
Eduardo Valentin | 2577e93 | 2013-03-15 09:00:11 -0400 | [diff] [blame] | 287 | * @adc_val: value in ADC representation |
| 288 | * @t: address where to write the resulting temperature in mCelsius |
| 289 | * |
| 290 | * Simple conversion from ADC representation to mCelsius. In case the ADC value |
| 291 | * is out of the ADC conv table range, it returns -ERANGE, 0 on success. |
| 292 | * The conversion table is indexed by the ADC values. |
Nishanth Menon | 169e8d0 | 2013-04-01 12:04:34 -0400 | [diff] [blame] | 293 | * |
| 294 | * Return: 0 if conversion was successful, else -ERANGE in case the @adc_val |
| 295 | * argument is out of the ADC conv table range. |
Eduardo Valentin | 2577e93 | 2013-03-15 09:00:11 -0400 | [diff] [blame] | 296 | */ |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 297 | static |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 298 | 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] | 299 | { |
Eduardo Valentin | 9879b2c | 2013-03-19 10:54:23 -0400 | [diff] [blame] | 300 | const struct ti_bandgap_data *conf = bgp->conf; |
Eduardo Valentin | 2047059 | 2013-03-15 09:00:10 -0400 | [diff] [blame] | 301 | int ret = 0; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 302 | |
| 303 | /* look up for temperature in the table and return the temperature */ |
Eduardo Valentin | 26a70ed | 2013-03-15 09:00:14 -0400 | [diff] [blame] | 304 | 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] | 305 | ret = -ERANGE; |
| 306 | goto exit; |
| 307 | } |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 308 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 309 | *t = bgp->conf->conv_table[adc_val - conf->adc_start_val]; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 310 | |
Eduardo Valentin | 2047059 | 2013-03-15 09:00:10 -0400 | [diff] [blame] | 311 | exit: |
| 312 | return ret; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 313 | } |
| 314 | |
Eduardo Valentin | e7f60b5 | 2013-03-15 09:00:15 -0400 | [diff] [blame] | 315 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 316 | * ti_bandgap_mcelsius_to_adc() - converts a mCelsius value to ADC scale |
| 317 | * @bgp: struct ti_bandgap pointer |
Eduardo Valentin | e7f60b5 | 2013-03-15 09:00:15 -0400 | [diff] [blame] | 318 | * @temp: value in mCelsius |
| 319 | * @adc: address where to write the resulting temperature in ADC representation |
| 320 | * |
| 321 | * Simple conversion from mCelsius to ADC values. In case the temp value |
| 322 | * is out of the ADC conv table range, it returns -ERANGE, 0 on success. |
| 323 | * The conversion table is indexed by the ADC values. |
Nishanth Menon | 169e8d0 | 2013-04-01 12:04:34 -0400 | [diff] [blame] | 324 | * |
| 325 | * Return: 0 if conversion was successful, else -ERANGE in case the @temp |
| 326 | * argument is out of the ADC conv table range. |
Eduardo Valentin | e7f60b5 | 2013-03-15 09:00:15 -0400 | [diff] [blame] | 327 | */ |
Eduardo Valentin | e16f072 | 2013-03-15 09:00:12 -0400 | [diff] [blame] | 328 | static |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 329 | 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] | 330 | { |
Eduardo Valentin | 9879b2c | 2013-03-19 10:54:23 -0400 | [diff] [blame] | 331 | const struct ti_bandgap_data *conf = bgp->conf; |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 332 | const int *conv_table = bgp->conf->conv_table; |
Eduardo Valentin | a619477 | 2013-03-15 09:00:13 -0400 | [diff] [blame] | 333 | int high, low, mid, ret = 0; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 334 | |
| 335 | low = 0; |
Eduardo Valentin | 26a70ed | 2013-03-15 09:00:14 -0400 | [diff] [blame] | 336 | high = conf->adc_end_val - conf->adc_start_val; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 337 | mid = (high + low) / 2; |
| 338 | |
Eduardo Valentin | a619477 | 2013-03-15 09:00:13 -0400 | [diff] [blame] | 339 | if (temp < conv_table[low] || temp > conv_table[high]) { |
| 340 | ret = -ERANGE; |
| 341 | goto exit; |
| 342 | } |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 343 | |
| 344 | while (low < high) { |
Eduardo Valentin | c8a8f84 | 2013-02-26 18:53:36 -0400 | [diff] [blame] | 345 | if (temp < conv_table[mid]) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 346 | high = mid - 1; |
| 347 | else |
| 348 | low = mid + 1; |
| 349 | mid = (low + high) / 2; |
| 350 | } |
| 351 | |
Eduardo Valentin | 26a70ed | 2013-03-15 09:00:14 -0400 | [diff] [blame] | 352 | *adc = conf->adc_start_val + low; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 353 | |
Eduardo Valentin | a619477 | 2013-03-15 09:00:13 -0400 | [diff] [blame] | 354 | exit: |
| 355 | return ret; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 356 | } |
| 357 | |
Eduardo Valentin | 8a1cefe | 2013-03-15 09:00:17 -0400 | [diff] [blame] | 358 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 359 | * ti_bandgap_add_hyst() - add hysteresis (in mCelsius) to an ADC value |
| 360 | * @bgp: struct ti_bandgap pointer |
Eduardo Valentin | 8a1cefe | 2013-03-15 09:00:17 -0400 | [diff] [blame] | 361 | * @adc_val: temperature value in ADC representation |
| 362 | * @hyst_val: hysteresis value in mCelsius |
| 363 | * @sum: address where to write the resulting temperature (in ADC scale) |
| 364 | * |
| 365 | * Adds an hysteresis value (in mCelsius) to a ADC temperature value. |
Nishanth Menon | 169e8d0 | 2013-04-01 12:04:34 -0400 | [diff] [blame] | 366 | * |
| 367 | * Return: 0 on success, -ERANGE otherwise. |
Eduardo Valentin | 8a1cefe | 2013-03-15 09:00:17 -0400 | [diff] [blame] | 368 | */ |
Eduardo Valentin | 0f0ed7d | 2013-03-15 09:00:16 -0400 | [diff] [blame] | 369 | static |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 370 | int ti_bandgap_add_hyst(struct ti_bandgap *bgp, int adc_val, int hyst_val, |
| 371 | u32 *sum) |
Eduardo Valentin | 0f0ed7d | 2013-03-15 09:00:16 -0400 | [diff] [blame] | 372 | { |
| 373 | int temp, ret; |
| 374 | |
| 375 | /* |
| 376 | * Need to add in the mcelsius domain, so we have a temperature |
| 377 | * the conv_table range |
| 378 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 379 | ret = ti_bandgap_adc_to_mcelsius(bgp, adc_val, &temp); |
Eduardo Valentin | 0f0ed7d | 2013-03-15 09:00:16 -0400 | [diff] [blame] | 380 | if (ret < 0) |
| 381 | goto exit; |
| 382 | |
| 383 | temp += hyst_val; |
| 384 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 385 | ret = ti_bandgap_mcelsius_to_adc(bgp, temp, sum); |
Eduardo Valentin | 0f0ed7d | 2013-03-15 09:00:16 -0400 | [diff] [blame] | 386 | |
| 387 | exit: |
| 388 | return ret; |
| 389 | } |
| 390 | |
Eduardo Valentin | f8ccce2 | 2013-03-15 09:00:18 -0400 | [diff] [blame] | 391 | /*** Helper functions handling device Alert/Shutdown signals ***/ |
| 392 | |
Eduardo Valentin | f47f6d3 | 2013-03-15 09:00:20 -0400 | [diff] [blame] | 393 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 394 | * ti_bandgap_unmask_interrupts() - unmasks the events of thot & tcold |
| 395 | * @bgp: struct ti_bandgap pointer |
Eduardo Valentin | 61603af | 2013-03-19 10:54:25 -0400 | [diff] [blame] | 396 | * @id: bandgap sensor id |
Eduardo Valentin | f47f6d3 | 2013-03-15 09:00:20 -0400 | [diff] [blame] | 397 | * @t_hot: hot temperature value to trigger alert signal |
| 398 | * @t_cold: cold temperature value to trigger alert signal |
| 399 | * |
| 400 | * Checks the requested t_hot and t_cold values and configures the IRQ event |
| 401 | * masks accordingly. Call this function only if bandgap features HAS(TALERT). |
| 402 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 403 | static void ti_bandgap_unmask_interrupts(struct ti_bandgap *bgp, int id, |
| 404 | u32 t_hot, u32 t_cold) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 405 | { |
| 406 | struct temp_sensor_registers *tsr; |
| 407 | u32 temp, reg_val; |
| 408 | |
| 409 | /* Read the current on die temperature */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 410 | temp = ti_bandgap_read_temp(bgp, id); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 411 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 412 | tsr = bgp->conf->sensors[id].registers; |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 413 | reg_val = ti_bandgap_readl(bgp, tsr->bgap_mask_ctrl); |
Eduardo Valentin | 194a54f | 2013-02-26 18:53:33 -0400 | [diff] [blame] | 414 | |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 415 | if (temp < t_hot) |
| 416 | reg_val |= tsr->mask_hot_mask; |
| 417 | else |
| 418 | reg_val &= ~tsr->mask_hot_mask; |
| 419 | |
| 420 | if (t_cold < temp) |
| 421 | reg_val |= tsr->mask_cold_mask; |
| 422 | else |
| 423 | reg_val &= ~tsr->mask_cold_mask; |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 424 | ti_bandgap_writel(bgp, reg_val, tsr->bgap_mask_ctrl); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 425 | } |
| 426 | |
Eduardo Valentin | 38d99e8 | 2013-03-15 09:00:27 -0400 | [diff] [blame] | 427 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 428 | * ti_bandgap_update_alert_threshold() - sequence to update thresholds |
| 429 | * @bgp: struct ti_bandgap pointer |
Eduardo Valentin | 38d99e8 | 2013-03-15 09:00:27 -0400 | [diff] [blame] | 430 | * @id: bandgap sensor id |
| 431 | * @val: value (ADC) of a new threshold |
| 432 | * @hot: desired threshold to be updated. true if threshold hot, false if |
| 433 | * threshold cold |
| 434 | * |
| 435 | * It will program the required thresholds (hot and cold) for TALERT signal. |
| 436 | * This function can be used to update t_hot or t_cold, depending on @hot value. |
| 437 | * It checks the resulting t_hot and t_cold values, based on the new passed @val |
| 438 | * and configures the thresholds so that t_hot is always greater than t_cold. |
| 439 | * Call this function only if bandgap features HAS(TALERT). |
Nishanth Menon | 169e8d0 | 2013-04-01 12:04:34 -0400 | [diff] [blame] | 440 | * |
| 441 | * Return: 0 if no error, else corresponding error |
Eduardo Valentin | 38d99e8 | 2013-03-15 09:00:27 -0400 | [diff] [blame] | 442 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 443 | static int ti_bandgap_update_alert_threshold(struct ti_bandgap *bgp, int id, |
| 444 | int val, bool hot) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 445 | { |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 446 | struct temp_sensor_data *ts_data = bgp->conf->sensors[id].ts_data; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 447 | struct temp_sensor_registers *tsr; |
Keerthy | e9a90d0 | 2015-04-22 18:21:42 +0530 | [diff] [blame] | 448 | u32 thresh_val, reg_val, t_hot, t_cold, ctrl; |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 449 | int err = 0; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 450 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 451 | tsr = bgp->conf->sensors[id].registers; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 452 | |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 453 | /* obtain the current value */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 454 | thresh_val = ti_bandgap_readl(bgp, tsr->bgap_threshold); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 455 | t_cold = (thresh_val & tsr->threshold_tcold_mask) >> |
| 456 | __ffs(tsr->threshold_tcold_mask); |
| 457 | t_hot = (thresh_val & tsr->threshold_thot_mask) >> |
| 458 | __ffs(tsr->threshold_thot_mask); |
| 459 | if (hot) |
| 460 | t_hot = val; |
| 461 | else |
| 462 | t_cold = val; |
| 463 | |
Eduardo Valentin | f5d43b7 | 2013-03-19 10:54:26 -0400 | [diff] [blame] | 464 | if (t_cold > t_hot) { |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 465 | if (hot) |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 466 | err = ti_bandgap_add_hyst(bgp, t_hot, |
| 467 | -ts_data->hyst_val, |
| 468 | &t_cold); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 469 | else |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 470 | err = ti_bandgap_add_hyst(bgp, t_cold, |
| 471 | ts_data->hyst_val, |
| 472 | &t_hot); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 473 | } |
| 474 | |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 475 | /* write the new threshold values */ |
Eduardo Valentin | 0fb3c24 | 2013-03-19 10:54:27 -0400 | [diff] [blame] | 476 | reg_val = thresh_val & |
| 477 | ~(tsr->threshold_thot_mask | tsr->threshold_tcold_mask); |
| 478 | reg_val |= (t_hot << __ffs(tsr->threshold_thot_mask)) | |
| 479 | (t_cold << __ffs(tsr->threshold_tcold_mask)); |
Keerthy | e9a90d0 | 2015-04-22 18:21:42 +0530 | [diff] [blame] | 480 | |
| 481 | /** |
| 482 | * Errata i813: |
| 483 | * Spurious Thermal Alert: Talert can happen randomly while the device |
| 484 | * remains under the temperature limit defined for this event to trig. |
| 485 | * This spurious event is caused by a incorrect re-synchronization |
| 486 | * between clock domains. The comparison between configured threshold |
| 487 | * and current temperature value can happen while the value is |
| 488 | * transitioning (metastable), thus causing inappropriate event |
| 489 | * generation. No spurious event occurs as long as the threshold value |
| 490 | * stays unchanged. Spurious event can be generated while a thermal |
| 491 | * alert threshold is modified in |
| 492 | * CONTROL_BANDGAP_THRESHOLD_MPU/GPU/CORE/DSPEVE/IVA_n. |
| 493 | */ |
| 494 | |
| 495 | if (TI_BANDGAP_HAS(bgp, ERRATA_813)) { |
| 496 | /* Mask t_hot and t_cold events at the IP Level */ |
| 497 | ctrl = ti_bandgap_readl(bgp, tsr->bgap_mask_ctrl); |
| 498 | |
| 499 | if (hot) |
| 500 | ctrl &= ~tsr->mask_hot_mask; |
| 501 | else |
| 502 | ctrl &= ~tsr->mask_cold_mask; |
| 503 | |
| 504 | ti_bandgap_writel(bgp, ctrl, tsr->bgap_mask_ctrl); |
| 505 | } |
| 506 | |
| 507 | /* Write the threshold value */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 508 | ti_bandgap_writel(bgp, reg_val, tsr->bgap_threshold); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 509 | |
Keerthy | e9a90d0 | 2015-04-22 18:21:42 +0530 | [diff] [blame] | 510 | if (TI_BANDGAP_HAS(bgp, ERRATA_813)) { |
| 511 | /* Unmask t_hot and t_cold events at the IP Level */ |
| 512 | ctrl = ti_bandgap_readl(bgp, tsr->bgap_mask_ctrl); |
| 513 | if (hot) |
| 514 | ctrl |= tsr->mask_hot_mask; |
| 515 | else |
| 516 | ctrl |= tsr->mask_cold_mask; |
| 517 | |
| 518 | ti_bandgap_writel(bgp, ctrl, tsr->bgap_mask_ctrl); |
| 519 | } |
| 520 | |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 521 | if (err) { |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 522 | dev_err(bgp->dev, "failed to reprogram thot threshold\n"); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 523 | err = -EIO; |
| 524 | goto exit; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 525 | } |
| 526 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 527 | ti_bandgap_unmask_interrupts(bgp, id, t_hot, t_cold); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 528 | exit: |
| 529 | return err; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 530 | } |
| 531 | |
Eduardo Valentin | e72b7bb | 2013-03-15 09:00:38 -0400 | [diff] [blame] | 532 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 533 | * ti_bandgap_validate() - helper to check the sanity of a struct ti_bandgap |
| 534 | * @bgp: struct ti_bandgap pointer |
Eduardo Valentin | e72b7bb | 2013-03-15 09:00:38 -0400 | [diff] [blame] | 535 | * @id: bandgap sensor id |
| 536 | * |
| 537 | * Checks if the bandgap pointer is valid and if the sensor id is also |
| 538 | * applicable. |
Nishanth Menon | 169e8d0 | 2013-04-01 12:04:34 -0400 | [diff] [blame] | 539 | * |
| 540 | * Return: 0 if no errors, -EINVAL for invalid @bgp pointer or -ERANGE if |
| 541 | * @id cannot index @bgp sensors. |
Eduardo Valentin | e72b7bb | 2013-03-15 09:00:38 -0400 | [diff] [blame] | 542 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 543 | static inline int ti_bandgap_validate(struct ti_bandgap *bgp, int id) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 544 | { |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 545 | int ret = 0; |
| 546 | |
Eduardo Valentin | 0c12b5a | 2013-05-29 15:07:43 +0000 | [diff] [blame] | 547 | if (!bgp || IS_ERR(bgp)) { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 548 | pr_err("%s: invalid bandgap pointer\n", __func__); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 549 | ret = -EINVAL; |
| 550 | goto exit; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 551 | } |
| 552 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 553 | if ((id < 0) || (id >= bgp->conf->sensor_count)) { |
| 554 | dev_err(bgp->dev, "%s: sensor id out of range (%d)\n", |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 555 | __func__, id); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 556 | ret = -ERANGE; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 557 | } |
| 558 | |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 559 | exit: |
| 560 | return ret; |
| 561 | } |
| 562 | |
Eduardo Valentin | 9efa93b | 2013-03-15 09:00:28 -0400 | [diff] [blame] | 563 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 564 | * _ti_bandgap_write_threshold() - helper to update TALERT t_cold or t_hot |
| 565 | * @bgp: struct ti_bandgap pointer |
Eduardo Valentin | 9efa93b | 2013-03-15 09:00:28 -0400 | [diff] [blame] | 566 | * @id: bandgap sensor id |
| 567 | * @val: value (mCelsius) of a new threshold |
| 568 | * @hot: desired threshold to be updated. true if threshold hot, false if |
| 569 | * threshold cold |
| 570 | * |
| 571 | * It will update the required thresholds (hot and cold) for TALERT signal. |
| 572 | * This function can be used to update t_hot or t_cold, depending on @hot value. |
| 573 | * Validates the mCelsius range and update the requested threshold. |
| 574 | * Call this function only if bandgap features HAS(TALERT). |
Nishanth Menon | 169e8d0 | 2013-04-01 12:04:34 -0400 | [diff] [blame] | 575 | * |
| 576 | * Return: 0 if no error, else corresponding error value. |
Eduardo Valentin | 9efa93b | 2013-03-15 09:00:28 -0400 | [diff] [blame] | 577 | */ |
Eduardo Valentin | 2f8ec2a | 2013-03-19 10:54:22 -0400 | [diff] [blame] | 578 | static int _ti_bandgap_write_threshold(struct ti_bandgap *bgp, int id, int val, |
| 579 | bool hot) |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 580 | { |
| 581 | struct temp_sensor_data *ts_data; |
| 582 | struct temp_sensor_registers *tsr; |
| 583 | u32 adc_val; |
| 584 | int ret; |
| 585 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 586 | ret = ti_bandgap_validate(bgp, id); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 587 | if (ret) |
| 588 | goto exit; |
| 589 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 590 | if (!TI_BANDGAP_HAS(bgp, TALERT)) { |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 591 | ret = -ENOTSUPP; |
| 592 | goto exit; |
| 593 | } |
| 594 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 595 | ts_data = bgp->conf->sensors[id].ts_data; |
| 596 | tsr = bgp->conf->sensors[id].registers; |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 597 | if (hot) { |
| 598 | if (val < ts_data->min_temp + ts_data->hyst_val) |
| 599 | ret = -EINVAL; |
| 600 | } else { |
| 601 | if (val > ts_data->max_temp + ts_data->hyst_val) |
| 602 | ret = -EINVAL; |
| 603 | } |
| 604 | |
| 605 | if (ret) |
| 606 | goto exit; |
| 607 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 608 | ret = ti_bandgap_mcelsius_to_adc(bgp, val, &adc_val); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 609 | if (ret < 0) |
| 610 | goto exit; |
| 611 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 612 | spin_lock(&bgp->lock); |
Eduardo Valentin | d52361c | 2013-03-19 10:54:28 -0400 | [diff] [blame] | 613 | ret = ti_bandgap_update_alert_threshold(bgp, id, adc_val, hot); |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 614 | spin_unlock(&bgp->lock); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 615 | |
| 616 | exit: |
| 617 | return ret; |
| 618 | } |
| 619 | |
Eduardo Valentin | 7a681a5 | 2013-03-15 09:00:29 -0400 | [diff] [blame] | 620 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 621 | * _ti_bandgap_read_threshold() - helper to read TALERT t_cold or t_hot |
| 622 | * @bgp: struct ti_bandgap pointer |
Eduardo Valentin | 7a681a5 | 2013-03-15 09:00:29 -0400 | [diff] [blame] | 623 | * @id: bandgap sensor id |
| 624 | * @val: value (mCelsius) of a threshold |
| 625 | * @hot: desired threshold to be read. true if threshold hot, false if |
| 626 | * threshold cold |
| 627 | * |
| 628 | * It will fetch the required thresholds (hot and cold) for TALERT signal. |
| 629 | * This function can be used to read t_hot or t_cold, depending on @hot value. |
| 630 | * Call this function only if bandgap features HAS(TALERT). |
Nishanth Menon | 169e8d0 | 2013-04-01 12:04:34 -0400 | [diff] [blame] | 631 | * |
| 632 | * Return: 0 if no error, -ENOTSUPP if it has no TALERT support, or the |
| 633 | * corresponding error value if some operation fails. |
Eduardo Valentin | 7a681a5 | 2013-03-15 09:00:29 -0400 | [diff] [blame] | 634 | */ |
Eduardo Valentin | 2f8ec2a | 2013-03-19 10:54:22 -0400 | [diff] [blame] | 635 | static int _ti_bandgap_read_threshold(struct ti_bandgap *bgp, int id, |
| 636 | int *val, bool hot) |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 637 | { |
| 638 | struct temp_sensor_registers *tsr; |
| 639 | u32 temp, mask; |
| 640 | int ret = 0; |
| 641 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 642 | ret = ti_bandgap_validate(bgp, id); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 643 | if (ret) |
| 644 | goto exit; |
| 645 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 646 | if (!TI_BANDGAP_HAS(bgp, TALERT)) { |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 647 | ret = -ENOTSUPP; |
| 648 | goto exit; |
| 649 | } |
| 650 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 651 | tsr = bgp->conf->sensors[id].registers; |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 652 | if (hot) |
| 653 | mask = tsr->threshold_thot_mask; |
| 654 | else |
| 655 | mask = tsr->threshold_tcold_mask; |
| 656 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 657 | temp = ti_bandgap_readl(bgp, tsr->bgap_threshold); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 658 | temp = (temp & mask) >> __ffs(mask); |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 659 | ret |= ti_bandgap_adc_to_mcelsius(bgp, temp, &temp); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 660 | if (ret) { |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 661 | dev_err(bgp->dev, "failed to read thot\n"); |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 662 | ret = -EIO; |
| 663 | goto exit; |
| 664 | } |
| 665 | |
| 666 | *val = temp; |
| 667 | |
| 668 | exit: |
Eduardo Valentin | 648b4c6 | 2013-03-19 10:54:17 -0400 | [diff] [blame] | 669 | return ret; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 670 | } |
| 671 | |
Eduardo Valentin | 56f132f | 2013-03-15 09:00:21 -0400 | [diff] [blame] | 672 | /*** Exposed APIs ***/ |
| 673 | |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 674 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 675 | * ti_bandgap_read_thot() - reads sensor current thot |
Eduardo Valentin | 61603af | 2013-03-19 10:54:25 -0400 | [diff] [blame] | 676 | * @bgp: pointer to bandgap instance |
| 677 | * @id: sensor id |
| 678 | * @thot: resulting current thot value |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 679 | * |
Nishanth Menon | 169e8d0 | 2013-04-01 12:04:34 -0400 | [diff] [blame] | 680 | * Return: 0 on success or the proper error code |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 681 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 682 | 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] | 683 | { |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 684 | return _ti_bandgap_read_threshold(bgp, id, thot, true); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 688 | * ti_bandgap_write_thot() - sets sensor current thot |
Eduardo Valentin | 61603af | 2013-03-19 10:54:25 -0400 | [diff] [blame] | 689 | * @bgp: pointer to bandgap instance |
| 690 | * @id: sensor id |
| 691 | * @val: desired thot value |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 692 | * |
Nishanth Menon | 169e8d0 | 2013-04-01 12:04:34 -0400 | [diff] [blame] | 693 | * Return: 0 on success or the proper error code |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 694 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 695 | 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] | 696 | { |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 697 | return _ti_bandgap_write_threshold(bgp, id, val, true); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 701 | * ti_bandgap_read_tcold() - reads sensor current tcold |
Eduardo Valentin | 61603af | 2013-03-19 10:54:25 -0400 | [diff] [blame] | 702 | * @bgp: pointer to bandgap instance |
| 703 | * @id: sensor id |
| 704 | * @tcold: resulting current tcold value |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 705 | * |
Nishanth Menon | 169e8d0 | 2013-04-01 12:04:34 -0400 | [diff] [blame] | 706 | * Return: 0 on success or the proper error code |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 707 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 708 | 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] | 709 | { |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 710 | return _ti_bandgap_read_threshold(bgp, id, tcold, false); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 714 | * ti_bandgap_write_tcold() - sets the sensor tcold |
Eduardo Valentin | 61603af | 2013-03-19 10:54:25 -0400 | [diff] [blame] | 715 | * @bgp: pointer to bandgap instance |
| 716 | * @id: sensor id |
| 717 | * @val: desired tcold value |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 718 | * |
Nishanth Menon | 169e8d0 | 2013-04-01 12:04:34 -0400 | [diff] [blame] | 719 | * Return: 0 on success or the proper error code |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 720 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 721 | 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] | 722 | { |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 723 | return _ti_bandgap_write_threshold(bgp, id, val, false); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | /** |
J Keerthy | 58bccd0 | 2013-04-01 12:04:42 -0400 | [diff] [blame] | 727 | * ti_bandgap_read_counter() - read the sensor counter |
| 728 | * @bgp: pointer to bandgap instance |
| 729 | * @id: sensor id |
| 730 | * @interval: resulting update interval in miliseconds |
| 731 | */ |
| 732 | static void ti_bandgap_read_counter(struct ti_bandgap *bgp, int id, |
| 733 | int *interval) |
| 734 | { |
| 735 | struct temp_sensor_registers *tsr; |
| 736 | int time; |
| 737 | |
| 738 | tsr = bgp->conf->sensors[id].registers; |
| 739 | time = ti_bandgap_readl(bgp, tsr->bgap_counter); |
| 740 | time = (time & tsr->counter_mask) >> |
| 741 | __ffs(tsr->counter_mask); |
| 742 | time = time * 1000 / bgp->clk_rate; |
| 743 | *interval = time; |
| 744 | } |
| 745 | |
| 746 | /** |
| 747 | * ti_bandgap_read_counter_delay() - read the sensor counter delay |
| 748 | * @bgp: pointer to bandgap instance |
| 749 | * @id: sensor id |
| 750 | * @interval: resulting update interval in miliseconds |
| 751 | */ |
| 752 | static void ti_bandgap_read_counter_delay(struct ti_bandgap *bgp, int id, |
| 753 | int *interval) |
| 754 | { |
| 755 | struct temp_sensor_registers *tsr; |
| 756 | int reg_val; |
| 757 | |
| 758 | tsr = bgp->conf->sensors[id].registers; |
| 759 | |
| 760 | reg_val = ti_bandgap_readl(bgp, tsr->bgap_mask_ctrl); |
| 761 | reg_val = (reg_val & tsr->mask_counter_delay_mask) >> |
| 762 | __ffs(tsr->mask_counter_delay_mask); |
| 763 | switch (reg_val) { |
| 764 | case 0: |
| 765 | *interval = 0; |
| 766 | break; |
| 767 | case 1: |
| 768 | *interval = 1; |
| 769 | break; |
| 770 | case 2: |
| 771 | *interval = 10; |
| 772 | break; |
| 773 | case 3: |
| 774 | *interval = 100; |
| 775 | break; |
| 776 | case 4: |
| 777 | *interval = 250; |
| 778 | break; |
| 779 | case 5: |
| 780 | *interval = 500; |
| 781 | break; |
| 782 | default: |
| 783 | dev_warn(bgp->dev, "Wrong counter delay value read from register %X", |
| 784 | reg_val); |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 789 | * ti_bandgap_read_update_interval() - read the sensor update interval |
Eduardo Valentin | 61603af | 2013-03-19 10:54:25 -0400 | [diff] [blame] | 790 | * @bgp: pointer to bandgap instance |
| 791 | * @id: sensor id |
| 792 | * @interval: resulting update interval in miliseconds |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 793 | * |
Nishanth Menon | 169e8d0 | 2013-04-01 12:04:34 -0400 | [diff] [blame] | 794 | * Return: 0 on success or the proper error code |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 795 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 796 | int ti_bandgap_read_update_interval(struct ti_bandgap *bgp, int id, |
| 797 | int *interval) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 798 | { |
J Keerthy | 58bccd0 | 2013-04-01 12:04:42 -0400 | [diff] [blame] | 799 | int ret = 0; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 800 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 801 | ret = ti_bandgap_validate(bgp, id); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 802 | if (ret) |
J Keerthy | 58bccd0 | 2013-04-01 12:04:42 -0400 | [diff] [blame] | 803 | goto exit; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 804 | |
J Keerthy | 58bccd0 | 2013-04-01 12:04:42 -0400 | [diff] [blame] | 805 | if (!TI_BANDGAP_HAS(bgp, COUNTER) && |
| 806 | !TI_BANDGAP_HAS(bgp, COUNTER_DELAY)) { |
| 807 | ret = -ENOTSUPP; |
| 808 | goto exit; |
| 809 | } |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 810 | |
J Keerthy | 58bccd0 | 2013-04-01 12:04:42 -0400 | [diff] [blame] | 811 | if (TI_BANDGAP_HAS(bgp, COUNTER)) { |
| 812 | ti_bandgap_read_counter(bgp, id, interval); |
| 813 | goto exit; |
| 814 | } |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 815 | |
J Keerthy | 58bccd0 | 2013-04-01 12:04:42 -0400 | [diff] [blame] | 816 | ti_bandgap_read_counter_delay(bgp, id, interval); |
| 817 | exit: |
| 818 | return ret; |
| 819 | } |
| 820 | |
| 821 | /** |
| 822 | * ti_bandgap_write_counter_delay() - set the counter_delay |
| 823 | * @bgp: pointer to bandgap instance |
| 824 | * @id: sensor id |
| 825 | * @interval: desired update interval in miliseconds |
| 826 | * |
| 827 | * Return: 0 on success or the proper error code |
| 828 | */ |
| 829 | static int ti_bandgap_write_counter_delay(struct ti_bandgap *bgp, int id, |
| 830 | u32 interval) |
| 831 | { |
| 832 | int rval; |
| 833 | |
| 834 | switch (interval) { |
| 835 | case 0: /* Immediate conversion */ |
| 836 | rval = 0x0; |
| 837 | break; |
| 838 | case 1: /* Conversion after ever 1ms */ |
| 839 | rval = 0x1; |
| 840 | break; |
| 841 | case 10: /* Conversion after ever 10ms */ |
| 842 | rval = 0x2; |
| 843 | break; |
| 844 | case 100: /* Conversion after ever 100ms */ |
| 845 | rval = 0x3; |
| 846 | break; |
| 847 | case 250: /* Conversion after ever 250ms */ |
| 848 | rval = 0x4; |
| 849 | break; |
| 850 | case 500: /* Conversion after ever 500ms */ |
| 851 | rval = 0x5; |
| 852 | break; |
| 853 | default: |
| 854 | dev_warn(bgp->dev, "Delay %d ms is not supported\n", interval); |
| 855 | return -EINVAL; |
| 856 | } |
| 857 | |
| 858 | spin_lock(&bgp->lock); |
| 859 | RMW_BITS(bgp, id, bgap_mask_ctrl, mask_counter_delay_mask, rval); |
| 860 | spin_unlock(&bgp->lock); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 861 | |
| 862 | return 0; |
| 863 | } |
| 864 | |
| 865 | /** |
J Keerthy | 58bccd0 | 2013-04-01 12:04:42 -0400 | [diff] [blame] | 866 | * ti_bandgap_write_counter() - set the bandgap sensor counter |
| 867 | * @bgp: pointer to bandgap instance |
| 868 | * @id: sensor id |
| 869 | * @interval: desired update interval in miliseconds |
| 870 | */ |
| 871 | static void ti_bandgap_write_counter(struct ti_bandgap *bgp, int id, |
| 872 | u32 interval) |
| 873 | { |
| 874 | interval = interval * bgp->clk_rate / 1000; |
| 875 | spin_lock(&bgp->lock); |
| 876 | RMW_BITS(bgp, id, bgap_counter, counter_mask, interval); |
| 877 | spin_unlock(&bgp->lock); |
| 878 | } |
| 879 | |
| 880 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 881 | * ti_bandgap_write_update_interval() - set the update interval |
Eduardo Valentin | 61603af | 2013-03-19 10:54:25 -0400 | [diff] [blame] | 882 | * @bgp: pointer to bandgap instance |
| 883 | * @id: sensor id |
| 884 | * @interval: desired update interval in miliseconds |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 885 | * |
Nishanth Menon | 169e8d0 | 2013-04-01 12:04:34 -0400 | [diff] [blame] | 886 | * Return: 0 on success or the proper error code |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 887 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 888 | int ti_bandgap_write_update_interval(struct ti_bandgap *bgp, |
| 889 | int id, u32 interval) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 890 | { |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 891 | int ret = ti_bandgap_validate(bgp, id); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 892 | if (ret) |
J Keerthy | 58bccd0 | 2013-04-01 12:04:42 -0400 | [diff] [blame] | 893 | goto exit; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 894 | |
J Keerthy | 58bccd0 | 2013-04-01 12:04:42 -0400 | [diff] [blame] | 895 | if (!TI_BANDGAP_HAS(bgp, COUNTER) && |
| 896 | !TI_BANDGAP_HAS(bgp, COUNTER_DELAY)) { |
| 897 | ret = -ENOTSUPP; |
| 898 | goto exit; |
| 899 | } |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 900 | |
J Keerthy | 58bccd0 | 2013-04-01 12:04:42 -0400 | [diff] [blame] | 901 | if (TI_BANDGAP_HAS(bgp, COUNTER)) { |
| 902 | ti_bandgap_write_counter(bgp, id, interval); |
| 903 | goto exit; |
| 904 | } |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 905 | |
J Keerthy | 58bccd0 | 2013-04-01 12:04:42 -0400 | [diff] [blame] | 906 | ret = ti_bandgap_write_counter_delay(bgp, id, interval); |
| 907 | exit: |
| 908 | return ret; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 912 | * ti_bandgap_read_temperature() - report current temperature |
Eduardo Valentin | 61603af | 2013-03-19 10:54:25 -0400 | [diff] [blame] | 913 | * @bgp: pointer to bandgap instance |
| 914 | * @id: sensor id |
| 915 | * @temperature: resulting temperature |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 916 | * |
Nishanth Menon | 169e8d0 | 2013-04-01 12:04:34 -0400 | [diff] [blame] | 917 | * Return: 0 on success or the proper error code |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 918 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 919 | int ti_bandgap_read_temperature(struct ti_bandgap *bgp, int id, |
| 920 | int *temperature) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 921 | { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 922 | u32 temp; |
| 923 | int ret; |
| 924 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 925 | ret = ti_bandgap_validate(bgp, id); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 926 | if (ret) |
| 927 | return ret; |
| 928 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 929 | spin_lock(&bgp->lock); |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 930 | temp = ti_bandgap_read_temp(bgp, id); |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 931 | spin_unlock(&bgp->lock); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 932 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 933 | ret |= ti_bandgap_adc_to_mcelsius(bgp, temp, &temp); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 934 | if (ret) |
| 935 | return -EIO; |
| 936 | |
| 937 | *temperature = temp; |
| 938 | |
| 939 | return 0; |
| 940 | } |
| 941 | |
| 942 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 943 | * ti_bandgap_set_sensor_data() - helper function to store thermal |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 944 | * framework related data. |
Eduardo Valentin | 61603af | 2013-03-19 10:54:25 -0400 | [diff] [blame] | 945 | * @bgp: pointer to bandgap instance |
| 946 | * @id: sensor id |
| 947 | * @data: thermal framework related data to be stored |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 948 | * |
Nishanth Menon | 169e8d0 | 2013-04-01 12:04:34 -0400 | [diff] [blame] | 949 | * Return: 0 on success or the proper error code |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 950 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 951 | 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] | 952 | { |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 953 | int ret = ti_bandgap_validate(bgp, id); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 954 | if (ret) |
| 955 | return ret; |
| 956 | |
Eduardo Valentin | 9879b2c | 2013-03-19 10:54:23 -0400 | [diff] [blame] | 957 | bgp->regval[id].data = data; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 958 | |
| 959 | return 0; |
| 960 | } |
| 961 | |
| 962 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 963 | * ti_bandgap_get_sensor_data() - helper function to get thermal |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 964 | * framework related data. |
Eduardo Valentin | 61603af | 2013-03-19 10:54:25 -0400 | [diff] [blame] | 965 | * @bgp: pointer to bandgap instance |
| 966 | * @id: sensor id |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 967 | * |
Nishanth Menon | 169e8d0 | 2013-04-01 12:04:34 -0400 | [diff] [blame] | 968 | * Return: data stored by set function with sensor id on success or NULL |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 969 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 970 | void *ti_bandgap_get_sensor_data(struct ti_bandgap *bgp, int id) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 971 | { |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 972 | int ret = ti_bandgap_validate(bgp, id); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 973 | if (ret) |
| 974 | return ERR_PTR(ret); |
| 975 | |
Eduardo Valentin | 9879b2c | 2013-03-19 10:54:23 -0400 | [diff] [blame] | 976 | return bgp->regval[id].data; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 977 | } |
| 978 | |
Eduardo Valentin | e195aba | 2013-03-15 09:00:22 -0400 | [diff] [blame] | 979 | /*** Helper functions used during device initialization ***/ |
| 980 | |
Eduardo Valentin | 31102a7 | 2013-03-15 09:00:26 -0400 | [diff] [blame] | 981 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 982 | * ti_bandgap_force_single_read() - executes 1 single ADC conversion |
| 983 | * @bgp: pointer to struct ti_bandgap |
Eduardo Valentin | 31102a7 | 2013-03-15 09:00:26 -0400 | [diff] [blame] | 984 | * @id: sensor id which it is desired to read 1 temperature |
| 985 | * |
| 986 | * Used to initialize the conversion state machine and set it to a valid |
| 987 | * state. Called during device initialization and context restore events. |
Nishanth Menon | 169e8d0 | 2013-04-01 12:04:34 -0400 | [diff] [blame] | 988 | * |
| 989 | * Return: 0 |
Eduardo Valentin | 31102a7 | 2013-03-15 09:00:26 -0400 | [diff] [blame] | 990 | */ |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 991 | static int |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 992 | ti_bandgap_force_single_read(struct ti_bandgap *bgp, int id) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 993 | { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 994 | u32 temp = 0, counter = 1000; |
| 995 | |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 996 | /* Select single conversion mode */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 997 | if (TI_BANDGAP_HAS(bgp, MODE_CONFIG)) |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 998 | RMW_BITS(bgp, id, bgap_mode_ctrl, mode_ctrl_mask, 0); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 999 | |
| 1000 | /* Start of Conversion = 1 */ |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1001 | RMW_BITS(bgp, id, temp_sensor_ctrl, bgap_soc_mask, 1); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1002 | /* Wait until DTEMP is updated */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1003 | temp = ti_bandgap_read_temp(bgp, id); |
Eduardo Valentin | 194a54f | 2013-02-26 18:53:33 -0400 | [diff] [blame] | 1004 | |
| 1005 | while ((temp == 0) && --counter) |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1006 | temp = ti_bandgap_read_temp(bgp, id); |
Eduardo Valentin | d3c291a | 2013-03-15 08:59:55 -0400 | [diff] [blame] | 1007 | /* REVISIT: Check correct condition for end of conversion */ |
Eduardo Valentin | 194a54f | 2013-02-26 18:53:33 -0400 | [diff] [blame] | 1008 | |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1009 | /* Start of Conversion = 0 */ |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1010 | RMW_BITS(bgp, id, temp_sensor_ctrl, bgap_soc_mask, 0); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1011 | |
| 1012 | return 0; |
| 1013 | } |
| 1014 | |
| 1015 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1016 | * ti_bandgap_set_continous_mode() - One time enabling of continuous mode |
| 1017 | * @bgp: pointer to struct ti_bandgap |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1018 | * |
Eduardo Valentin | a84b6f4 | 2013-03-15 09:00:25 -0400 | [diff] [blame] | 1019 | * Call this function only if HAS(MODE_CONFIG) is set. As this driver may |
| 1020 | * be used for junction temperature monitoring, it is desirable that the |
| 1021 | * sensors are operational all the time, so that alerts are generated |
| 1022 | * properly. |
Nishanth Menon | 169e8d0 | 2013-04-01 12:04:34 -0400 | [diff] [blame] | 1023 | * |
| 1024 | * Return: 0 |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1025 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1026 | static int ti_bandgap_set_continuous_mode(struct ti_bandgap *bgp) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1027 | { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1028 | int i; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1029 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1030 | for (i = 0; i < bgp->conf->sensor_count; i++) { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1031 | /* Perform a single read just before enabling continuous */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1032 | ti_bandgap_force_single_read(bgp, i); |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1033 | RMW_BITS(bgp, i, bgap_mode_ctrl, mode_ctrl_mask, 1); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | return 0; |
| 1037 | } |
| 1038 | |
Eduardo Valentin | d3790b3 | 2013-03-15 09:00:30 -0400 | [diff] [blame] | 1039 | /** |
J Keerthy | 2f440b0 | 2013-04-01 12:04:45 -0400 | [diff] [blame] | 1040 | * ti_bandgap_get_trend() - To fetch the temperature trend of a sensor |
| 1041 | * @bgp: pointer to struct ti_bandgap |
| 1042 | * @id: id of the individual sensor |
| 1043 | * @trend: Pointer to trend. |
| 1044 | * |
| 1045 | * This function needs to be called to fetch the temperature trend of a |
| 1046 | * Particular sensor. The function computes the difference in temperature |
| 1047 | * w.r.t time. For the bandgaps with built in history buffer the temperatures |
| 1048 | * are read from the buffer and for those without the Buffer -ENOTSUPP is |
| 1049 | * returned. |
| 1050 | * |
| 1051 | * Return: 0 if no error, else return corresponding error. If no |
| 1052 | * error then the trend value is passed on to trend parameter |
| 1053 | */ |
| 1054 | int ti_bandgap_get_trend(struct ti_bandgap *bgp, int id, int *trend) |
| 1055 | { |
| 1056 | struct temp_sensor_registers *tsr; |
| 1057 | u32 temp1, temp2, reg1, reg2; |
| 1058 | int t1, t2, interval, ret = 0; |
| 1059 | |
| 1060 | ret = ti_bandgap_validate(bgp, id); |
| 1061 | if (ret) |
| 1062 | goto exit; |
| 1063 | |
| 1064 | if (!TI_BANDGAP_HAS(bgp, HISTORY_BUFFER) || |
| 1065 | !TI_BANDGAP_HAS(bgp, FREEZE_BIT)) { |
| 1066 | ret = -ENOTSUPP; |
| 1067 | goto exit; |
| 1068 | } |
| 1069 | |
Eduardo Valentin | ba0049e | 2013-06-07 19:13:13 +0000 | [diff] [blame] | 1070 | spin_lock(&bgp->lock); |
| 1071 | |
J Keerthy | 2f440b0 | 2013-04-01 12:04:45 -0400 | [diff] [blame] | 1072 | tsr = bgp->conf->sensors[id].registers; |
| 1073 | |
| 1074 | /* Freeze and read the last 2 valid readings */ |
Eduardo Valentin | ba0049e | 2013-06-07 19:13:13 +0000 | [diff] [blame] | 1075 | RMW_BITS(bgp, id, bgap_mask_ctrl, mask_freeze_mask, 1); |
J Keerthy | 2f440b0 | 2013-04-01 12:04:45 -0400 | [diff] [blame] | 1076 | reg1 = tsr->ctrl_dtemp_1; |
| 1077 | reg2 = tsr->ctrl_dtemp_2; |
| 1078 | |
| 1079 | /* read temperature from history buffer */ |
| 1080 | temp1 = ti_bandgap_readl(bgp, reg1); |
| 1081 | temp1 &= tsr->bgap_dtemp_mask; |
| 1082 | |
| 1083 | temp2 = ti_bandgap_readl(bgp, reg2); |
| 1084 | temp2 &= tsr->bgap_dtemp_mask; |
| 1085 | |
| 1086 | /* Convert from adc values to mCelsius temperature */ |
| 1087 | ret = ti_bandgap_adc_to_mcelsius(bgp, temp1, &t1); |
| 1088 | if (ret) |
Eduardo Valentin | ba0049e | 2013-06-07 19:13:13 +0000 | [diff] [blame] | 1089 | goto unfreeze; |
J Keerthy | 2f440b0 | 2013-04-01 12:04:45 -0400 | [diff] [blame] | 1090 | |
| 1091 | ret = ti_bandgap_adc_to_mcelsius(bgp, temp2, &t2); |
| 1092 | if (ret) |
Eduardo Valentin | ba0049e | 2013-06-07 19:13:13 +0000 | [diff] [blame] | 1093 | goto unfreeze; |
J Keerthy | 2f440b0 | 2013-04-01 12:04:45 -0400 | [diff] [blame] | 1094 | |
| 1095 | /* Fetch the update interval */ |
| 1096 | ret = ti_bandgap_read_update_interval(bgp, id, &interval); |
Ranganath Krishnan | e838ff8 | 2013-08-23 11:08:23 -0500 | [diff] [blame] | 1097 | if (ret) |
Eduardo Valentin | ba0049e | 2013-06-07 19:13:13 +0000 | [diff] [blame] | 1098 | goto unfreeze; |
J Keerthy | 2f440b0 | 2013-04-01 12:04:45 -0400 | [diff] [blame] | 1099 | |
Ranganath Krishnan | e838ff8 | 2013-08-23 11:08:23 -0500 | [diff] [blame] | 1100 | /* Set the interval to 1 ms if bandgap counter delay is not set */ |
| 1101 | if (interval == 0) |
| 1102 | interval = 1; |
| 1103 | |
J Keerthy | 2f440b0 | 2013-04-01 12:04:45 -0400 | [diff] [blame] | 1104 | *trend = (t1 - t2) / interval; |
| 1105 | |
| 1106 | dev_dbg(bgp->dev, "The temperatures are t1 = %d and t2 = %d and trend =%d\n", |
| 1107 | t1, t2, *trend); |
| 1108 | |
Eduardo Valentin | ba0049e | 2013-06-07 19:13:13 +0000 | [diff] [blame] | 1109 | unfreeze: |
| 1110 | RMW_BITS(bgp, id, bgap_mask_ctrl, mask_freeze_mask, 0); |
| 1111 | spin_unlock(&bgp->lock); |
J Keerthy | 2f440b0 | 2013-04-01 12:04:45 -0400 | [diff] [blame] | 1112 | exit: |
| 1113 | return ret; |
| 1114 | } |
| 1115 | |
| 1116 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1117 | * ti_bandgap_tshut_init() - setup and initialize tshut handling |
| 1118 | * @bgp: pointer to struct ti_bandgap |
Eduardo Valentin | d3790b3 | 2013-03-15 09:00:30 -0400 | [diff] [blame] | 1119 | * @pdev: pointer to device struct platform_device |
| 1120 | * |
| 1121 | * Call this function only in case the bandgap features HAS(TSHUT). |
| 1122 | * In this case, the driver needs to handle the TSHUT signal as an IRQ. |
| 1123 | * The IRQ is wired as a GPIO, and for this purpose, it is required |
| 1124 | * to specify which GPIO line is used. TSHUT IRQ is fired anytime |
| 1125 | * one of the bandgap sensors violates the TSHUT high/hot threshold. |
| 1126 | * And in that case, the system must go off. |
Nishanth Menon | 169e8d0 | 2013-04-01 12:04:34 -0400 | [diff] [blame] | 1127 | * |
| 1128 | * Return: 0 if no error, else error status |
Eduardo Valentin | d3790b3 | 2013-03-15 09:00:30 -0400 | [diff] [blame] | 1129 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1130 | static int ti_bandgap_tshut_init(struct ti_bandgap *bgp, |
| 1131 | struct platform_device *pdev) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1132 | { |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1133 | int gpio_nr = bgp->tshut_gpio; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1134 | int status; |
| 1135 | |
| 1136 | /* Request for gpio_86 line */ |
| 1137 | status = gpio_request(gpio_nr, "tshut"); |
| 1138 | if (status < 0) { |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1139 | 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] | 1140 | return status; |
| 1141 | } |
| 1142 | status = gpio_direction_input(gpio_nr); |
| 1143 | if (status) { |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1144 | 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] | 1145 | return status; |
| 1146 | } |
| 1147 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1148 | status = request_irq(gpio_to_irq(gpio_nr), ti_bandgap_tshut_irq_handler, |
| 1149 | IRQF_TRIGGER_RISING, "tshut", NULL); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1150 | if (status) { |
| 1151 | gpio_free(gpio_nr); |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1152 | dev_err(bgp->dev, "request irq failed for TSHUT"); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1153 | } |
| 1154 | |
| 1155 | return 0; |
| 1156 | } |
| 1157 | |
Eduardo Valentin | 094b8ac | 2013-03-15 09:00:31 -0400 | [diff] [blame] | 1158 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1159 | * ti_bandgap_alert_init() - setup and initialize talert handling |
| 1160 | * @bgp: pointer to struct ti_bandgap |
Eduardo Valentin | 094b8ac | 2013-03-15 09:00:31 -0400 | [diff] [blame] | 1161 | * @pdev: pointer to device struct platform_device |
| 1162 | * |
| 1163 | * Call this function only in case the bandgap features HAS(TALERT). |
| 1164 | * In this case, the driver needs to handle the TALERT signals as an IRQs. |
| 1165 | * TALERT is a normal IRQ and it is fired any time thresholds (hot or cold) |
| 1166 | * are violated. In these situation, the driver must reprogram the thresholds, |
| 1167 | * accordingly to specified policy. |
Nishanth Menon | 169e8d0 | 2013-04-01 12:04:34 -0400 | [diff] [blame] | 1168 | * |
| 1169 | * Return: 0 if no error, else return corresponding error. |
Eduardo Valentin | 094b8ac | 2013-03-15 09:00:31 -0400 | [diff] [blame] | 1170 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1171 | static int ti_bandgap_talert_init(struct ti_bandgap *bgp, |
| 1172 | struct platform_device *pdev) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1173 | { |
| 1174 | int ret; |
| 1175 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1176 | bgp->irq = platform_get_irq(pdev, 0); |
| 1177 | if (bgp->irq < 0) { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1178 | dev_err(&pdev->dev, "get_irq failed\n"); |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1179 | return bgp->irq; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1180 | } |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1181 | ret = request_threaded_irq(bgp->irq, NULL, |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1182 | ti_bandgap_talert_irq_handler, |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1183 | IRQF_TRIGGER_HIGH | IRQF_ONESHOT, |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1184 | "talert", bgp); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1185 | if (ret) { |
| 1186 | dev_err(&pdev->dev, "Request threaded irq failed.\n"); |
| 1187 | return ret; |
| 1188 | } |
| 1189 | |
| 1190 | return 0; |
| 1191 | } |
| 1192 | |
Eduardo Valentin | 61603af | 2013-03-19 10:54:25 -0400 | [diff] [blame] | 1193 | static const struct of_device_id of_ti_bandgap_match[]; |
Eduardo Valentin | e9b6f8c | 2013-03-15 09:00:32 -0400 | [diff] [blame] | 1194 | /** |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1195 | * ti_bandgap_build() - parse DT and setup a struct ti_bandgap |
Eduardo Valentin | e9b6f8c | 2013-03-15 09:00:32 -0400 | [diff] [blame] | 1196 | * @pdev: pointer to device struct platform_device |
| 1197 | * |
| 1198 | * Used to read the device tree properties accordingly to the bandgap |
| 1199 | * matching version. Based on bandgap version and its capabilities it |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1200 | * will build a struct ti_bandgap out of the required DT entries. |
Nishanth Menon | 169e8d0 | 2013-04-01 12:04:34 -0400 | [diff] [blame] | 1201 | * |
| 1202 | * Return: valid bandgap structure if successful, else returns ERR_PTR |
| 1203 | * return value must be verified with IS_ERR. |
Eduardo Valentin | e9b6f8c | 2013-03-15 09:00:32 -0400 | [diff] [blame] | 1204 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1205 | static struct ti_bandgap *ti_bandgap_build(struct platform_device *pdev) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1206 | { |
| 1207 | struct device_node *node = pdev->dev.of_node; |
| 1208 | const struct of_device_id *of_id; |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1209 | struct ti_bandgap *bgp; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1210 | struct resource *res; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1211 | int i; |
| 1212 | |
| 1213 | /* just for the sake */ |
| 1214 | if (!node) { |
| 1215 | dev_err(&pdev->dev, "no platform information available\n"); |
| 1216 | return ERR_PTR(-EINVAL); |
| 1217 | } |
| 1218 | |
Eduardo Valentin | f684356 | 2013-03-19 10:54:24 -0400 | [diff] [blame] | 1219 | bgp = devm_kzalloc(&pdev->dev, sizeof(*bgp), GFP_KERNEL); |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1220 | if (!bgp) { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1221 | dev_err(&pdev->dev, "Unable to allocate mem for driver ref\n"); |
| 1222 | return ERR_PTR(-ENOMEM); |
| 1223 | } |
| 1224 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1225 | of_id = of_match_device(of_ti_bandgap_match, &pdev->dev); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1226 | if (of_id) |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1227 | bgp->conf = of_id->data; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1228 | |
Eduardo Valentin | 9879b2c | 2013-03-19 10:54:23 -0400 | [diff] [blame] | 1229 | /* register shadow for context save and restore */ |
| 1230 | bgp->regval = devm_kzalloc(&pdev->dev, sizeof(*bgp->regval) * |
| 1231 | bgp->conf->sensor_count, GFP_KERNEL); |
Rickard Strandqvist | fbe2ddc | 2014-06-02 23:25:30 +0200 | [diff] [blame] | 1232 | if (!bgp->regval) { |
Eduardo Valentin | 9879b2c | 2013-03-19 10:54:23 -0400 | [diff] [blame] | 1233 | dev_err(&pdev->dev, "Unable to allocate mem for driver ref\n"); |
| 1234 | return ERR_PTR(-ENOMEM); |
| 1235 | } |
| 1236 | |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1237 | i = 0; |
| 1238 | do { |
| 1239 | void __iomem *chunk; |
| 1240 | |
| 1241 | res = platform_get_resource(pdev, IORESOURCE_MEM, i); |
| 1242 | if (!res) |
| 1243 | break; |
Thierry Reding | 97f4be60 | 2013-01-21 11:09:19 +0100 | [diff] [blame] | 1244 | chunk = devm_ioremap_resource(&pdev->dev, res); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1245 | if (i == 0) |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1246 | bgp->base = chunk; |
Thierry Reding | 97f4be60 | 2013-01-21 11:09:19 +0100 | [diff] [blame] | 1247 | if (IS_ERR(chunk)) |
| 1248 | return ERR_CAST(chunk); |
Eduardo Valentin | 24796e1 | 2013-03-15 08:59:53 -0400 | [diff] [blame] | 1249 | |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1250 | i++; |
| 1251 | } while (res); |
| 1252 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1253 | if (TI_BANDGAP_HAS(bgp, TSHUT)) { |
Eduardo Valentin | 57d1617 | 2013-06-07 11:11:53 -0400 | [diff] [blame] | 1254 | bgp->tshut_gpio = of_get_gpio(node, 0); |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1255 | if (!gpio_is_valid(bgp->tshut_gpio)) { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1256 | dev_err(&pdev->dev, "invalid gpio for tshut (%d)\n", |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1257 | bgp->tshut_gpio); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1258 | return ERR_PTR(-EINVAL); |
| 1259 | } |
| 1260 | } |
| 1261 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1262 | return bgp; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1263 | } |
| 1264 | |
Eduardo Valentin | f91ddfe | 2013-03-15 09:00:23 -0400 | [diff] [blame] | 1265 | /*** Device driver call backs ***/ |
| 1266 | |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1267 | static |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1268 | int ti_bandgap_probe(struct platform_device *pdev) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1269 | { |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1270 | struct ti_bandgap *bgp; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1271 | int clk_rate, ret = 0, i; |
| 1272 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1273 | bgp = ti_bandgap_build(pdev); |
Eduardo Valentin | 0c12b5a | 2013-05-29 15:07:43 +0000 | [diff] [blame] | 1274 | if (IS_ERR(bgp)) { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1275 | dev_err(&pdev->dev, "failed to fetch platform data\n"); |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1276 | return PTR_ERR(bgp); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1277 | } |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1278 | bgp->dev = &pdev->dev; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1279 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1280 | if (TI_BANDGAP_HAS(bgp, TSHUT)) { |
| 1281 | ret = ti_bandgap_tshut_init(bgp, pdev); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1282 | if (ret) { |
| 1283 | dev_err(&pdev->dev, |
| 1284 | "failed to initialize system tshut IRQ\n"); |
| 1285 | return ret; |
| 1286 | } |
| 1287 | } |
| 1288 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1289 | bgp->fclock = clk_get(NULL, bgp->conf->fclock_name); |
Eduardo Valentin | 0c12b5a | 2013-05-29 15:07:43 +0000 | [diff] [blame] | 1290 | ret = IS_ERR(bgp->fclock); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1291 | if (ret) { |
| 1292 | dev_err(&pdev->dev, "failed to request fclock reference\n"); |
Eduardo Valentin | 0c12b5a | 2013-05-29 15:07:43 +0000 | [diff] [blame] | 1293 | ret = PTR_ERR(bgp->fclock); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1294 | goto free_irqs; |
| 1295 | } |
| 1296 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1297 | bgp->div_clk = clk_get(NULL, bgp->conf->div_ck_name); |
Eduardo Valentin | 0c12b5a | 2013-05-29 15:07:43 +0000 | [diff] [blame] | 1298 | ret = IS_ERR(bgp->div_clk); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1299 | if (ret) { |
| 1300 | dev_err(&pdev->dev, |
| 1301 | "failed to request div_ts_ck clock ref\n"); |
Eduardo Valentin | 0c12b5a | 2013-05-29 15:07:43 +0000 | [diff] [blame] | 1302 | ret = PTR_ERR(bgp->div_clk); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1303 | goto free_irqs; |
| 1304 | } |
| 1305 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1306 | for (i = 0; i < bgp->conf->sensor_count; i++) { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1307 | struct temp_sensor_registers *tsr; |
| 1308 | u32 val; |
| 1309 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1310 | tsr = bgp->conf->sensors[i].registers; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1311 | /* |
| 1312 | * check if the efuse has a non-zero value if not |
| 1313 | * it is an untrimmed sample and the temperatures |
| 1314 | * may not be accurate |
| 1315 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1316 | val = ti_bandgap_readl(bgp, tsr->bgap_efuse); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1317 | if (ret || !val) |
| 1318 | dev_info(&pdev->dev, |
| 1319 | "Non-trimmed BGAP, Temp not accurate\n"); |
| 1320 | } |
| 1321 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1322 | clk_rate = clk_round_rate(bgp->div_clk, |
| 1323 | bgp->conf->sensors[0].ts_data->max_freq); |
| 1324 | if (clk_rate < bgp->conf->sensors[0].ts_data->min_freq || |
Paul Walmsley | c68789e | 2013-12-09 18:09:22 -0800 | [diff] [blame] | 1325 | clk_rate <= 0) { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1326 | ret = -ENODEV; |
| 1327 | dev_err(&pdev->dev, "wrong clock rate (%d)\n", clk_rate); |
| 1328 | goto put_clks; |
| 1329 | } |
| 1330 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1331 | ret = clk_set_rate(bgp->div_clk, clk_rate); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1332 | if (ret) |
| 1333 | dev_err(&pdev->dev, "Cannot re-set clock rate. Continuing\n"); |
| 1334 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1335 | bgp->clk_rate = clk_rate; |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1336 | if (TI_BANDGAP_HAS(bgp, CLK_CTRL)) |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1337 | clk_prepare_enable(bgp->fclock); |
Radhesh Fadnis | 6c9c1d6 | 2013-02-26 18:53:25 -0400 | [diff] [blame] | 1338 | |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1339 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1340 | spin_lock_init(&bgp->lock); |
| 1341 | bgp->dev = &pdev->dev; |
| 1342 | platform_set_drvdata(pdev, bgp); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1343 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1344 | ti_bandgap_power(bgp, true); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1345 | |
| 1346 | /* Set default counter to 1 for now */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1347 | if (TI_BANDGAP_HAS(bgp, COUNTER)) |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1348 | for (i = 0; i < bgp->conf->sensor_count; i++) |
| 1349 | RMW_BITS(bgp, i, bgap_counter, counter_mask, 1); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1350 | |
Eduardo Valentin | d3c291a | 2013-03-15 08:59:55 -0400 | [diff] [blame] | 1351 | /* Set default thresholds for alert and shutdown */ |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1352 | for (i = 0; i < bgp->conf->sensor_count; i++) { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1353 | struct temp_sensor_data *ts_data; |
| 1354 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1355 | ts_data = bgp->conf->sensors[i].ts_data; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1356 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1357 | if (TI_BANDGAP_HAS(bgp, TALERT)) { |
Eduardo Valentin | d3c291a | 2013-03-15 08:59:55 -0400 | [diff] [blame] | 1358 | /* Set initial Talert thresholds */ |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1359 | RMW_BITS(bgp, i, bgap_threshold, |
Eduardo Valentin | d3c291a | 2013-03-15 08:59:55 -0400 | [diff] [blame] | 1360 | threshold_tcold_mask, ts_data->t_cold); |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1361 | RMW_BITS(bgp, i, bgap_threshold, |
Eduardo Valentin | d3c291a | 2013-03-15 08:59:55 -0400 | [diff] [blame] | 1362 | threshold_thot_mask, ts_data->t_hot); |
| 1363 | /* Enable the alert events */ |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1364 | RMW_BITS(bgp, i, bgap_mask_ctrl, mask_hot_mask, 1); |
| 1365 | RMW_BITS(bgp, i, bgap_mask_ctrl, mask_cold_mask, 1); |
Eduardo Valentin | d3c291a | 2013-03-15 08:59:55 -0400 | [diff] [blame] | 1366 | } |
| 1367 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1368 | if (TI_BANDGAP_HAS(bgp, TSHUT_CONFIG)) { |
Eduardo Valentin | d3c291a | 2013-03-15 08:59:55 -0400 | [diff] [blame] | 1369 | /* Set initial Tshut thresholds */ |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1370 | RMW_BITS(bgp, i, tshut_threshold, |
Eduardo Valentin | d3c291a | 2013-03-15 08:59:55 -0400 | [diff] [blame] | 1371 | tshut_hot_mask, ts_data->tshut_hot); |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1372 | RMW_BITS(bgp, i, tshut_threshold, |
Eduardo Valentin | d3c291a | 2013-03-15 08:59:55 -0400 | [diff] [blame] | 1373 | tshut_cold_mask, ts_data->tshut_cold); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1374 | } |
| 1375 | } |
| 1376 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1377 | if (TI_BANDGAP_HAS(bgp, MODE_CONFIG)) |
| 1378 | ti_bandgap_set_continuous_mode(bgp); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1379 | |
| 1380 | /* Set .250 seconds time as default counter */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1381 | if (TI_BANDGAP_HAS(bgp, COUNTER)) |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1382 | for (i = 0; i < bgp->conf->sensor_count; i++) |
| 1383 | RMW_BITS(bgp, i, bgap_counter, counter_mask, |
| 1384 | bgp->clk_rate / 4); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1385 | |
| 1386 | /* Every thing is good? Then expose the sensors */ |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1387 | for (i = 0; i < bgp->conf->sensor_count; i++) { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1388 | char *domain; |
| 1389 | |
Eduardo Valentin | f155333 | 2013-04-08 08:19:13 -0400 | [diff] [blame] | 1390 | if (bgp->conf->sensors[i].register_cooling) { |
| 1391 | ret = bgp->conf->sensors[i].register_cooling(bgp, i); |
| 1392 | if (ret) |
| 1393 | goto remove_sensors; |
| 1394 | } |
Eduardo Valentin | 04a4d10 | 2012-09-11 19:06:55 +0300 | [diff] [blame] | 1395 | |
Eduardo Valentin | f155333 | 2013-04-08 08:19:13 -0400 | [diff] [blame] | 1396 | if (bgp->conf->expose_sensor) { |
| 1397 | domain = bgp->conf->sensors[i].domain; |
| 1398 | ret = bgp->conf->expose_sensor(bgp, i, domain); |
| 1399 | if (ret) |
| 1400 | goto remove_last_cooling; |
| 1401 | } |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | /* |
| 1405 | * Enable the Interrupts once everything is set. Otherwise irq handler |
| 1406 | * might be called as soon as it is enabled where as rest of framework |
| 1407 | * is still getting initialised. |
| 1408 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1409 | if (TI_BANDGAP_HAS(bgp, TALERT)) { |
| 1410 | ret = ti_bandgap_talert_init(bgp, pdev); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1411 | if (ret) { |
| 1412 | dev_err(&pdev->dev, "failed to initialize Talert IRQ\n"); |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1413 | i = bgp->conf->sensor_count; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1414 | goto disable_clk; |
| 1415 | } |
| 1416 | } |
| 1417 | |
| 1418 | return 0; |
| 1419 | |
Eduardo Valentin | f155333 | 2013-04-08 08:19:13 -0400 | [diff] [blame] | 1420 | remove_last_cooling: |
| 1421 | if (bgp->conf->sensors[i].unregister_cooling) |
| 1422 | bgp->conf->sensors[i].unregister_cooling(bgp, i); |
| 1423 | remove_sensors: |
| 1424 | for (i--; i >= 0; i--) { |
| 1425 | if (bgp->conf->sensors[i].unregister_cooling) |
| 1426 | bgp->conf->sensors[i].unregister_cooling(bgp, i); |
| 1427 | if (bgp->conf->remove_sensor) |
| 1428 | bgp->conf->remove_sensor(bgp, i); |
| 1429 | } |
| 1430 | ti_bandgap_power(bgp, false); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1431 | disable_clk: |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1432 | if (TI_BANDGAP_HAS(bgp, CLK_CTRL)) |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1433 | clk_disable_unprepare(bgp->fclock); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1434 | put_clks: |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1435 | clk_put(bgp->fclock); |
| 1436 | clk_put(bgp->div_clk); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1437 | free_irqs: |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1438 | if (TI_BANDGAP_HAS(bgp, TSHUT)) { |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1439 | free_irq(gpio_to_irq(bgp->tshut_gpio), NULL); |
| 1440 | gpio_free(bgp->tshut_gpio); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | return ret; |
| 1444 | } |
| 1445 | |
| 1446 | static |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1447 | int ti_bandgap_remove(struct platform_device *pdev) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1448 | { |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1449 | struct ti_bandgap *bgp = platform_get_drvdata(pdev); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1450 | int i; |
| 1451 | |
| 1452 | /* First thing is to remove sensor interfaces */ |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1453 | for (i = 0; i < bgp->conf->sensor_count; i++) { |
Eduardo Valentin | 262235b | 2013-04-08 08:19:14 -0400 | [diff] [blame] | 1454 | if (bgp->conf->sensors[i].unregister_cooling) |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1455 | bgp->conf->sensors[i].unregister_cooling(bgp, i); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1456 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1457 | if (bgp->conf->remove_sensor) |
| 1458 | bgp->conf->remove_sensor(bgp, i); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1459 | } |
| 1460 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1461 | ti_bandgap_power(bgp, false); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1462 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1463 | if (TI_BANDGAP_HAS(bgp, CLK_CTRL)) |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1464 | clk_disable_unprepare(bgp->fclock); |
| 1465 | clk_put(bgp->fclock); |
| 1466 | clk_put(bgp->div_clk); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1467 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1468 | if (TI_BANDGAP_HAS(bgp, TALERT)) |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1469 | free_irq(bgp->irq, bgp); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1470 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1471 | if (TI_BANDGAP_HAS(bgp, TSHUT)) { |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1472 | free_irq(gpio_to_irq(bgp->tshut_gpio), NULL); |
| 1473 | gpio_free(bgp->tshut_gpio); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | return 0; |
| 1477 | } |
| 1478 | |
Grygorii Strashko | 3992b62 | 2015-02-06 16:55:46 +0200 | [diff] [blame] | 1479 | #ifdef CONFIG_PM_SLEEP |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1480 | static int ti_bandgap_save_ctxt(struct ti_bandgap *bgp) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1481 | { |
| 1482 | int i; |
| 1483 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1484 | for (i = 0; i < bgp->conf->sensor_count; i++) { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1485 | struct temp_sensor_registers *tsr; |
| 1486 | struct temp_sensor_regval *rval; |
| 1487 | |
Eduardo Valentin | 9879b2c | 2013-03-19 10:54:23 -0400 | [diff] [blame] | 1488 | rval = &bgp->regval[i]; |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1489 | tsr = bgp->conf->sensors[i].registers; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1490 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1491 | if (TI_BANDGAP_HAS(bgp, MODE_CONFIG)) |
| 1492 | rval->bg_mode_ctrl = ti_bandgap_readl(bgp, |
J Keerthy | 76d2cd3 | 2012-09-11 19:06:52 +0300 | [diff] [blame] | 1493 | tsr->bgap_mode_ctrl); |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1494 | if (TI_BANDGAP_HAS(bgp, COUNTER)) |
| 1495 | rval->bg_counter = ti_bandgap_readl(bgp, |
J Keerthy | 76d2cd3 | 2012-09-11 19:06:52 +0300 | [diff] [blame] | 1496 | tsr->bgap_counter); |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1497 | if (TI_BANDGAP_HAS(bgp, TALERT)) { |
| 1498 | rval->bg_threshold = ti_bandgap_readl(bgp, |
J Keerthy | 76d2cd3 | 2012-09-11 19:06:52 +0300 | [diff] [blame] | 1499 | tsr->bgap_threshold); |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1500 | rval->bg_ctrl = ti_bandgap_readl(bgp, |
J Keerthy | 76d2cd3 | 2012-09-11 19:06:52 +0300 | [diff] [blame] | 1501 | tsr->bgap_mask_ctrl); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1502 | } |
| 1503 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1504 | if (TI_BANDGAP_HAS(bgp, TSHUT_CONFIG)) |
| 1505 | rval->tshut_threshold = ti_bandgap_readl(bgp, |
J Keerthy | 76d2cd3 | 2012-09-11 19:06:52 +0300 | [diff] [blame] | 1506 | tsr->tshut_threshold); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | return 0; |
| 1510 | } |
| 1511 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1512 | static int ti_bandgap_restore_ctxt(struct ti_bandgap *bgp) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1513 | { |
| 1514 | int i; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1515 | |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1516 | for (i = 0; i < bgp->conf->sensor_count; i++) { |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1517 | struct temp_sensor_registers *tsr; |
| 1518 | struct temp_sensor_regval *rval; |
| 1519 | u32 val = 0; |
| 1520 | |
Eduardo Valentin | 9879b2c | 2013-03-19 10:54:23 -0400 | [diff] [blame] | 1521 | rval = &bgp->regval[i]; |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1522 | tsr = bgp->conf->sensors[i].registers; |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1523 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1524 | if (TI_BANDGAP_HAS(bgp, COUNTER)) |
| 1525 | val = ti_bandgap_readl(bgp, tsr->bgap_counter); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1526 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1527 | if (TI_BANDGAP_HAS(bgp, TSHUT_CONFIG)) |
| 1528 | ti_bandgap_writel(bgp, rval->tshut_threshold, |
| 1529 | tsr->tshut_threshold); |
Radhesh Fadnis | b87ea75 | 2012-11-13 14:10:04 -0400 | [diff] [blame] | 1530 | /* Force immediate temperature measurement and update |
| 1531 | * of the DTEMP field |
| 1532 | */ |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1533 | ti_bandgap_force_single_read(bgp, i); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1534 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1535 | if (TI_BANDGAP_HAS(bgp, COUNTER)) |
| 1536 | ti_bandgap_writel(bgp, rval->bg_counter, |
| 1537 | tsr->bgap_counter); |
| 1538 | if (TI_BANDGAP_HAS(bgp, MODE_CONFIG)) |
| 1539 | ti_bandgap_writel(bgp, rval->bg_mode_ctrl, |
| 1540 | tsr->bgap_mode_ctrl); |
| 1541 | if (TI_BANDGAP_HAS(bgp, TALERT)) { |
| 1542 | ti_bandgap_writel(bgp, rval->bg_threshold, |
| 1543 | tsr->bgap_threshold); |
| 1544 | ti_bandgap_writel(bgp, rval->bg_ctrl, |
| 1545 | tsr->bgap_mask_ctrl); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1546 | } |
| 1547 | } |
| 1548 | |
| 1549 | return 0; |
| 1550 | } |
| 1551 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1552 | static int ti_bandgap_suspend(struct device *dev) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1553 | { |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1554 | struct ti_bandgap *bgp = dev_get_drvdata(dev); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1555 | int err; |
| 1556 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1557 | err = ti_bandgap_save_ctxt(bgp); |
| 1558 | ti_bandgap_power(bgp, false); |
Radhesh Fadnis | 6c9c1d6 | 2013-02-26 18:53:25 -0400 | [diff] [blame] | 1559 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1560 | if (TI_BANDGAP_HAS(bgp, CLK_CTRL)) |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1561 | clk_disable_unprepare(bgp->fclock); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1562 | |
| 1563 | return err; |
| 1564 | } |
| 1565 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1566 | static int ti_bandgap_resume(struct device *dev) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1567 | { |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1568 | struct ti_bandgap *bgp = dev_get_drvdata(dev); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1569 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1570 | if (TI_BANDGAP_HAS(bgp, CLK_CTRL)) |
Eduardo Valentin | d7f080e | 2013-03-19 10:54:18 -0400 | [diff] [blame] | 1571 | clk_prepare_enable(bgp->fclock); |
Radhesh Fadnis | 6c9c1d6 | 2013-02-26 18:53:25 -0400 | [diff] [blame] | 1572 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1573 | ti_bandgap_power(bgp, true); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1574 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1575 | return ti_bandgap_restore_ctxt(bgp); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1576 | } |
Jingoo Han | 5204f8c | 2014-02-27 20:43:02 +0900 | [diff] [blame] | 1577 | static SIMPLE_DEV_PM_OPS(ti_bandgap_dev_pm_ops, ti_bandgap_suspend, |
| 1578 | ti_bandgap_resume); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1579 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1580 | #define DEV_PM_OPS (&ti_bandgap_dev_pm_ops) |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1581 | #else |
| 1582 | #define DEV_PM_OPS NULL |
| 1583 | #endif |
| 1584 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1585 | static const struct of_device_id of_ti_bandgap_match[] = { |
Eduardo Valentin | 1a31270 | 2012-07-12 19:02:31 +0300 | [diff] [blame] | 1586 | #ifdef CONFIG_OMAP4_THERMAL |
| 1587 | { |
| 1588 | .compatible = "ti,omap4430-bandgap", |
| 1589 | .data = (void *)&omap4430_data, |
| 1590 | }, |
| 1591 | { |
| 1592 | .compatible = "ti,omap4460-bandgap", |
| 1593 | .data = (void *)&omap4460_data, |
| 1594 | }, |
| 1595 | { |
| 1596 | .compatible = "ti,omap4470-bandgap", |
| 1597 | .data = (void *)&omap4470_data, |
| 1598 | }, |
| 1599 | #endif |
Eduardo Valentin | 949f5a5 | 2012-07-12 19:02:32 +0300 | [diff] [blame] | 1600 | #ifdef CONFIG_OMAP5_THERMAL |
| 1601 | { |
| 1602 | .compatible = "ti,omap5430-bandgap", |
| 1603 | .data = (void *)&omap5430_data, |
| 1604 | }, |
| 1605 | #endif |
Eduardo Valentin | 25870e6 | 2013-05-29 15:07:45 +0000 | [diff] [blame] | 1606 | #ifdef CONFIG_DRA752_THERMAL |
| 1607 | { |
| 1608 | .compatible = "ti,dra752-bandgap", |
| 1609 | .data = (void *)&dra752_data, |
| 1610 | }, |
| 1611 | #endif |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1612 | /* Sentinel */ |
| 1613 | { }, |
| 1614 | }; |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1615 | MODULE_DEVICE_TABLE(of, of_ti_bandgap_match); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1616 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1617 | static struct platform_driver ti_bandgap_sensor_driver = { |
| 1618 | .probe = ti_bandgap_probe, |
| 1619 | .remove = ti_bandgap_remove, |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1620 | .driver = { |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1621 | .name = "ti-soc-thermal", |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1622 | .pm = DEV_PM_OPS, |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1623 | .of_match_table = of_ti_bandgap_match, |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1624 | }, |
| 1625 | }; |
| 1626 | |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1627 | module_platform_driver(ti_bandgap_sensor_driver); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1628 | |
| 1629 | MODULE_DESCRIPTION("OMAP4+ bandgap temperature sensor driver"); |
| 1630 | MODULE_LICENSE("GPL v2"); |
Eduardo Valentin | 03e859d | 2013-03-19 10:54:21 -0400 | [diff] [blame] | 1631 | MODULE_ALIAS("platform:ti-soc-thermal"); |
Eduardo Valentin | 8feaf0ce | 2012-07-12 19:02:29 +0300 | [diff] [blame] | 1632 | MODULE_AUTHOR("Texas Instrument Inc."); |