Skip to content

Commit 1adc624

Browse files
Bence CsókásWilliam Breathitt Gray
authored andcommitted
counter: microchip-tcb-capture: Add capture extensions for registers RA/RB
TCB hardware is capable of capturing the timer value to registers RA and RB. Add these registers as capture extensions. Signed-off-by: Bence Csókás <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: William Breathitt Gray <[email protected]>
1 parent e5d5813 commit 1adc624

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

drivers/counter/microchip-tcb-capture.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,62 @@ static int mchp_tc_count_read(struct counter_device *counter,
253253
return 0;
254254
}
255255

256+
static int mchp_tc_count_cap_read(struct counter_device *counter,
257+
struct counter_count *count, size_t idx, u64 *val)
258+
{
259+
struct mchp_tc_data *const priv = counter_priv(counter);
260+
u32 cnt;
261+
int ret;
262+
263+
switch (idx) {
264+
case COUNTER_MCHP_EXCAP_RA:
265+
ret = regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], RA), &cnt);
266+
break;
267+
case COUNTER_MCHP_EXCAP_RB:
268+
ret = regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], RB), &cnt);
269+
break;
270+
default:
271+
return -EINVAL;
272+
}
273+
274+
if (ret < 0)
275+
return ret;
276+
277+
*val = cnt;
278+
279+
return 0;
280+
}
281+
282+
static int mchp_tc_count_cap_write(struct counter_device *counter,
283+
struct counter_count *count, size_t idx, u64 val)
284+
{
285+
struct mchp_tc_data *const priv = counter_priv(counter);
286+
int ret;
287+
288+
if (val > U32_MAX)
289+
return -ERANGE;
290+
291+
switch (idx) {
292+
case COUNTER_MCHP_EXCAP_RA:
293+
ret = regmap_write(priv->regmap, ATMEL_TC_REG(priv->channel[0], RA), val);
294+
break;
295+
case COUNTER_MCHP_EXCAP_RB:
296+
ret = regmap_write(priv->regmap, ATMEL_TC_REG(priv->channel[0], RB), val);
297+
break;
298+
default:
299+
return -EINVAL;
300+
}
301+
302+
return ret;
303+
}
304+
305+
static DEFINE_COUNTER_ARRAY_CAPTURE(mchp_tc_cnt_cap_array, 2);
306+
307+
static struct counter_comp mchp_tc_count_ext[] = {
308+
COUNTER_COMP_ARRAY_CAPTURE(mchp_tc_count_cap_read, mchp_tc_count_cap_write,
309+
mchp_tc_cnt_cap_array),
310+
};
311+
256312
static struct counter_count mchp_tc_counts[] = {
257313
{
258314
.id = 0,
@@ -261,6 +317,8 @@ static struct counter_count mchp_tc_counts[] = {
261317
.num_functions = ARRAY_SIZE(mchp_tc_count_functions),
262318
.synapses = mchp_tc_count_synapses,
263319
.num_synapses = ARRAY_SIZE(mchp_tc_count_synapses),
320+
.ext = mchp_tc_count_ext,
321+
.num_ext = ARRAY_SIZE(mchp_tc_count_ext),
264322
},
265323
};
266324

include/uapi/linux/counter/microchip-tcb-capture.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* Count 0
1313
* \__ Synapse 0 -- Signal 0 (Channel A, i.e. TIOA)
1414
* \__ Synapse 1 -- Signal 1 (Channel B, i.e. TIOB)
15+
* \__ Extension capture0 (RA register)
16+
* \__ Extension capture1 (RB register)
1517
*
1618
* It also supports the following events:
1719
*
@@ -25,6 +27,10 @@
2527
* - RC compare triggered
2628
*/
2729

30+
/* Capture extensions */
31+
#define COUNTER_MCHP_EXCAP_RA 0
32+
#define COUNTER_MCHP_EXCAP_RB 1
33+
2834
/* Event channels */
2935
#define COUNTER_MCHP_EVCHN_CV 0
3036
#define COUNTER_MCHP_EVCHN_RA 0

0 commit comments

Comments
 (0)