Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * exynos-nocp.c - Exynos NoC (Network On Chip) Probe support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Author : Chanwoo Choi <cw00.choi@samsung.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/devfreq-event.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/of_address.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "exynos-nocp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) struct exynos_nocp {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	struct devfreq_event_dev *edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	struct devfreq_event_desc desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	struct regmap *regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	struct clk *clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * The devfreq-event ops structure for nocp probe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static int exynos_nocp_set_event(struct devfreq_event_dev *edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct exynos_nocp *nocp = devfreq_event_get_drvdata(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	/* Disable NoC probe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	ret = regmap_update_bits(nocp->regmap, NOCP_MAIN_CTL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 				NOCP_MAIN_CTL_STATEN_MASK, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		dev_err(nocp->dev, "failed to disable the NoC probe device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	/* Set a statistics dump period to 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	ret = regmap_write(nocp->regmap, NOCP_STAT_PERIOD, 0x0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	/* Set the IntEvent fields of *_SRC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	ret = regmap_update_bits(nocp->regmap, NOCP_COUNTERS_0_SRC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 				NOCP_CNT_SRC_INTEVENT_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 				NOCP_CNT_SRC_INTEVENT_BYTE_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	ret = regmap_update_bits(nocp->regmap, NOCP_COUNTERS_1_SRC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 				NOCP_CNT_SRC_INTEVENT_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 				NOCP_CNT_SRC_INTEVENT_CHAIN_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	ret = regmap_update_bits(nocp->regmap, NOCP_COUNTERS_2_SRC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 				NOCP_CNT_SRC_INTEVENT_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 				NOCP_CNT_SRC_INTEVENT_CYCLE_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	ret = regmap_update_bits(nocp->regmap, NOCP_COUNTERS_3_SRC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 				NOCP_CNT_SRC_INTEVENT_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 				NOCP_CNT_SRC_INTEVENT_CHAIN_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	/* Set an alarm with a max/min value of 0 to generate StatALARM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	ret = regmap_write(nocp->regmap, NOCP_STAT_ALARM_MIN, 0x0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	ret = regmap_write(nocp->regmap, NOCP_STAT_ALARM_MAX, 0x0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	/* Set AlarmMode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	ret = regmap_update_bits(nocp->regmap, NOCP_COUNTERS_0_ALARM_MODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 				NOCP_CNT_ALARM_MODE_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 				NOCP_CNT_ALARM_MODE_MIN_MAX_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	ret = regmap_update_bits(nocp->regmap, NOCP_COUNTERS_1_ALARM_MODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 				NOCP_CNT_ALARM_MODE_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 				NOCP_CNT_ALARM_MODE_MIN_MAX_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	ret = regmap_update_bits(nocp->regmap, NOCP_COUNTERS_2_ALARM_MODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 				NOCP_CNT_ALARM_MODE_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 				NOCP_CNT_ALARM_MODE_MIN_MAX_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	ret = regmap_update_bits(nocp->regmap, NOCP_COUNTERS_3_ALARM_MODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 				NOCP_CNT_ALARM_MODE_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 				NOCP_CNT_ALARM_MODE_MIN_MAX_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	/* Enable the measurements by setting AlarmEn and StatEn */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	ret = regmap_update_bits(nocp->regmap, NOCP_MAIN_CTL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 			NOCP_MAIN_CTL_STATEN_MASK | NOCP_MAIN_CTL_ALARMEN_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			NOCP_MAIN_CTL_STATEN_MASK | NOCP_MAIN_CTL_ALARMEN_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	/* Set GlobalEN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	ret = regmap_update_bits(nocp->regmap, NOCP_CFG_CTL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 				NOCP_CFG_CTL_GLOBALEN_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 				NOCP_CFG_CTL_GLOBALEN_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	/* Enable NoC probe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	ret = regmap_update_bits(nocp->regmap, NOCP_MAIN_CTL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 				NOCP_MAIN_CTL_STATEN_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 				NOCP_MAIN_CTL_STATEN_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	/* Reset NoC probe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	if (regmap_update_bits(nocp->regmap, NOCP_MAIN_CTL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 				NOCP_MAIN_CTL_STATEN_MASK, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		dev_err(nocp->dev, "Failed to reset NoC probe device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static int exynos_nocp_get_event(struct devfreq_event_dev *edev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 				struct devfreq_event_data *edata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	struct exynos_nocp *nocp = devfreq_event_get_drvdata(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	unsigned int counter[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	/* Read cycle count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	ret = regmap_read(nocp->regmap, NOCP_COUNTERS_0_VAL, &counter[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	ret = regmap_read(nocp->regmap, NOCP_COUNTERS_1_VAL, &counter[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	ret = regmap_read(nocp->regmap, NOCP_COUNTERS_2_VAL, &counter[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	ret = regmap_read(nocp->regmap, NOCP_COUNTERS_3_VAL, &counter[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	edata->load_count = ((counter[1] << 16) | counter[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	edata->total_count = ((counter[3] << 16) | counter[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	dev_dbg(&edev->dev, "%s (event: %ld/%ld)\n", edev->desc->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 					edata->load_count, edata->total_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	dev_err(nocp->dev, "Failed to read the counter of NoC probe device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static const struct devfreq_event_ops exynos_nocp_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	.set_event = exynos_nocp_set_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	.get_event = exynos_nocp_get_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) static const struct of_device_id exynos_nocp_id_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	{ .compatible = "samsung,exynos5420-nocp", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	{ /* sentinel */ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) MODULE_DEVICE_TABLE(of, exynos_nocp_id_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static struct regmap_config exynos_nocp_regmap_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	.reg_bits = 32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	.val_bits = 32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	.reg_stride = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	.max_register = NOCP_COUNTERS_3_VAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) static int exynos_nocp_parse_dt(struct platform_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 				struct exynos_nocp *nocp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	struct device *dev = nocp->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	struct device_node *np = dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	void __iomem *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	if (!np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		dev_err(dev, "failed to find devicetree node\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	nocp->clk = devm_clk_get(dev, "nocp");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	if (IS_ERR(nocp->clk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		nocp->clk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	/* Maps the memory mapped IO to control nocp register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	base = devm_ioremap_resource(dev, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	if (IS_ERR(base))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		return PTR_ERR(base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	exynos_nocp_regmap_config.max_register = resource_size(res) - 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	nocp->regmap = devm_regmap_init_mmio(dev, base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 					&exynos_nocp_regmap_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	if (IS_ERR(nocp->regmap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		dev_err(dev, "failed to initialize regmap\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		return PTR_ERR(nocp->regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static int exynos_nocp_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	struct device_node *np = dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	struct exynos_nocp *nocp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	nocp = devm_kzalloc(&pdev->dev, sizeof(*nocp), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	if (!nocp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	nocp->dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	/* Parse dt data to get resource */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	ret = exynos_nocp_parse_dt(pdev, nocp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 			"failed to parse devicetree for resource\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	/* Add devfreq-event device to measure the bandwidth of NoC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	nocp->desc.ops = &exynos_nocp_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	nocp->desc.driver_data = nocp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	nocp->desc.name = np->full_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	nocp->edev = devm_devfreq_event_add_edev(&pdev->dev, &nocp->desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	if (IS_ERR(nocp->edev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 			"failed to add devfreq-event device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		return PTR_ERR(nocp->edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	platform_set_drvdata(pdev, nocp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	ret = clk_prepare_enable(nocp->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		dev_err(&pdev->dev, "failed to prepare ppmu clock\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	pr_info("exynos-nocp: new NoC Probe device registered: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			dev_name(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) static int exynos_nocp_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	struct exynos_nocp *nocp = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	clk_disable_unprepare(nocp->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static struct platform_driver exynos_nocp_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	.probe	= exynos_nocp_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	.remove	= exynos_nocp_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		.name	= "exynos-nocp",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		.of_match_table = exynos_nocp_id_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) module_platform_driver(exynos_nocp_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) MODULE_DESCRIPTION("Exynos NoC (Network on Chip) Probe driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) MODULE_LICENSE("GPL");