Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4627274b authored by Taniya Das's avatar Taniya Das Committed by Gerrit - the friendly Code Review server
Browse files

clk: msm: Add reset controller support



A reset signal is associated with each clock branch but sometimes a reset
signal is associated with a handful of clocks. Either way the register
interface is the same; set a bit to assert a reset and clear a bit to
deassert a reset. Add support for these types of resets signals.

Change-Id: Ic9d00c0a03507a55ca6c96f977a6ddf55b4b5db7
Signed-off-by: default avatarTaniya Das <tdas@codeaurora.org>
parent e94b446e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ obj-$(CONFIG_COMMON_CLK_MSM) += clock-pll.o
obj-$(CONFIG_COMMON_CLK_MSM)	+= clock-alpha-pll.o
obj-$(CONFIG_COMMON_CLK_MSM)	+= clock-rpm.o
obj-$(CONFIG_COMMON_CLK_MSM)	+= clock-voter.o
obj-$(CONFIG_COMMON_CLK_MSM)	+= reset.o

obj-$(CONFIG_MSM_CLK_CONTROLLER_V2)	+= msm-clock-controller.o

+94 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2016, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <linux/device.h>
#include <linux/delay.h>
#include <linux/io.h>
#include <linux/reset-controller.h>

#include "reset.h"

static int msm_reset(struct reset_controller_dev *rcdev, unsigned long id)
{
	rcdev->ops->assert(rcdev, id);
	udelay(1);
	rcdev->ops->deassert(rcdev, id);
	return 0;
}

static int
msm_reset_assert(struct reset_controller_dev *rcdev, unsigned long id)
{
	struct msm_reset_controller *rst;
	const struct msm_reset_map *map;
	u32 regval;

	rst = to_msm_reset_controller(rcdev);
	map = &rst->reset_map[id];

	regval = readl_relaxed(rst->base + map->reg);
	regval |= BIT(map->bit);
	writel_relaxed(regval, rst->base + map->reg);

	return 0;
}

static int
msm_reset_deassert(struct reset_controller_dev *rcdev, unsigned long id)
{
	struct msm_reset_controller *rst;
	const struct msm_reset_map *map;
	u32 regval;

	rst = to_msm_reset_controller(rcdev);
	map = &rst->reset_map[id];

	regval = readl_relaxed(rst->base + map->reg);
	regval &= ~BIT(map->bit);
	writel_relaxed(regval, rst->base + map->reg);

	return 0;
}

struct reset_control_ops msm_reset_ops = {
	.reset = msm_reset,
	.assert = msm_reset_assert,
	.deassert = msm_reset_deassert,
};
EXPORT_SYMBOL_GPL(msm_reset_ops);

int msm_reset_controller_register(struct platform_device *pdev,
	const struct msm_reset_map *map, unsigned int num_resets,
	void __iomem *virt_base)
{
	struct msm_reset_controller *reset;
	int ret = 0;

	reset = devm_kzalloc(&pdev->dev, sizeof(*reset), GFP_KERNEL);
	if (!reset)
		return -ENOMEM;

	reset->rcdev.of_node = pdev->dev.of_node;
	reset->rcdev.ops = &msm_reset_ops;
	reset->rcdev.owner = pdev->dev.driver->owner;
	reset->rcdev.nr_resets = num_resets;
	reset->reset_map = map;
	reset->base = virt_base;

	ret = reset_controller_register(&reset->rcdev);
	if (ret)
		dev_err(&pdev->dev, "Failed to register with reset controller\n");

	return ret;
}
EXPORT_SYMBOL_GPL(msm_reset_controller_register);
+39 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2016, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#ifndef __DRIVERS_CLK_RESET_H
#define __DRIVERS_CLK_RESET_H

#include <linux/platform_device.h>
#include <linux/reset-controller.h>

struct msm_reset_map {
	unsigned int reg;
	u8 bit;
};

struct msm_reset_controller {
	const struct msm_reset_map *reset_map;
	struct reset_controller_dev rcdev;
	void __iomem  *base;
};

#define to_msm_reset_controller(r) \
	container_of(r, struct msm_reset_controller, rcdev)

extern struct reset_control_ops msm_reset_ops;

int msm_reset_controller_register(struct platform_device *pdev,
		const struct msm_reset_map *map, unsigned int nr_resets,
		void __iomem *virt_base);
#endif