Skip to content

Commit d49e6ee

Browse files
William Breathitt GrayJonathan Cameron
authored andcommitted
counter: Simplify the count_read and count_write callbacks
The count_read and count_write callbacks are simplified to pass val as unsigned long rather than as an opaque data structure. The opaque counter_count_read_value and counter_count_write_value structures, counter_count_value_type enum, and relevant counter_count_read_value_set and counter_count_write_value_get functions, are removed as they are no longer used. Cc: Patrick Havelange <patrick.havelange@essensium.com> Acked-by: Fabrice Gasnier <fabrice.gasnier@st.com> Acked-by: David Lechner <david@lechnology.com> Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 16922ff commit d49e6ee

7 files changed

Lines changed: 51 additions & 212 deletions

File tree

‎drivers/counter/104-quad-8.c‎

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -562,11 +562,10 @@ static const struct iio_chan_spec quad8_channels[] = {
562562
};
563563

564564
static int quad8_signal_read(struct counter_device *counter,
565-
struct counter_signal *signal, struct counter_signal_read_value *val)
565+
struct counter_signal *signal, enum counter_signal_value *val)
566566
{
567567
const struct quad8_iio *const priv = counter->priv;
568568
unsigned int state;
569-
enum counter_signal_level level;
570569

571570
/* Only Index signal levels can be read */
572571
if (signal->id < 16)
@@ -575,67 +574,55 @@ static int quad8_signal_read(struct counter_device *counter,
575574
state = inb(priv->base + QUAD8_REG_INDEX_INPUT_LEVELS)
576575
& BIT(signal->id - 16);
577576

578-
level = (state) ? COUNTER_SIGNAL_LEVEL_HIGH : COUNTER_SIGNAL_LEVEL_LOW;
579-
580-
counter_signal_read_value_set(val, COUNTER_SIGNAL_LEVEL, &level);
577+
*val = (state) ? COUNTER_SIGNAL_HIGH : COUNTER_SIGNAL_LOW;
581578

582579
return 0;
583580
}
584581

585582
static int quad8_count_read(struct counter_device *counter,
586-
struct counter_count *count, struct counter_count_read_value *val)
583+
struct counter_count *count, unsigned long *val)
587584
{
588585
const struct quad8_iio *const priv = counter->priv;
589586
const int base_offset = priv->base + 2 * count->id;
590587
unsigned int flags;
591588
unsigned int borrow;
592589
unsigned int carry;
593-
unsigned long position;
594590
int i;
595591

596592
flags = inb(base_offset + 1);
597593
borrow = flags & QUAD8_FLAG_BT;
598594
carry = !!(flags & QUAD8_FLAG_CT);
599595

600596
/* Borrow XOR Carry effectively doubles count range */
601-
position = (unsigned long)(borrow ^ carry) << 24;
597+
*val = (unsigned long)(borrow ^ carry) << 24;
602598

603599
/* Reset Byte Pointer; transfer Counter to Output Latch */
604600
outb(QUAD8_CTR_RLD | QUAD8_RLD_RESET_BP | QUAD8_RLD_CNTR_OUT,
605601
base_offset + 1);
606602

607603
for (i = 0; i < 3; i++)
608-
position |= (unsigned long)inb(base_offset) << (8 * i);
609-
610-
counter_count_read_value_set(val, COUNTER_COUNT_POSITION, &position);
604+
*val |= (unsigned long)inb(base_offset) << (8 * i);
611605

612606
return 0;
613607
}
614608

