162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * PRU-ICSS Subsystem user interfaces
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (C) 2015-2023 Texas Instruments Incorporated - http://www.ti.com
662306a36Sopenharmony_ci *	MD Danish Anwar <danishanwar@ti.com>
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#ifndef _SOC_TI_PRUSS_H_
1062306a36Sopenharmony_ci#define _SOC_TI_PRUSS_H_
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#include <linux/bits.h>
1362306a36Sopenharmony_ci#include <linux/regmap.h>
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci/*
1662306a36Sopenharmony_ci * PRU_ICSS_CFG registers
1762306a36Sopenharmony_ci * SYSCFG, ISRP, ISP, IESP, IECP, SCRP applicable on AMxxxx devices only
1862306a36Sopenharmony_ci */
1962306a36Sopenharmony_ci#define PRUSS_CFG_REVID         0x00
2062306a36Sopenharmony_ci#define PRUSS_CFG_SYSCFG        0x04
2162306a36Sopenharmony_ci#define PRUSS_CFG_GPCFG(x)      (0x08 + (x) * 4)
2262306a36Sopenharmony_ci#define PRUSS_CFG_CGR           0x10
2362306a36Sopenharmony_ci#define PRUSS_CFG_ISRP          0x14
2462306a36Sopenharmony_ci#define PRUSS_CFG_ISP           0x18
2562306a36Sopenharmony_ci#define PRUSS_CFG_IESP          0x1C
2662306a36Sopenharmony_ci#define PRUSS_CFG_IECP          0x20
2762306a36Sopenharmony_ci#define PRUSS_CFG_SCRP          0x24
2862306a36Sopenharmony_ci#define PRUSS_CFG_PMAO          0x28
2962306a36Sopenharmony_ci#define PRUSS_CFG_MII_RT        0x2C
3062306a36Sopenharmony_ci#define PRUSS_CFG_IEPCLK        0x30
3162306a36Sopenharmony_ci#define PRUSS_CFG_SPP           0x34
3262306a36Sopenharmony_ci#define PRUSS_CFG_PIN_MX        0x40
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci/* PRUSS_GPCFG register bits */
3562306a36Sopenharmony_ci#define PRUSS_GPCFG_PRU_GPI_MODE_MASK           GENMASK(1, 0)
3662306a36Sopenharmony_ci#define PRUSS_GPCFG_PRU_GPI_MODE_SHIFT          0
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci#define PRUSS_GPCFG_PRU_MUX_SEL_SHIFT           26
3962306a36Sopenharmony_ci#define PRUSS_GPCFG_PRU_MUX_SEL_MASK            GENMASK(29, 26)
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci/* PRUSS_MII_RT register bits */
4262306a36Sopenharmony_ci#define PRUSS_MII_RT_EVENT_EN                   BIT(0)
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci/* PRUSS_SPP register bits */
4562306a36Sopenharmony_ci#define PRUSS_SPP_XFER_SHIFT_EN                 BIT(1)
4662306a36Sopenharmony_ci#define PRUSS_SPP_PRU1_PAD_HP_EN                BIT(0)
4762306a36Sopenharmony_ci#define PRUSS_SPP_RTU_XFR_SHIFT_EN              BIT(3)
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci/**
5062306a36Sopenharmony_ci * pruss_cfg_read() - read a PRUSS CFG sub-module register
5162306a36Sopenharmony_ci * @pruss: the pruss instance handle
5262306a36Sopenharmony_ci * @reg: register offset within the CFG sub-module
5362306a36Sopenharmony_ci * @val: pointer to return the value in
5462306a36Sopenharmony_ci *
5562306a36Sopenharmony_ci * Reads a given register within the PRUSS CFG sub-module and
5662306a36Sopenharmony_ci * returns it through the passed-in @val pointer
5762306a36Sopenharmony_ci *
5862306a36Sopenharmony_ci * Return: 0 on success, or an error code otherwise
5962306a36Sopenharmony_ci */
6062306a36Sopenharmony_cistatic int pruss_cfg_read(struct pruss *pruss, unsigned int reg, unsigned int *val)
6162306a36Sopenharmony_ci{
6262306a36Sopenharmony_ci	if (IS_ERR_OR_NULL(pruss))
6362306a36Sopenharmony_ci		return -EINVAL;
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci	return regmap_read(pruss->cfg_regmap, reg, val);
6662306a36Sopenharmony_ci}
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci/**
6962306a36Sopenharmony_ci * pruss_cfg_update() - configure a PRUSS CFG sub-module register
7062306a36Sopenharmony_ci * @pruss: the pruss instance handle
7162306a36Sopenharmony_ci * @reg: register offset within the CFG sub-module
7262306a36Sopenharmony_ci * @mask: bit mask to use for programming the @val
7362306a36Sopenharmony_ci * @val: value to write
7462306a36Sopenharmony_ci *
7562306a36Sopenharmony_ci * Programs a given register within the PRUSS CFG sub-module
7662306a36Sopenharmony_ci *
7762306a36Sopenharmony_ci * Return: 0 on success, or an error code otherwise
7862306a36Sopenharmony_ci */
7962306a36Sopenharmony_cistatic int pruss_cfg_update(struct pruss *pruss, unsigned int reg,
8062306a36Sopenharmony_ci			    unsigned int mask, unsigned int val)
8162306a36Sopenharmony_ci{
8262306a36Sopenharmony_ci	if (IS_ERR_OR_NULL(pruss))
8362306a36Sopenharmony_ci		return -EINVAL;
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci	return regmap_update_bits(pruss->cfg_regmap, reg, mask, val);
8662306a36Sopenharmony_ci}
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci#endif  /* _SOC_TI_PRUSS_H_ */
89