[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2c5bd165-d95e-4b66-a3ef-ad40f9b8e0ad@enneenne.com>
Date: Wed, 26 Feb 2025 08:50:43 +0100
From: Rodolfo Giometti <giometti@...eenne.com>
To: Raag Jadav <raag.jadav@...el.com>, lee@...nel.org,
gregkh@...uxfoundation.org, andriy.shevchenko@...ux.intel.com,
raymond.tan@...el.com
Cc: linux-kernel@...r.kernel.org
Subject: Re: [PATCH v1 2/4] pps: generators: tio: move to match_data() model
On 26/02/25 07:15, Raag Jadav wrote:
> Use device_get_match_data() which allows configuring platform
> specific data like number of pins and MMIO registers for TIO.
>
> Signed-off-by: Raag Jadav <raag.jadav@...el.com>
Acked-by: Rodolfo Giometti <giometti@...eenne.com>
> ---
> drivers/pps/generators/pps_gen_tio.c | 33 ++++++++++++++++++++--------
> drivers/pps/generators/pps_gen_tio.h | 19 +++++++++++++---
> 2 files changed, 40 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/pps/generators/pps_gen_tio.c b/drivers/pps/generators/pps_gen_tio.c
> index 7f2aab1219af..89b08301d21e 100644
> --- a/drivers/pps/generators/pps_gen_tio.c
> +++ b/drivers/pps/generators/pps_gen_tio.c
> @@ -14,6 +14,7 @@
> #include <linux/module.h>
> #include <linux/platform_device.h>
> #include <linux/pps_gen_kernel.h>
> +#include <linux/property.h>
> #include <linux/timekeeping.h>
> #include <linux/types.h>
>
> @@ -21,6 +22,14 @@
>
> #include "pps_gen_tio.h"
>
> +static const struct pps_tio_data pmc_data = {
> + .regs = {
> + .ctl = TIOCTL_PMC,
> + .compv = TIOCOMPV_PMC,
> + .ec = TIOEC_PMC,
> + },
> +};
> +
> static inline u32 pps_tio_read(u32 offset, struct pps_tio *tio)
> {
> return readl(tio->base + offset);
> @@ -28,7 +37,7 @@ static inline u32 pps_tio_read(u32 offset, struct pps_tio *tio)
>
> static inline void pps_ctl_write(u32 value, struct pps_tio *tio)
> {
> - writel(value, tio->base + TIOCTL);
> + writel(value, tio->base + tio->regs.ctl);
> }
>
> /*
> @@ -37,7 +46,7 @@ static inline void pps_ctl_write(u32 value, struct pps_tio *tio)
> */
> static inline void pps_compv_write(u64 value, struct pps_tio *tio)
> {
> - hi_lo_writeq(value, tio->base + TIOCOMPV);
> + hi_lo_writeq(value, tio->base + tio->regs.compv);
> }
>
> static inline ktime_t first_event(struct pps_tio *tio)
> @@ -49,7 +58,7 @@ static u32 pps_tio_disable(struct pps_tio *tio)
> {
> u32 ctrl;
>
> - ctrl = pps_tio_read(TIOCTL, tio);
> + ctrl = pps_tio_read(tio->regs.ctl, tio);
> pps_compv_write(0, tio);
>
> ctrl &= ~TIOCTL_EN;
> @@ -63,7 +72,7 @@ static void pps_tio_enable(struct pps_tio *tio)
> {
> u32 ctrl;
>
> - ctrl = pps_tio_read(TIOCTL, tio);
> + ctrl = pps_tio_read(tio->regs.ctl, tio);
> ctrl |= TIOCTL_EN;
> pps_ctl_write(ctrl, tio);
> tio->pps_gen->enabled = true;
> @@ -112,7 +121,7 @@ static enum hrtimer_restart hrtimer_callback(struct hrtimer *timer)
> * Check if any event is missed.
> * If an event is missed, TIO will be disabled.
> */
> - event_count = pps_tio_read(TIOEC, tio);
> + event_count = pps_tio_read(tio->regs.ec, tio);
> if (tio->prev_count && tio->prev_count == event_count)
> goto err;
> tio->prev_count = event_count;
> @@ -172,6 +181,7 @@ static int pps_tio_get_time(struct pps_gen_device *pps_gen,
> static int pps_gen_tio_probe(struct platform_device *pdev)
> {
> struct device *dev = &pdev->dev;
> + const struct pps_tio_data *data;
> struct pps_tio *tio;
>
> if (!(cpu_feature_enabled(X86_FEATURE_TSC_KNOWN_FREQ) &&
> @@ -184,6 +194,11 @@ static int pps_gen_tio_probe(struct platform_device *pdev)
> if (!tio)
> return -ENOMEM;
>
> + data = device_get_match_data(dev);
> + if (!data)
> + return -ENODEV;
> +
> + tio->regs = data->regs;
> tio->gen_info.use_system_clock = true;
> tio->gen_info.enable = pps_tio_gen_enable;
> tio->gen_info.get_time = pps_tio_get_time;
> @@ -217,10 +232,10 @@ static void pps_gen_tio_remove(struct platform_device *pdev)
> }
>
> static const struct acpi_device_id intel_pmc_tio_acpi_match[] = {
> - { "INTC1021" },
> - { "INTC1022" },
> - { "INTC1023" },
> - { "INTC1024" },
> + { "INTC1021", (kernel_ulong_t)&pmc_data },
> + { "INTC1022", (kernel_ulong_t)&pmc_data },
> + { "INTC1023", (kernel_ulong_t)&pmc_data },
> + { "INTC1024", (kernel_ulong_t)&pmc_data },
> {}
> };
> MODULE_DEVICE_TABLE(acpi, intel_pmc_tio_acpi_match);
> diff --git a/drivers/pps/generators/pps_gen_tio.h b/drivers/pps/generators/pps_gen_tio.h
> index 78d4d7c25221..e652f976e455 100644
> --- a/drivers/pps/generators/pps_gen_tio.h
> +++ b/drivers/pps/generators/pps_gen_tio.h
> @@ -14,9 +14,10 @@
> #include <linux/pps_gen_kernel.h>
> #include <linux/spinlock_types.h>
>
> -#define TIOCTL 0x00
> -#define TIOCOMPV 0x10
> -#define TIOEC 0x30
> +/* PMC Registers */
> +#define TIOCTL_PMC 0x00
> +#define TIOCOMPV_PMC 0x10
> +#define TIOEC_PMC 0x30
>
> /* Control Register */
> #define TIOCTL_EN BIT(0)
> @@ -32,9 +33,21 @@
> #define MAGIC_CONST (NSEC_PER_SEC - SAFE_TIME_NS)
> #define ART_HW_DELAY_CYCLES 2
>
> +struct pps_tio_regs {
> + u32 ctl;
> + u32 compv;
> + u32 ec;
> +};
> +
> +struct pps_tio_data {
> + struct pps_tio_regs regs;
> + u32 num_pins;
> +};
> +
> struct pps_tio {
> struct pps_gen_source_info gen_info;
> struct pps_gen_device *pps_gen;
> + struct pps_tio_regs regs;
> struct hrtimer timer;
> void __iomem *base;
> u32 prev_count;
--
GNU/Linux Solutions e-mail: giometti@...eenne.com
Linux Device Driver giometti@...ux.it
Embedded Systems phone: +39 349 2432127
UNIX programming
Powered by blists - more mailing lists