2016-08-27 16:43:46 +03:00
/*
2017-10-09 16:26:40 +03:00
* Amlogic Meson GX eFuse Driver
2016-08-27 16:43:46 +03:00
*
* Copyright ( c ) 2016 Endless Computers , Inc .
* Author : Carlo Caione < carlo @ endlessm . com >
*
* This program is free software ; you can redistribute it and / or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation .
*
* This program is distributed in the hope that it will be useful , but WITHOUT
* ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE . See the GNU General Public License for
* more details .
*/
# include <linux/module.h>
# include <linux/nvmem-provider.h>
# include <linux/of.h>
# include <linux/platform_device.h>
# include <linux/firmware/meson/meson_sm.h>
static int meson_efuse_read ( void * context , unsigned int offset ,
void * val , size_t bytes )
{
u8 * buf = val ;
int ret ;
2017-03-03 18:17:58 +03:00
ret = meson_sm_call_read ( buf , bytes , SM_EFUSE_READ , offset ,
2016-08-27 16:43:46 +03:00
bytes , 0 , 0 , 0 ) ;
if ( ret < 0 )
return ret ;
return 0 ;
}
static const struct of_device_id meson_efuse_match [ ] = {
{ . compatible = " amlogic,meson-gxbb-efuse " , } ,
{ /* sentinel */ } ,
} ;
MODULE_DEVICE_TABLE ( of , meson_efuse_match ) ;
static int meson_efuse_probe ( struct platform_device * pdev )
{
2018-05-11 14:06:59 +03:00
struct device * dev = & pdev - > dev ;
2016-08-27 16:43:46 +03:00
struct nvmem_device * nvmem ;
2018-05-11 14:06:59 +03:00
struct nvmem_config * econfig ;
2016-08-27 16:43:46 +03:00
unsigned int size ;
if ( meson_sm_call ( SM_EFUSE_USER_MAX , & size , 0 , 0 , 0 , 0 , 0 ) < 0 )
return - EINVAL ;
2018-05-11 14:06:59 +03:00
econfig = devm_kzalloc ( dev , sizeof ( * econfig ) , GFP_KERNEL ) ;
if ( ! econfig )
return - ENOMEM ;
econfig - > dev = dev ;
econfig - > name = dev_name ( dev ) ;
econfig - > stride = 1 ;
econfig - > word_size = 1 ;
econfig - > read_only = true ;
econfig - > reg_read = meson_efuse_read ;
econfig - > size = size ;
2016-08-27 16:43:46 +03:00
2018-05-11 14:06:59 +03:00
nvmem = devm_nvmem_register ( & pdev - > dev , econfig ) ;
2016-08-27 16:43:46 +03:00
2018-03-09 17:47:05 +03:00
return PTR_ERR_OR_ZERO ( nvmem ) ;
2016-08-27 16:43:46 +03:00
}
static struct platform_driver meson_efuse_driver = {
. probe = meson_efuse_probe ,
. driver = {
. name = " meson-efuse " ,
. of_match_table = meson_efuse_match ,
} ,
} ;
module_platform_driver ( meson_efuse_driver ) ;
MODULE_AUTHOR ( " Carlo Caione <carlo@endlessm.com> " ) ;
2017-10-09 16:26:40 +03:00
MODULE_DESCRIPTION ( " Amlogic Meson GX NVMEM driver " ) ;
2016-08-27 16:43:46 +03:00
MODULE_LICENSE ( " GPL v2 " ) ;