blob: 71823d1403c5201539b36d682135258ddf655455 [file] [log] [blame]
Carlo Caionead855ea2016-08-27 15:43:46 +02001/*
Martin Blumenstingl9593ad32017-10-09 15:26:40 +02002 * Amlogic Meson GX eFuse Driver
Carlo Caionead855ea2016-08-27 15:43:46 +02003 *
4 * Copyright (c) 2016 Endless Computers, Inc.
5 * Author: Carlo Caione <carlo@endlessm.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 */
16
17#include <linux/module.h>
18#include <linux/nvmem-provider.h>
19#include <linux/of.h>
20#include <linux/platform_device.h>
21
22#include <linux/firmware/meson/meson_sm.h>
23
24static int meson_efuse_read(void *context, unsigned int offset,
25 void *val, size_t bytes)
26{
27 u8 *buf = val;
28 int ret;
29
Carlo Caione83e007a2017-03-03 16:17:58 +010030 ret = meson_sm_call_read(buf, bytes, SM_EFUSE_READ, offset,
Carlo Caionead855ea2016-08-27 15:43:46 +020031 bytes, 0, 0, 0);
32 if (ret < 0)
33 return ret;
34
35 return 0;
36}
37
38static struct nvmem_config econfig = {
39 .name = "meson-efuse",
Carlo Caionead855ea2016-08-27 15:43:46 +020040 .stride = 1,
41 .word_size = 1,
42 .read_only = true,
43};
44
45static const struct of_device_id meson_efuse_match[] = {
46 { .compatible = "amlogic,meson-gxbb-efuse", },
47 { /* sentinel */ },
48};
49MODULE_DEVICE_TABLE(of, meson_efuse_match);
50
51static int meson_efuse_probe(struct platform_device *pdev)
52{
53 struct nvmem_device *nvmem;
54 unsigned int size;
55
56 if (meson_sm_call(SM_EFUSE_USER_MAX, &size, 0, 0, 0, 0, 0) < 0)
57 return -EINVAL;
58
59 econfig.dev = &pdev->dev;
60 econfig.reg_read = meson_efuse_read;
61 econfig.size = size;
62
Andrey Smirnov90696a42018-03-09 14:47:05 +000063 nvmem = devm_nvmem_register(&pdev->dev, &econfig);
Carlo Caionead855ea2016-08-27 15:43:46 +020064
Andrey Smirnov90696a42018-03-09 14:47:05 +000065 return PTR_ERR_OR_ZERO(nvmem);
Carlo Caionead855ea2016-08-27 15:43:46 +020066}
67
68static struct platform_driver meson_efuse_driver = {
69 .probe = meson_efuse_probe,
Carlo Caionead855ea2016-08-27 15:43:46 +020070 .driver = {
71 .name = "meson-efuse",
72 .of_match_table = meson_efuse_match,
73 },
74};
75
76module_platform_driver(meson_efuse_driver);
77
78MODULE_AUTHOR("Carlo Caione <carlo@endlessm.com>");
Martin Blumenstingl9593ad32017-10-09 15:26:40 +020079MODULE_DESCRIPTION("Amlogic Meson GX NVMEM driver");
Carlo Caionead855ea2016-08-27 15:43:46 +020080MODULE_LICENSE("GPL v2");