Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Amlogic Meson GX eFuse Driver
  4 *
  5 * Copyright (c) 2016 Endless Computers, Inc.
  6 * Author: Carlo Caione <carlo@endlessm.com>
 
 
 
 
 
 
 
 
 
  7 */
  8
  9#include <linux/clk.h>
 10#include <linux/module.h>
 11#include <linux/nvmem-provider.h>
 12#include <linux/of.h>
 13#include <linux/platform_device.h>
 14
 15#include <linux/firmware/meson/meson_sm.h>
 16
 17static int meson_efuse_read(void *context, unsigned int offset,
 18			    void *val, size_t bytes)
 19{
 20	struct meson_sm_firmware *fw = context;
 21	int ret;
 22
 23	ret = meson_sm_call_read(fw, (u8 *)val, bytes, SM_EFUSE_READ, offset,
 24				 bytes, 0, 0, 0);
 
 
 25
 26	return ret < 0 ? ret : 0;
 27}
 28
 29static int meson_efuse_write(void *context, unsigned int offset,
 30			     void *val, size_t bytes)
 31{
 32	struct meson_sm_firmware *fw = context;
 33	int ret;
 34
 35	ret = meson_sm_call_write(fw, (u8 *)val, bytes, SM_EFUSE_WRITE, offset,
 36				  bytes, 0, 0, 0);
 37
 38	return ret < 0 ? ret : 0;
 39}
 40
 41static const struct of_device_id meson_efuse_match[] = {
 42	{ .compatible = "amlogic,meson-gxbb-efuse", },
 43	{ /* sentinel */ },
 44};
 45MODULE_DEVICE_TABLE(of, meson_efuse_match);
 46
 47static int meson_efuse_probe(struct platform_device *pdev)
 48{
 49	struct device *dev = &pdev->dev;
 50	struct meson_sm_firmware *fw;
 51	struct nvmem_device *nvmem;
 52	struct nvmem_config *econfig;
 53	struct clk *clk;
 54	unsigned int size;
 55	struct device_node *sm_np __free(device_node) =
 56			of_parse_phandle(pdev->dev.of_node, "secure-monitor", 0);
 57
 58	if (!sm_np) {
 59		dev_err(&pdev->dev, "no secure-monitor node\n");
 60		return -ENODEV;
 61	}
 62
 63	fw = meson_sm_get(sm_np);
 64	if (!fw)
 65		return -EPROBE_DEFER;
 66
 67	clk = devm_clk_get_enabled(dev, NULL);
 68	if (IS_ERR(clk))
 69		return dev_err_probe(dev, PTR_ERR(clk), "failed to get efuse gate");
 70
 71	if (meson_sm_call(fw, SM_EFUSE_USER_MAX, &size, 0, 0, 0, 0, 0) < 0) {
 72		dev_err(dev, "failed to get max user");
 73		return -EINVAL;
 74	}
 75
 76	econfig = devm_kzalloc(dev, sizeof(*econfig), GFP_KERNEL);
 77	if (!econfig)
 78		return -ENOMEM;
 79
 80	econfig->dev = dev;
 81	econfig->name = dev_name(dev);
 82	econfig->add_legacy_fixed_of_cells = true;
 83	econfig->stride = 1;
 84	econfig->word_size = 1;
 85	econfig->reg_read = meson_efuse_read;
 86	econfig->reg_write = meson_efuse_write;
 87	econfig->size = size;
 88	econfig->priv = fw;
 89
 90	nvmem = devm_nvmem_register(&pdev->dev, econfig);
 91
 92	return PTR_ERR_OR_ZERO(nvmem);
 93}
 94
 95static struct platform_driver meson_efuse_driver = {
 96	.probe = meson_efuse_probe,
 97	.driver = {
 98		.name = "meson-efuse",
 99		.of_match_table = meson_efuse_match,
100	},
101};
102
103module_platform_driver(meson_efuse_driver);
104
105MODULE_AUTHOR("Carlo Caione <carlo@endlessm.com>");
106MODULE_DESCRIPTION("Amlogic Meson GX NVMEM driver");
107MODULE_LICENSE("GPL v2");
v4.17
 
 1/*
 2 * Amlogic Meson GX eFuse Driver
 3 *
 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
30	ret = meson_sm_call_read(buf, bytes, SM_EFUSE_READ, offset,
31				 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",
40	.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
63	nvmem = devm_nvmem_register(&pdev->dev, &econfig);
64
65	return PTR_ERR_OR_ZERO(nvmem);
66}
67
68static struct platform_driver meson_efuse_driver = {
69	.probe = meson_efuse_probe,
70	.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>");
79MODULE_DESCRIPTION("Amlogic Meson GX NVMEM driver");
80MODULE_LICENSE("GPL v2");