Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'ib-iio-input-3.13-1' into for-mfd-next

Immutable branch for IIO and Input

Lee Jones 28b4c294 09fd19da

+120 -37
+49 -19
drivers/iio/adc/ti_am335x_adc.c
··· 60 60 return step_en; 61 61 } 62 62 63 + static u32 get_adc_chan_step_mask(struct tiadc_device *adc_dev, 64 + struct iio_chan_spec const *chan) 65 + { 66 + int i; 67 + 68 + for (i = 0; i < ARRAY_SIZE(adc_dev->channel_step); i++) { 69 + if (chan->channel == adc_dev->channel_line[i]) { 70 + u32 step; 71 + 72 + step = adc_dev->channel_step[i]; 73 + /* +1 for the charger */ 74 + return 1 << (step + 1); 75 + } 76 + } 77 + WARN_ON(1); 78 + return 0; 79 + } 80 + 63 81 static u32 get_adc_step_bit(struct tiadc_device *adc_dev, int chan) 64 82 { 65 83 return 1 << adc_dev->channel_step[chan]; ··· 199 181 enb |= (get_adc_step_bit(adc_dev, bit) << 1); 200 182 adc_dev->buffer_en_ch_steps = enb; 201 183 202 - am335x_tsc_se_set(adc_dev->mfd_tscadc, enb); 184 + am335x_tsc_se_set_cache(adc_dev->mfd_tscadc, enb); 203 185 204 186 tiadc_writel(adc_dev, REG_IRQSTATUS, IRQENB_FIFO1THRES 205 187 | IRQENB_FIFO1OVRRUN | IRQENB_FIFO1UNDRFLW); ··· 217 199 tiadc_writel(adc_dev, REG_IRQCLR, (IRQENB_FIFO1THRES | 218 200 IRQENB_FIFO1OVRRUN | IRQENB_FIFO1UNDRFLW)); 219 201 am335x_tsc_se_clr(adc_dev->mfd_tscadc, adc_dev->buffer_en_ch_steps); 202 + adc_dev->buffer_en_ch_steps = 0; 220 203 221 204 /* Flush FIFO of leftover data in the time it takes to disable adc */ 222 205 fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT); ··· 347 328 unsigned int fifo1count, read, stepid; 348 329 bool found = false; 349 330 u32 step_en; 350 - unsigned long timeout = jiffies + usecs_to_jiffies 351 - (IDLE_TIMEOUT * adc_dev->channels); 331 + unsigned long timeout; 352 332 353 333 if (iio_buffer_enabled(indio_dev)) 354 334 return -EBUSY; 355 335 356 - step_en = get_adc_step_mask(adc_dev); 357 - am335x_tsc_se_set(adc_dev->mfd_tscadc, step_en); 336 + step_en = get_adc_chan_step_mask(adc_dev, chan); 337 + if (!step_en) 338 + return -EINVAL; 358 339 359 - /* Wait for ADC sequencer to complete sampling */ 360 - while (tiadc_readl(adc_dev, REG_ADCFSM) & SEQ_STATUS) { 361 - if (time_after(jiffies, timeout)) 340 + fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT); 341 + while (fifo1count--) 342 + tiadc_readl(adc_dev, REG_FIFO1); 343 + 344 + am335x_tsc_se_set_once(adc_dev->mfd_tscadc, step_en); 345 + 346 + timeout = jiffies + usecs_to_jiffies 347 + (IDLE_TIMEOUT * adc_dev->channels); 348 + /* Wait for Fifo threshold interrupt */ 349 + while (1) { 350 + fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT); 351 + if (fifo1count) 352 + break; 353 + 354 + if (time_after(jiffies, timeout)) { 355 + am335x_tsc_se_adc_done(adc_dev->mfd_tscadc); 362 356 return -EAGAIN; 363 357 } 358 + } 364 359 map_val = chan->channel + TOTAL_CHANNELS; 365 360 366 361 /* 367 - * When the sub-system is first enabled, 368 - * the sequencer will always start with the 369 - * lowest step (1) and continue until step (16). 370 - * For ex: If we have enabled 4 ADC channels and 371 - * currently use only 1 out of them, the 372 - * sequencer still configures all the 4 steps, 373 - * leading to 3 unwanted data. 374 - * Hence we need to flush out this data. 362 + * We check the complete FIFO. We programmed just one entry but in case 363 + * something went wrong we left empty handed (-EAGAIN previously) and 364 + * then the value apeared somehow in the FIFO we would have two entries. 365 + * Therefore we read every item and keep only the latest version of the 366 + * requested channel. 375 367 */ 376 - 377 - fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT); 378 368 for (i = 0; i < fifo1count; i++) { 379 369 read = tiadc_readl(adc_dev, REG_FIFO1); 380 370 stepid = read & FIFOREAD_CHNLID_MASK; ··· 395 367 *val = (u16) read; 396 368 } 397 369 } 370 + am335x_tsc_se_adc_done(adc_dev->mfd_tscadc); 398 371 399 372 if (found == false) 400 373 return -EBUSY; ··· 523 494 tiadc_writel(adc_dev, REG_CTRL, restore); 524 495 525 496 tiadc_step_config(indio_dev); 526 - 497 + am335x_tsc_se_set_cache(adc_dev->mfd_tscadc, 498 + adc_dev->buffer_en_ch_steps); 527 499 return 0; 528 500 } 529 501
+2 -2
drivers/input/touchscreen/ti_am335x_tsc.c
··· 198 198 /* The steps1 … end and bit 0 for TS_Charge */ 199 199 stepenable = (1 << (end_step + 2)) - 1; 200 200 ts_dev->step_mask = stepenable; 201 - am335x_tsc_se_set(ts_dev->mfd_tscadc, ts_dev->step_mask); 201 + am335x_tsc_se_set_cache(ts_dev->mfd_tscadc, ts_dev->step_mask); 202 202 } 203 203 204 204 static void titsc_read_coordinates(struct titsc *ts_dev, ··· 322 322 323 323 if (irqclr) { 324 324 titsc_writel(ts_dev, REG_IRQSTATUS, irqclr); 325 - am335x_tsc_se_set(ts_dev->mfd_tscadc, ts_dev->step_mask); 325 + am335x_tsc_se_set_cache(ts_dev->mfd_tscadc, ts_dev->step_mask); 326 326 return IRQ_HANDLED; 327 327 } 328 328 return IRQ_NONE;
+63 -14
drivers/mfd/ti_am335x_tscadc.c
··· 24 24 #include <linux/pm_runtime.h> 25 25 #include <linux/of.h> 26 26 #include <linux/of_device.h> 27 + #include <linux/sched.h> 27 28 28 29 #include <linux/mfd/ti_am335x_tscadc.h> 29 30 ··· 49 48 .val_bits = 32, 50 49 }; 51 50 52 - void am335x_tsc_se_update(struct ti_tscadc_dev *tsadc) 53 - { 54 - tscadc_writel(tsadc, REG_SE, tsadc->reg_se_cache); 55 - } 56 - EXPORT_SYMBOL_GPL(am335x_tsc_se_update); 57 - 58 - void am335x_tsc_se_set(struct ti_tscadc_dev *tsadc, u32 val) 51 + void am335x_tsc_se_set_cache(struct ti_tscadc_dev *tsadc, u32 val) 59 52 { 60 53 unsigned long flags; 61 54 62 55 spin_lock_irqsave(&tsadc->reg_lock, flags); 63 - tsadc->reg_se_cache = tscadc_readl(tsadc, REG_SE); 64 - tsadc->reg_se_cache |= val; 65 - am335x_tsc_se_update(tsadc); 56 + tsadc->reg_se_cache = val; 57 + if (tsadc->adc_waiting) 58 + wake_up(&tsadc->reg_se_wait); 59 + else if (!tsadc->adc_in_use) 60 + tscadc_writel(tsadc, REG_SE, val); 61 + 66 62 spin_unlock_irqrestore(&tsadc->reg_lock, flags); 67 63 } 68 - EXPORT_SYMBOL_GPL(am335x_tsc_se_set); 64 + EXPORT_SYMBOL_GPL(am335x_tsc_se_set_cache); 65 + 66 + static void am335x_tscadc_need_adc(struct ti_tscadc_dev *tsadc) 67 + { 68 + DEFINE_WAIT(wait); 69 + u32 reg; 70 + 71 + /* 72 + * disable TSC steps so it does not run while the ADC is using it. If 73 + * write 0 while it is running (it just started or was already running) 74 + * then it completes all steps that were enabled and stops then. 75 + */ 76 + tscadc_writel(tsadc, REG_SE, 0); 77 + reg = tscadc_readl(tsadc, REG_ADCFSM); 78 + if (reg & SEQ_STATUS) { 79 + tsadc->adc_waiting = true; 80 + prepare_to_wait(&tsadc->reg_se_wait, &wait, 81 + TASK_UNINTERRUPTIBLE); 82 + spin_unlock_irq(&tsadc->reg_lock); 83 + 84 + schedule(); 85 + 86 + spin_lock_irq(&tsadc->reg_lock); 87 + finish_wait(&tsadc->reg_se_wait, &wait); 88 + 89 + reg = tscadc_readl(tsadc, REG_ADCFSM); 90 + WARN_ON(reg & SEQ_STATUS); 91 + tsadc->adc_waiting = false; 92 + } 93 + tsadc->adc_in_use = true; 94 + } 95 + 96 + void am335x_tsc_se_set_once(struct ti_tscadc_dev *tsadc, u32 val) 97 + { 98 + spin_lock_irq(&tsadc->reg_lock); 99 + am335x_tscadc_need_adc(tsadc); 100 + 101 + tscadc_writel(tsadc, REG_SE, val); 102 + spin_unlock_irq(&tsadc->reg_lock); 103 + } 104 + EXPORT_SYMBOL_GPL(am335x_tsc_se_set_once); 105 + 106 + void am335x_tsc_se_adc_done(struct ti_tscadc_dev *tsadc) 107 + { 108 + unsigned long flags; 109 + 110 + spin_lock_irqsave(&tsadc->reg_lock, flags); 111 + tsadc->adc_in_use = false; 112 + tscadc_writel(tsadc, REG_SE, tsadc->reg_se_cache); 113 + spin_unlock_irqrestore(&tsadc->reg_lock, flags); 114 + } 115 + EXPORT_SYMBOL_GPL(am335x_tsc_se_adc_done); 69 116 70 117 void am335x_tsc_se_clr(struct ti_tscadc_dev *tsadc, u32 val) 71 118 { 72 119 unsigned long flags; 73 120 74 121 spin_lock_irqsave(&tsadc->reg_lock, flags); 75 - tsadc->reg_se_cache = tscadc_readl(tsadc, REG_SE); 76 122 tsadc->reg_se_cache &= ~val; 77 - am335x_tsc_se_update(tsadc); 123 + tscadc_writel(tsadc, REG_SE, tsadc->reg_se_cache); 78 124 spin_unlock_irqrestore(&tsadc->reg_lock, flags); 79 125 } 80 126 EXPORT_SYMBOL_GPL(am335x_tsc_se_clr); ··· 229 181 } 230 182 231 183 spin_lock_init(&tscadc->reg_lock); 184 + init_waitqueue_head(&tscadc->reg_se_wait); 185 + 232 186 pm_runtime_enable(&pdev->dev); 233 187 pm_runtime_get_sync(&pdev->dev); 234 188 ··· 352 302 353 303 if (tscadc_dev->tsc_cell != -1) 354 304 tscadc_idle_config(tscadc_dev); 355 - am335x_tsc_se_update(tscadc_dev); 356 305 restore = tscadc_readl(tscadc_dev, REG_CTRL); 357 306 tscadc_writel(tscadc_dev, REG_CTRL, 358 307 (restore | CNTRLREG_TSCSSENB));
+6 -2
include/linux/mfd/ti_am335x_tscadc.h
··· 159 159 int adc_cell; /* -1 if not used */ 160 160 struct mfd_cell cells[TSCADC_CELLS]; 161 161 u32 reg_se_cache; 162 + bool adc_waiting; 163 + bool adc_in_use; 164 + wait_queue_head_t reg_se_wait; 162 165 spinlock_t reg_lock; 163 166 unsigned int clk_div; 164 167 ··· 179 176 return *tscadc_dev; 180 177 } 181 178 182 - void am335x_tsc_se_update(struct ti_tscadc_dev *tsadc); 183 - void am335x_tsc_se_set(struct ti_tscadc_dev *tsadc, u32 val); 179 + void am335x_tsc_se_set_cache(struct ti_tscadc_dev *tsadc, u32 val); 180 + void am335x_tsc_se_set_once(struct ti_tscadc_dev *tsadc, u32 val); 184 181 void am335x_tsc_se_clr(struct ti_tscadc_dev *tsadc, u32 val); 182 + void am335x_tsc_se_adc_done(struct ti_tscadc_dev *tsadc); 185 183 186 184 #endif