xref: /openbmc/linux/drivers/reset/reset-qcom-aoss.c (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
15ecb0651SSibi Sankar // SPDX-License-Identifier: GPL-2.0
25ecb0651SSibi Sankar /*
35ecb0651SSibi Sankar  * Copyright (C) 2018 The Linux Foundation. All rights reserved.
45ecb0651SSibi Sankar  */
55ecb0651SSibi Sankar 
65ecb0651SSibi Sankar #include <linux/module.h>
75ecb0651SSibi Sankar #include <linux/platform_device.h>
85ecb0651SSibi Sankar #include <linux/reset-controller.h>
95ecb0651SSibi Sankar #include <linux/delay.h>
105ecb0651SSibi Sankar #include <linux/io.h>
11*bad8a8afSRob Herring #include <linux/of.h>
125ecb0651SSibi Sankar #include <dt-bindings/reset/qcom,sdm845-aoss.h>
135ecb0651SSibi Sankar 
145ecb0651SSibi Sankar struct qcom_aoss_reset_map {
155ecb0651SSibi Sankar 	unsigned int reg;
165ecb0651SSibi Sankar };
175ecb0651SSibi Sankar 
185ecb0651SSibi Sankar struct qcom_aoss_desc {
195ecb0651SSibi Sankar 	const struct qcom_aoss_reset_map *resets;
205ecb0651SSibi Sankar 	size_t num_resets;
215ecb0651SSibi Sankar };
225ecb0651SSibi Sankar 
235ecb0651SSibi Sankar struct qcom_aoss_reset_data {
245ecb0651SSibi Sankar 	struct reset_controller_dev rcdev;
255ecb0651SSibi Sankar 	void __iomem *base;
265ecb0651SSibi Sankar 	const struct qcom_aoss_desc *desc;
275ecb0651SSibi Sankar };
285ecb0651SSibi Sankar 
295ecb0651SSibi Sankar static const struct qcom_aoss_reset_map sdm845_aoss_resets[] = {
305ecb0651SSibi Sankar 	[AOSS_CC_MSS_RESTART] = {0x10000},
315ecb0651SSibi Sankar 	[AOSS_CC_CAMSS_RESTART] = {0x11000},
325ecb0651SSibi Sankar 	[AOSS_CC_VENUS_RESTART] = {0x12000},
335ecb0651SSibi Sankar 	[AOSS_CC_GPU_RESTART] = {0x13000},
345ecb0651SSibi Sankar 	[AOSS_CC_DISPSS_RESTART] = {0x14000},
355ecb0651SSibi Sankar 	[AOSS_CC_WCSS_RESTART] = {0x20000},
365ecb0651SSibi Sankar 	[AOSS_CC_LPASS_RESTART] = {0x30000},
375ecb0651SSibi Sankar };
385ecb0651SSibi Sankar 
395ecb0651SSibi Sankar static const struct qcom_aoss_desc sdm845_aoss_desc = {
405ecb0651SSibi Sankar 	.resets = sdm845_aoss_resets,
415ecb0651SSibi Sankar 	.num_resets = ARRAY_SIZE(sdm845_aoss_resets),
425ecb0651SSibi Sankar };
435ecb0651SSibi Sankar 
to_qcom_aoss_reset_data(struct reset_controller_dev * rcdev)445ecb0651SSibi Sankar static inline struct qcom_aoss_reset_data *to_qcom_aoss_reset_data(
455ecb0651SSibi Sankar 				struct reset_controller_dev *rcdev)
465ecb0651SSibi Sankar {
475ecb0651SSibi Sankar 	return container_of(rcdev, struct qcom_aoss_reset_data, rcdev);
485ecb0651SSibi Sankar }
495ecb0651SSibi Sankar 
qcom_aoss_control_assert(struct reset_controller_dev * rcdev,unsigned long idx)505ecb0651SSibi Sankar static int qcom_aoss_control_assert(struct reset_controller_dev *rcdev,
515ecb0651SSibi Sankar 				    unsigned long idx)
525ecb0651SSibi Sankar {
535ecb0651SSibi Sankar 	struct qcom_aoss_reset_data *data = to_qcom_aoss_reset_data(rcdev);
545ecb0651SSibi Sankar 	const struct qcom_aoss_reset_map *map = &data->desc->resets[idx];
555ecb0651SSibi Sankar 
565ecb0651SSibi Sankar 	writel(1, data->base + map->reg);
575ecb0651SSibi Sankar 	/* Wait 6 32kHz sleep cycles for reset */
585ecb0651SSibi Sankar 	usleep_range(200, 300);
595ecb0651SSibi Sankar 	return 0;
605ecb0651SSibi Sankar }
615ecb0651SSibi Sankar 
qcom_aoss_control_deassert(struct reset_controller_dev * rcdev,unsigned long idx)625ecb0651SSibi Sankar static int qcom_aoss_control_deassert(struct reset_controller_dev *rcdev,
635ecb0651SSibi Sankar 				      unsigned long idx)
645ecb0651SSibi Sankar {
655ecb0651SSibi Sankar 	struct qcom_aoss_reset_data *data = to_qcom_aoss_reset_data(rcdev);
665ecb0651SSibi Sankar 	const struct qcom_aoss_reset_map *map = &data->desc->resets[idx];
675ecb0651SSibi Sankar 
685ecb0651SSibi Sankar 	writel(0, data->base + map->reg);
695ecb0651SSibi Sankar 	/* Wait 6 32kHz sleep cycles for reset */
705ecb0651SSibi Sankar 	usleep_range(200, 300);
715ecb0651SSibi Sankar 	return 0;
725ecb0651SSibi Sankar }
735ecb0651SSibi Sankar 
qcom_aoss_control_reset(struct reset_controller_dev * rcdev,unsigned long idx)745ecb0651SSibi Sankar static int qcom_aoss_control_reset(struct reset_controller_dev *rcdev,
755ecb0651SSibi Sankar 					unsigned long idx)
765ecb0651SSibi Sankar {
775ecb0651SSibi Sankar 	qcom_aoss_control_assert(rcdev, idx);
785ecb0651SSibi Sankar 
795ecb0651SSibi Sankar 	return qcom_aoss_control_deassert(rcdev, idx);
805ecb0651SSibi Sankar }
815ecb0651SSibi Sankar 
825ecb0651SSibi Sankar static const struct reset_control_ops qcom_aoss_reset_ops = {
835ecb0651SSibi Sankar 	.reset = qcom_aoss_control_reset,
845ecb0651SSibi Sankar 	.assert = qcom_aoss_control_assert,
855ecb0651SSibi Sankar 	.deassert = qcom_aoss_control_deassert,
865ecb0651SSibi Sankar };
875ecb0651SSibi Sankar 
qcom_aoss_reset_probe(struct platform_device * pdev)885ecb0651SSibi Sankar static int qcom_aoss_reset_probe(struct platform_device *pdev)
895ecb0651SSibi Sankar {
905ecb0651SSibi Sankar 	struct qcom_aoss_reset_data *data;
915ecb0651SSibi Sankar 	struct device *dev = &pdev->dev;
925ecb0651SSibi Sankar 	const struct qcom_aoss_desc *desc;
935ecb0651SSibi Sankar 	struct resource *res;
945ecb0651SSibi Sankar 
955ecb0651SSibi Sankar 	desc = of_device_get_match_data(dev);
965ecb0651SSibi Sankar 	if (!desc)
975ecb0651SSibi Sankar 		return -EINVAL;
985ecb0651SSibi Sankar 
995ecb0651SSibi Sankar 	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
1005ecb0651SSibi Sankar 	if (!data)
1015ecb0651SSibi Sankar 		return -ENOMEM;
1025ecb0651SSibi Sankar 
1035ecb0651SSibi Sankar 	data->desc = desc;
1045ecb0651SSibi Sankar 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1055ecb0651SSibi Sankar 	data->base = devm_ioremap_resource(dev, res);
1065ecb0651SSibi Sankar 	if (IS_ERR(data->base))
1075ecb0651SSibi Sankar 		return PTR_ERR(data->base);
1085ecb0651SSibi Sankar 
1095ecb0651SSibi Sankar 	data->rcdev.owner = THIS_MODULE;
1105ecb0651SSibi Sankar 	data->rcdev.ops = &qcom_aoss_reset_ops;
1115ecb0651SSibi Sankar 	data->rcdev.nr_resets = desc->num_resets;
1125ecb0651SSibi Sankar 	data->rcdev.of_node = dev->of_node;
1135ecb0651SSibi Sankar 
1145ecb0651SSibi Sankar 	return devm_reset_controller_register(dev, &data->rcdev);
1155ecb0651SSibi Sankar }
1165ecb0651SSibi Sankar 
1175ecb0651SSibi Sankar static const struct of_device_id qcom_aoss_reset_of_match[] = {
1185ecb0651SSibi Sankar 	{ .compatible = "qcom,sdm845-aoss-cc", .data = &sdm845_aoss_desc },
1195ecb0651SSibi Sankar 	{}
1205ecb0651SSibi Sankar };
121e2d5e833SJohn Stultz MODULE_DEVICE_TABLE(of, qcom_aoss_reset_of_match);
1225ecb0651SSibi Sankar 
1235ecb0651SSibi Sankar static struct platform_driver qcom_aoss_reset_driver = {
1245ecb0651SSibi Sankar 	.probe = qcom_aoss_reset_probe,
1255ecb0651SSibi Sankar 	.driver  = {
1265ecb0651SSibi Sankar 		.name = "qcom_aoss_reset",
1275ecb0651SSibi Sankar 		.of_match_table = qcom_aoss_reset_of_match,
1285ecb0651SSibi Sankar 	},
1295ecb0651SSibi Sankar };
1305ecb0651SSibi Sankar 
131e2d5e833SJohn Stultz module_platform_driver(qcom_aoss_reset_driver);
1325ecb0651SSibi Sankar 
1335ecb0651SSibi Sankar MODULE_DESCRIPTION("Qualcomm AOSS Reset Driver");
1345ecb0651SSibi Sankar MODULE_LICENSE("GPL v2");
135