Carlo Caione | ad855ea | 2016-08-27 15:43:46 +0200 | [diff] [blame] | 1 | /* |
Martin Blumenstingl | 9593ad3 | 2017-10-09 15:26:40 +0200 | [diff] [blame] | 2 | * Amlogic Meson GX eFuse Driver |
Carlo Caione | ad855ea | 2016-08-27 15:43:46 +0200 | [diff] [blame] | 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 | |
| 24 | static int meson_efuse_read(void *context, unsigned int offset, |
| 25 | void *val, size_t bytes) |
| 26 | { |
Jerome Brunet | a29a63b | 2018-05-11 12:07:00 +0100 | [diff] [blame] | 27 | return meson_sm_call_read((u8 *)val, bytes, SM_EFUSE_READ, offset, |
| 28 | bytes, 0, 0, 0); |
Carlo Caione | ad855ea | 2016-08-27 15:43:46 +0200 | [diff] [blame] | 29 | } |
| 30 | |
Jerome Brunet | e550773 | 2018-05-11 12:07:01 +0100 | [diff] [blame] | 31 | static int meson_efuse_write(void *context, unsigned int offset, |
| 32 | void *val, size_t bytes) |
| 33 | { |
| 34 | return meson_sm_call_write((u8 *)val, bytes, SM_EFUSE_WRITE, offset, |
| 35 | bytes, 0, 0, 0); |
| 36 | } |
| 37 | |
Carlo Caione | ad855ea | 2016-08-27 15:43:46 +0200 | [diff] [blame] | 38 | static const struct of_device_id meson_efuse_match[] = { |
| 39 | { .compatible = "amlogic,meson-gxbb-efuse", }, |
| 40 | { /* sentinel */ }, |
| 41 | }; |
| 42 | MODULE_DEVICE_TABLE(of, meson_efuse_match); |
| 43 | |
| 44 | static int meson_efuse_probe(struct platform_device *pdev) |
| 45 | { |
Jerome Brunet | 401488d | 2018-05-11 12:06:59 +0100 | [diff] [blame] | 46 | struct device *dev = &pdev->dev; |
Carlo Caione | ad855ea | 2016-08-27 15:43:46 +0200 | [diff] [blame] | 47 | struct nvmem_device *nvmem; |
Jerome Brunet | 401488d | 2018-05-11 12:06:59 +0100 | [diff] [blame] | 48 | struct nvmem_config *econfig; |
Carlo Caione | ad855ea | 2016-08-27 15:43:46 +0200 | [diff] [blame] | 49 | unsigned int size; |
| 50 | |
| 51 | if (meson_sm_call(SM_EFUSE_USER_MAX, &size, 0, 0, 0, 0, 0) < 0) |
| 52 | return -EINVAL; |
| 53 | |
Jerome Brunet | 401488d | 2018-05-11 12:06:59 +0100 | [diff] [blame] | 54 | econfig = devm_kzalloc(dev, sizeof(*econfig), GFP_KERNEL); |
| 55 | if (!econfig) |
| 56 | return -ENOMEM; |
Carlo Caione | ad855ea | 2016-08-27 15:43:46 +0200 | [diff] [blame] | 57 | |
Jerome Brunet | 401488d | 2018-05-11 12:06:59 +0100 | [diff] [blame] | 58 | econfig->dev = dev; |
| 59 | econfig->name = dev_name(dev); |
| 60 | econfig->stride = 1; |
| 61 | econfig->word_size = 1; |
Jerome Brunet | 401488d | 2018-05-11 12:06:59 +0100 | [diff] [blame] | 62 | econfig->reg_read = meson_efuse_read; |
Jerome Brunet | e550773 | 2018-05-11 12:07:01 +0100 | [diff] [blame] | 63 | econfig->reg_write = meson_efuse_write; |
Jerome Brunet | 401488d | 2018-05-11 12:06:59 +0100 | [diff] [blame] | 64 | econfig->size = size; |
| 65 | |
| 66 | nvmem = devm_nvmem_register(&pdev->dev, econfig); |
Carlo Caione | ad855ea | 2016-08-27 15:43:46 +0200 | [diff] [blame] | 67 | |
Andrey Smirnov | 90696a4 | 2018-03-09 14:47:05 +0000 | [diff] [blame] | 68 | return PTR_ERR_OR_ZERO(nvmem); |
Carlo Caione | ad855ea | 2016-08-27 15:43:46 +0200 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static struct platform_driver meson_efuse_driver = { |
| 72 | .probe = meson_efuse_probe, |
Carlo Caione | ad855ea | 2016-08-27 15:43:46 +0200 | [diff] [blame] | 73 | .driver = { |
| 74 | .name = "meson-efuse", |
| 75 | .of_match_table = meson_efuse_match, |
| 76 | }, |
| 77 | }; |
| 78 | |
| 79 | module_platform_driver(meson_efuse_driver); |
| 80 | |
| 81 | MODULE_AUTHOR("Carlo Caione <carlo@endlessm.com>"); |
Martin Blumenstingl | 9593ad3 | 2017-10-09 15:26:40 +0200 | [diff] [blame] | 82 | MODULE_DESCRIPTION("Amlogic Meson GX NVMEM driver"); |
Carlo Caione | ad855ea | 2016-08-27 15:43:46 +0200 | [diff] [blame] | 83 | MODULE_LICENSE("GPL v2"); |