/** * iio_trigger_read_name() - retrieve useful identifying name **/ static ssize_t iio_trigger_read_name(struct device *dev, struct device_attribute *attr, char *buf) { struct iio_trigger *trig = to_iio_trigger(dev); return sprintf(buf, "%s\n", trig->name); }
static ssize_t iio_sysfs_trigger_poll(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct iio_trigger *trig = to_iio_trigger(dev); struct iio_sysfs_trig *sysfs_trig = iio_trigger_get_drvdata(trig); irq_work_queue(&sysfs_trig->work); return count; }
static ssize_t stm32_tt_show_master_mode(struct device *dev, struct device_attribute *attr, char *buf) { struct stm32_timer_trigger *priv = dev_get_drvdata(dev); struct iio_trigger *trig = to_iio_trigger(dev); u32 cr2; regmap_read(priv->regmap, TIM_CR2, &cr2); if (stm32_timer_is_trgo2_name(trig->name)) cr2 = (cr2 & TIM_CR2_MMS2) >> TIM_CR2_MMS2_SHIFT; else
static ssize_t iio_bfin_tmr_frequency_show(struct device *dev, struct device_attribute *attr, char *buf) { struct iio_trigger *trig = to_iio_trigger(dev); struct bfin_tmr_state *st = trig->private_data; unsigned int period = get_gptimer_period(st->t->id); unsigned long val; if (period == 0) val = 0; else val = get_sclk() / get_gptimer_period(st->t->id); return sprintf(buf, "%lu\n", val); }
static ssize_t stm32_tt_read_frequency(struct device *dev, struct device_attribute *attr, char *buf) { struct iio_trigger *trig = to_iio_trigger(dev); struct stm32_timer_trigger *priv = iio_trigger_get_drvdata(trig); u32 psc, arr, cr1; unsigned long long freq = 0; regmap_read(priv->regmap, TIM_CR1, &cr1); regmap_read(priv->regmap, TIM_PSC, &psc); regmap_read(priv->regmap, TIM_ARR, &arr); if (cr1 & TIM_CR1_CEN) { freq = (unsigned long long)clk_get_rate(priv->clk); do_div(freq, psc + 1); do_div(freq, arr + 1); } return sprintf(buf, "%d\n", (unsigned int)freq); }
static ssize_t iio_bfin_tmr_frequency_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct iio_trigger *trig = to_iio_trigger(dev); struct bfin_tmr_state *st = trig->private_data; unsigned long val; bool enabled; int ret; ret = strict_strtoul(buf, 10, &val); if (ret) goto error_ret; if (val > 100000) { ret = -EINVAL; goto error_ret; } enabled = get_enabled_gptimers() & st->t->bit; if (enabled) disable_gptimers(st->t->bit); if (!val) goto error_ret; val = get_sclk() / val; if (val <= 4 || val <= st->duty) { ret = -EINVAL; goto error_ret; } set_gptimer_period(st->t->id, val); set_gptimer_pwidth(st->t->id, val - st->duty); if (enabled) enable_gptimers(st->t->bit); error_ret: return ret ? ret : count; }
static ssize_t stm32_tt_store_frequency(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { struct iio_trigger *trig = to_iio_trigger(dev); struct stm32_timer_trigger *priv = iio_trigger_get_drvdata(trig); unsigned int freq; int ret; ret = kstrtouint(buf, 10, &freq); if (ret) return ret; if (freq == 0) { stm32_timer_stop(priv); } else { ret = stm32_timer_start(priv, trig, freq); if (ret) return ret; } return len; }
static ssize_t iio_bfin_tmr_frequency_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct iio_trigger *trig = to_iio_trigger(dev); struct bfin_tmr_state *st = iio_trigger_get_drvdata(trig); unsigned int val; bool enabled; int ret; ret = kstrtouint(buf, 10, &val); if (ret) return ret; if (val > 100000) return -EINVAL; enabled = get_enabled_gptimers() & st->t->bit; if (enabled) disable_gptimers(st->t->bit); if (val == 0) return count; val = get_sclk() / val; if (val <= 4 || val <= st->duty) return -EINVAL; set_gptimer_period(st->t->id, val); set_gptimer_pwidth(st->t->id, val - st->duty); if (enabled) enable_gptimers(st->t->bit); return count; }