2019-02-06 14:07:21 +03:00
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright ( C ) 2019 Xilinx , Inc .
2024-02-24 14:45:11 +03:00
* Copyright ( C ) 2022 - 2023 , Advanced Micro Devices , Inc .
2019-02-06 14:07:21 +03:00
*/
# include <linux/module.h>
# include <linux/nvmem-provider.h>
# include <linux/of.h>
# include <linux/platform_device.h>
# include <linux/firmware/xlnx-zynqmp.h>
# define SILICON_REVISION_MASK 0xF
static int zynqmp_nvmem_read ( void * context , unsigned int offset ,
void * val , size_t bytes )
{
2024-02-24 14:45:11 +03:00
struct device * dev = context ;
2019-02-06 14:07:21 +03:00
int ret ;
2024-02-24 14:45:11 +03:00
int idcode ;
int version ;
2019-02-06 14:07:21 +03:00
2020-04-24 23:57:44 +03:00
ret = zynqmp_pm_get_chipid ( & idcode , & version ) ;
2019-02-06 14:07:21 +03:00
if ( ret < 0 )
return ret ;
2024-02-24 14:45:11 +03:00
dev_dbg ( dev , " Read chipid val %x %x \n " , idcode , version ) ;
2019-02-06 14:07:21 +03:00
* ( int * ) val = version & SILICON_REVISION_MASK ;
return 0 ;
}
static const struct of_device_id zynqmp_nvmem_match [ ] = {
{ . compatible = " xlnx,zynqmp-nvmem-fw " , } ,
{ /* sentinel */ } ,
} ;
MODULE_DEVICE_TABLE ( of , zynqmp_nvmem_match ) ;
static int zynqmp_nvmem_probe ( struct platform_device * pdev )
{
struct device * dev = & pdev - > dev ;
2024-02-24 14:45:11 +03:00
struct nvmem_config econfig = { } ;
2019-02-06 14:07:21 +03:00
2024-02-24 14:45:11 +03:00
econfig . name = " zynqmp-nvmem " ;
econfig . owner = THIS_MODULE ;
econfig . word_size = 1 ;
econfig . size = 1 ;
2019-02-06 14:07:21 +03:00
econfig . dev = dev ;
2023-10-20 13:55:41 +03:00
econfig . add_legacy_fixed_of_cells = true ;
2024-02-24 14:45:11 +03:00
econfig . read_only = true ;
2019-02-06 14:07:21 +03:00
econfig . reg_read = zynqmp_nvmem_read ;
2024-02-24 14:45:11 +03:00
return PTR_ERR_OR_ZERO ( devm_nvmem_register ( dev , & econfig ) ) ;
2019-02-06 14:07:21 +03:00
}
static struct platform_driver zynqmp_nvmem_driver = {
. probe = zynqmp_nvmem_probe ,
. driver = {
. name = " zynqmp-nvmem " ,
. of_match_table = zynqmp_nvmem_match ,
} ,
} ;
module_platform_driver ( zynqmp_nvmem_driver ) ;
2023-06-11 17:03:23 +03:00
MODULE_AUTHOR ( " Michal Simek <michal.simek@amd.com>, Nava kishore Manne <nava.kishore.manne@amd.com> " ) ;
2019-02-06 14:07:21 +03:00
MODULE_DESCRIPTION ( " ZynqMP NVMEM driver " ) ;
MODULE_LICENSE ( " GPL " ) ;