Channagoud Kadabi | 97335b2 | 2016-08-17 13:40:46 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2016, The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/err.h> |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/of.h> |
| 17 | #include <linux/of_device.h> |
| 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/mfd/syscon.h> |
| 20 | #include <linux/regmap.h> |
| 21 | |
| 22 | /* Config registers offsets*/ |
| 23 | #define COMMON_CFG0 0x00030004 |
Channagoud Kadabi | dbaf723 | 2016-10-10 15:25:19 -0700 | [diff] [blame^] | 24 | #define DRP_ECC_ERROR_CFG 0x00040000 |
| 25 | #define TRP_MISC_CFG 0x00022300 |
Channagoud Kadabi | 97335b2 | 2016-08-17 13:40:46 -0700 | [diff] [blame] | 26 | |
| 27 | /* TRP, DRP interrupt register offsets */ |
| 28 | #define CMN_INTERRUPT_0_ENABLE 0x0003001C |
Channagoud Kadabi | dbaf723 | 2016-10-10 15:25:19 -0700 | [diff] [blame^] | 29 | #define CMN_INTERRUPT_2_ENABLE 0x0003003C |
| 30 | #define TRP_INTERRUPT_0_ENABLE 0x00020488 |
| 31 | #define DRP_INTERRUPT_ENABLE 0x0004100C |
Channagoud Kadabi | 97335b2 | 2016-08-17 13:40:46 -0700 | [diff] [blame] | 32 | |
| 33 | #define DATA_RAM_ECC_ENABLE 0x1 |
| 34 | #define SB_ERROR_THRESHOLD 0x1 |
| 35 | #define SB_ERROR_THRESHOLD_SHIFT 24 |
| 36 | #define TAG_RAM_ECC_DISABLE 0x1 |
| 37 | #define TAG_RAM_ECC_DISABLE_SHIFT 0x1 |
| 38 | #define SB_DB_TRP_INTERRUPT_ENABLE 0x3 |
| 39 | #define TRP0_INTERRUPT_ENABLE 0x1 |
Channagoud Kadabi | dbaf723 | 2016-10-10 15:25:19 -0700 | [diff] [blame^] | 40 | #define DRP0_INTERRUPT_ENABLE BIT(6) |
Channagoud Kadabi | 97335b2 | 2016-08-17 13:40:46 -0700 | [diff] [blame] | 41 | #define COMMON_INTERRUPT_0_AMON BIT(8) |
| 42 | #define SB_DB_DRP_INTERRUPT_ENABLE 0x3 |
| 43 | |
| 44 | static void qcom_llcc_core_setup(struct regmap *llcc_regmap) |
| 45 | { |
| 46 | u32 trp_misc_val; |
| 47 | u32 sb_err_threshold; |
| 48 | |
Channagoud Kadabi | dbaf723 | 2016-10-10 15:25:19 -0700 | [diff] [blame^] | 49 | /* Enable Tag RAM ECC */ |
| 50 | trp_misc_val = (TAG_RAM_ECC_DISABLE << TAG_RAM_ECC_DISABLE_SHIFT); |
| 51 | regmap_update_bits(llcc_regmap, TRP_MISC_CFG, |
| 52 | ~trp_misc_val, trp_misc_val); |
| 53 | |
| 54 | /* Enable TRP in instance 2 of common interrupt enable register */ |
| 55 | regmap_update_bits(llcc_regmap, CMN_INTERRUPT_2_ENABLE, |
| 56 | TRP0_INTERRUPT_ENABLE, TRP0_INTERRUPT_ENABLE); |
| 57 | |
| 58 | /* Enable ECC interrupts on Tag Ram */ |
| 59 | regmap_update_bits(llcc_regmap, TRP_INTERRUPT_0_ENABLE, |
| 60 | SB_DB_TRP_INTERRUPT_ENABLE, SB_DB_TRP_INTERRUPT_ENABLE); |
| 61 | |
Channagoud Kadabi | 97335b2 | 2016-08-17 13:40:46 -0700 | [diff] [blame] | 62 | /* Enable ECC for for data ram */ |
Channagoud Kadabi | dbaf723 | 2016-10-10 15:25:19 -0700 | [diff] [blame^] | 63 | regmap_update_bits(llcc_regmap, COMMON_CFG0, |
| 64 | DATA_RAM_ECC_ENABLE, DATA_RAM_ECC_ENABLE); |
Channagoud Kadabi | 97335b2 | 2016-08-17 13:40:46 -0700 | [diff] [blame] | 65 | |
| 66 | /* Enable SB error for Data RAM */ |
| 67 | sb_err_threshold = (SB_ERROR_THRESHOLD << SB_ERROR_THRESHOLD_SHIFT); |
| 68 | regmap_write(llcc_regmap, DRP_ECC_ERROR_CFG, sb_err_threshold); |
| 69 | |
Channagoud Kadabi | dbaf723 | 2016-10-10 15:25:19 -0700 | [diff] [blame^] | 70 | /* Enable DRP in instance 2 of common interrupt enable register */ |
| 71 | regmap_update_bits(llcc_regmap, CMN_INTERRUPT_2_ENABLE, |
| 72 | DRP0_INTERRUPT_ENABLE, DRP0_INTERRUPT_ENABLE); |
Channagoud Kadabi | 97335b2 | 2016-08-17 13:40:46 -0700 | [diff] [blame] | 73 | |
| 74 | /* Enable ECC interrupts on Data Ram */ |
| 75 | regmap_write(llcc_regmap, DRP_INTERRUPT_ENABLE, |
| 76 | SB_DB_DRP_INTERRUPT_ENABLE); |
Channagoud Kadabi | dbaf723 | 2016-10-10 15:25:19 -0700 | [diff] [blame^] | 77 | |
Channagoud Kadabi | 97335b2 | 2016-08-17 13:40:46 -0700 | [diff] [blame] | 78 | /* Enable AMON interrupt in the common interrupt register */ |
Channagoud Kadabi | dbaf723 | 2016-10-10 15:25:19 -0700 | [diff] [blame^] | 79 | regmap_update_bits(llcc_regmap, CMN_INTERRUPT_0_ENABLE, |
| 80 | COMMON_INTERRUPT_0_AMON, COMMON_INTERRUPT_0_AMON); |
Channagoud Kadabi | 97335b2 | 2016-08-17 13:40:46 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | static int qcom_llcc_core_probe(struct platform_device *pdev) |
| 84 | { |
| 85 | struct regmap *llcc_regmap; |
| 86 | struct device *dev = &pdev->dev; |
| 87 | |
| 88 | llcc_regmap = syscon_node_to_regmap(dev->of_node); |
| 89 | |
| 90 | if (IS_ERR(llcc_regmap)) { |
| 91 | dev_err(&pdev->dev, "Cannot find regmap for llcc\n"); |
| 92 | return PTR_ERR(llcc_regmap); |
| 93 | } |
| 94 | |
| 95 | qcom_llcc_core_setup(llcc_regmap); |
| 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | static int qcom_llcc_core_remove(struct platform_device *pdev) |
| 101 | { |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | static const struct of_device_id qcom_llcc_core_match_table[] = { |
| 106 | { .compatible = "qcom,llcc-core" }, |
| 107 | { }, |
| 108 | }; |
| 109 | |
| 110 | static struct platform_driver qcom_llcc_core_driver = { |
| 111 | .probe = qcom_llcc_core_probe, |
| 112 | .remove = qcom_llcc_core_remove, |
| 113 | .driver = { |
| 114 | .name = "qcom_llcc_core", |
| 115 | .owner = THIS_MODULE, |
| 116 | .of_match_table = qcom_llcc_core_match_table, |
| 117 | }, |
| 118 | }; |
| 119 | |
| 120 | static int __init qcom_llcc_core_init(void) |
| 121 | { |
| 122 | return platform_driver_register(&qcom_llcc_core_driver); |
| 123 | } |
| 124 | module_init(qcom_llcc_core_init); |
| 125 | |
| 126 | static void __exit qcom_llcc_core_exit(void) |
| 127 | { |
| 128 | platform_driver_unregister(&qcom_llcc_core_driver); |
| 129 | } |
| 130 | module_exit(qcom_llcc_core_exit); |
| 131 | |
| 132 | MODULE_DESCRIPTION("QCOM LLCC Core Driver"); |
| 133 | MODULE_LICENSE("GPL v2"); |