615609
static int quad8_count_write(struct counter_device *counter,
616-
struct counter_count *count, struct counter_count_write_value *val)
610+
struct counter_count *count, unsigned long val)
617611
{
618612
const struct quad8_iio *const priv = counter->priv;
619613
const int base_offset = priv->base + 2 * count->id;
620-
int err;
621-
unsigned long position;
622614
int i;
623615

624-
err = counter_count_write_value_get(&position, COUNTER_COUNT_POSITION,
625-
val);
626-
if (err)
627-
return err;
628-
629616
/* Only 24-bit values are supported */
630-
if (position > 0xFFFFFF)
617+
if (val > 0xFFFFFF)
631618
return -EINVAL;
632619

633620
/* Reset Byte Pointer */
634621
outb(QUAD8_CTR_RLD | QUAD8_RLD_RESET_BP, base_offset + 1);
635622

636623
/* Counter can only be set via Preset Register */
637624
for (i = 0; i < 3; i++)
638-
outb(position >> (8 * i), base_offset);
625+
outb(val >> (8 * i), base_offset);
639626

640627
/* Transfer Preset Register to Counter */
641628
outb(QUAD8_CTR_RLD | QUAD8_RLD_PRESET_CNTR, base_offset + 1);
@@ -644,9 +631,9 @@ static int quad8_count_write(struct counter_device *counter,
644631
outb(QUAD8_CTR_RLD | QUAD8_RLD_RESET_BP, base_offset + 1);
645632

646633
/* Set Preset Register back to original value */
647-
position = priv->preset[count->id];
634+
val = priv->preset[count->id];
648635
for (i = 0; i < 3; i++)
649-
outb(position >> (8 * i), base_offset);
636+
outb(val >> (8 * i), base_offset);
650637

651638
/* Reset Borrow, Carry, Compare, and Sign flags */
652639
outb(QUAD8_CTR_RLD | QUAD8_RLD_RESET_FLAGS, base_offset + 1);

‎drivers/counter/counter.c‎

Lines changed: 15 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -220,86 +220,6 @@ ssize_t counter_device_enum_available_read(struct counter_device *counter,
220220
}
221221
EXPORT_SYMBOL_GPL(counter_device_enum_available_read);
222222

223-
static const char *const counter_signal_level_str[] = {
224-
[COUNTER_SIGNAL_LEVEL_LOW] = "low",
225-
[COUNTER_SIGNAL_LEVEL_HIGH] = "high"
226-
};
227-
228-
/**
229-
* counter_signal_read_value_set - set counter_signal_read_value data
230-
* @val: counter_signal_read_value structure to set
231-
* @type: property Signal data represents
232-
* @data: Signal data
233-
*
234-
* This function sets an opaque counter_signal_read_value structure with the
235-
* provided Signal data.
236-
*/
237-
void counter_signal_read_value_set(struct counter_signal_read_value *const val,
238-
const enum counter_signal_value_type type,
239-
void *const data)
240-
{
241-
if (type == COUNTER_SIGNAL_LEVEL)
242-
val->len = sprintf(val->buf, "%s\n",
243-
counter_signal_level_str[*(enum counter_signal_level *)data]);
244-
else
245-
val->len = 0;
246-
}
247-
EXPORT_SYMBOL_GPL(counter_signal_read_value_set);
248-
249-
/**
250-
* counter_count_read_value_set - set counter_count_read_value data
251-
* @val: counter_count_read_value structure to set
252-
* @type: property Count data represents
253-
* @data: Count data
254-
*
255-
* This function sets an opaque counter_count_read_value structure with the
256-
* provided Count data.
257-
*/
258-
void counter_count_read_value_set(struct counter_count_read_value *const val,
259-
const enum counter_count_value_type type,
260-
void *const data)
261-
{
262-
switch (type) {
263-
case COUNTER_COUNT_POSITION:
264-
val->len = sprintf(val->buf, "%lu\n", *(unsigned long *)data);
265-
break;
266-
default:
267-
val->len = 0;
268-
}
269-
}
270-
EXPORT_SYMBOL_GPL(counter_count_read_value_set);
271-
272-
/**
273-
* counter_count_write_value_get - get counter_count_write_value data
274-
* @data: Count data
275-
* @type: property Count data represents
276-
* @val: counter_count_write_value structure containing data
277-
*
278-
* This function extracts Count data from the provided opaque
279-
* counter_count_write_value structure and stores it at the address provided by
280-
* @data.
281-
*
282-
* RETURNS:
283-
* 0 on success, negative error number on failure.
284-
*/
285-
int counter_count_write_value_get(void *const data,
286-
const enum counter_count_value_type type,
287-
const struct counter_count_write_value *const val)
288-
{
289-
int err;
290-
291-
switch (type) {
292-
case COUNTER_COUNT_POSITION:
293-
err = kstrtoul(val->buf, 0, data);
294-
if (err)
295-
return err;
296-
break;
297-
}
298-
299-
return 0;
300-
}
301-
EXPORT_SYMBOL_GPL(counter_count_write_value_get);
302-
303223
struct counter_attr_parm {
304224
struct counter_device_attr_group *group;
305225
const char *prefix;
@@ -369,6 +289,11 @@ struct counter_signal_unit {
369289
struct counter_signal *signal;
370290
};
371291

292+
static const char *const counter_signal_value_str[] = {
293+
[COUNTER_SIGNAL_LOW] = "low",
294+
[COUNTER_SIGNAL_HIGH] = "high"
295+
};
296+
372297
static ssize_t counter_signal_show(struct device *dev,
373298
struct device_attribute *attr, char *buf)
374299
{
@@ -377,13 +302,13 @@ static ssize_t counter_signal_show(struct device *dev,
377302
const struct counter_signal_unit *const component = devattr->component;
378303
struct counter_signal *const signal = component->signal;
379304
int err;
380-
struct counter_signal_read_value val = { .buf = buf };
305+
enum counter_signal_value val;
381306

382307
err = counter->ops->signal_read(counter, signal, &val);
383308
if (err)
384309
return err;
385310

386-
return val.len;
311+
return sprintf(buf, "%s\n", counter_signal_value_str[val]);
387312
}
388313

389314
struct counter_name_unit {
@@ -788,13 +713,13 @@ static ssize_t counter_count_show(struct device *dev,
788713
const struct counter_count_unit *const component = devattr->component;
789714
struct counter_count *const count = component->count;
790715
int err;
791-
struct counter_count_read_value val = { .buf = buf };
716+
unsigned long val;
792717

793718
err = counter->ops->count_read(counter, count, &val);
794719
if (err)
795720
return err;
796721

797-
return val.len;
722+
return sprintf(buf, "%lu\n", val);
798723
}
799724

800725
static ssize_t counter_count_store(struct device *dev,
@@ -806,9 +731,13 @@ static ssize_t counter_count_store(struct device *dev,
806731
const struct counter_count_unit *const component = devattr->component;
807732
struct counter_count *const count = component->count;
808733
int err;
809-
struct counter_count_write_value val = { .buf = buf };
734+
unsigned long val;
735+
736+
err = kstrtoul(buf, 0, &val);
737+
if (err)
738+
return err;
810739

811-
err = counter->ops->count_write(counter, count, &val);
740+
err = counter->ops->count_write(counter, count, val);
812741
if (err)
813742
return err;
814743

‎drivers/counter/ftm-quaddec.c‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,31 +178,25 @@ static const enum counter_count_function ftm_quaddec_count_functions[] = {
178178

179179
static int ftm_quaddec_count_read(struct counter_device *counter,
180180
struct counter_count *count,
181-
struct counter_count_read_value *val)
181+
unsigned long *val)
182182
{
183183
struct ftm_quaddec *const ftm = counter->priv;
184184
uint32_t cntval;
185185

186186
ftm_read(ftm, FTM_CNT, &cntval);
187187

188-
counter_count_read_value_set(val, COUNTER_COUNT_POSITION, &cntval);
188+
*val = cntval;
189189

190190
return 0;
191191
}
192192

193193
static int ftm_quaddec_count_write(struct counter_device *counter,
194194
struct counter_count *count,
195-
struct counter_count_write_value *val)
195+
const unsigned long val)
196196
{
197197
struct ftm_quaddec *const ftm = counter->priv;
198-
u32 cnt;
199-
int err;
200198

201-
err = counter_count_write_value_get(&cnt, COUNTER_COUNT_POSITION, val);
202-
if (err)
203-
return err;
204-
205-
if (cnt != 0) {
199+
if (val != 0) {
206200
dev_warn(&ftm->pdev->dev, "Can only accept '0' as new counter value\n");
207201
return -EINVAL;
208202
}

‎drivers/counter/stm32-lptimer-cnt.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,7 @@ static enum counter_synapse_action stm32_lptim_cnt_synapse_actions[] = {
377377
};
378378

379379
static int stm32_lptim_cnt_read(struct counter_device *counter,
380-
struct counter_count *count,
381-
struct counter_count_read_value *val)
380+
struct counter_count *count, unsigned long *val)
382381
{
383382
struct stm32_lptim_cnt *const priv = counter->priv;
384383
u32 cnt;
@@ -388,7 +387,7 @@ static int stm32_lptim_cnt_read(struct counter_device *counter,
388387
if (ret)
389388
return ret;
390389

391-
counter_count_read_value_set(val, COUNTER_COUNT_POSITION, &cnt);
390+
*val = cnt;
392391

393392
return 0;
394393
}

‎drivers/counter/stm32-timer-cnt.c‎

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,34 +48,27 @@ static enum counter_count_function stm32_count_functions[] = {
4848
};
4949

5050
static int stm32_count_read(struct counter_device *counter,
51-
struct counter_count *count,
52-
struct counter_count_read_value *val)
51+
struct counter_count *count, unsigned long *val)
5352
{
5453
struct stm32_timer_cnt *const priv = counter->priv;
5554
u32 cnt;
5655

5756
regmap_read(priv->regmap, TIM_CNT, &cnt);
58-
counter_count_read_value_set(val, COUNTER_COUNT_POSITION, &cnt);
57+
*val = cnt;
5958

6059
return 0;
6160
}
6261

6362
static int stm32_count_write(struct counter_device *counter,
6463
struct counter_count *count,
65-
struct counter_count_write_value *val)
64+
const unsigned long val)
6665
{
6766
struct stm32_timer_cnt *const priv = counter->priv;
68-
u32 cnt;
69-
int err;
70-
71-
err = counter_count_write_value_get(&cnt, COUNTER_COUNT_POSITION, val);
72-
if (err)
73-
return err;
7467

75-
if (cnt > priv->ceiling)
68+
if (val > priv->ceiling)
7669
return -EINVAL;
7770

78-
return regmap_write(priv->regmap, TIM_CNT, cnt);
71+
return regmap_write(priv->regmap, TIM_CNT, val);
7972
}
8073

8174
static int stm32_count_function_get(struct counter_device *counter,

‎drivers/counter/ti-eqep.c‎

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,35 +93,28 @@ struct ti_eqep_cnt {
9393
};
9494

9595
static int ti_eqep_count_read(struct counter_device *counter,
96-
struct counter_count *count,
97-
struct counter_count_read_value *val)
96+
struct counter_count *count, unsigned long *val)
9897
{
9998
struct ti_eqep_cnt *priv = counter->priv;
10099
u32 cnt;
101100

102101
regmap_read(priv->regmap32, QPOSCNT, &cnt);
103-
counter_count_read_value_set(val, COUNTER_COUNT_POSITION, &cnt);
102+
*val = cnt;
104103

105104
return 0;
106105
}
107106

108107
static int ti_eqep_count_write(struct counter_device *counter,
109-
struct counter_count *count,
110-
struct counter_count_write_value *val)
108+
struct counter_count *count, unsigned long val)
111109
{
112110
struct ti_eqep_cnt *priv = counter->priv;
113-
u32 cnt, max;
114-
int err;
115-
116-
err = counter_count_write_value_get(&cnt, COUNTER_COUNT_POSITION, val);
117-
if (err)
118-
return err;
111+
u32 max;
119112

120113
regmap_read(priv->regmap32, QPOSMAX, &max);
121-
if (cnt > max)
114+
if (val > max)
122115
return -EINVAL;
123116

124-
return regmap_write(priv->regmap32, QPOSCNT, cnt);
117+
return regmap_write(priv->regmap32, QPOSCNT, val);
125118
}
126119

127120
static int ti_eqep_function_get(struct counter_device *counter,

0 commit comments

Comments
 (0)