···11+= Reset Signal Device Tree Bindings =22+33+This binding is intended to represent the hardware reset signals present44+internally in most IC (SoC, FPGA, ...) designs. Reset signals for whole55+standalone chips are most likely better represented as GPIOs, although there66+are likely to be exceptions to this rule.77+88+Hardware blocks typically receive a reset signal. This signal is generated by99+a reset provider (e.g. power management or clock module) and received by a1010+reset consumer (the module being reset, or a module managing when a sub-1111+ordinate module is reset). This binding exists to represent the provider and1212+consumer, and provide a way to couple the two together.1313+1414+A reset signal is represented by the phandle of the provider, plus a reset1515+specifier - a list of DT cells that represents the reset signal within the1616+provider. The length (number of cells) and semantics of the reset specifier1717+are dictated by the binding of the reset provider, although common schemes1818+are described below.1919+2020+A word on where to place reset signal consumers in device tree: It is possible2121+in hardware for a reset signal to affect multiple logically separate HW blocks2222+at once. In this case, it would be unwise to represent this reset signal in2323+the DT node of each affected HW block, since if activated, an unrelated block2424+may be reset. Instead, reset signals should be represented in the DT node2525+where it makes most sense to control it; this may be a bus node if all2626+children of the bus are affected by the reset signal, or an individual HW2727+block node for dedicated reset signals. The intent of this binding is to give2828+appropriate software access to the reset signals in order to manage the HW,2929+rather than to slavishly enumerate the reset signal that affects each HW3030+block.3131+3232+= Reset providers =3333+3434+Required properties:3535+#reset-cells: Number of cells in a reset specifier; Typically 0 for nodes3636+ with a single reset output and 1 for nodes with multiple3737+ reset outputs.3838+3939+For example:4040+4141+ rst: reset-controller {4242+ #reset-cells = <1>;4343+ };4444+4545+= Reset consumers =4646+4747+Required properties:4848+resets: List of phandle and reset specifier pairs, one pair4949+ for each reset signal that affects the device, or that the5050+ device manages. Note: if the reset provider specifies '0' for5151+ #reset-cells, then only the phandle portion of the pair will5252+ appear.5353+5454+Optional properties:5555+reset-names: List of reset signal name strings sorted in the same order as5656+ the resets property. Consumers drivers will use reset-names to5757+ match reset signal names with reset specifiers.5858+5959+For example:6060+6161+ device {6262+ resets = <&rst 20>;6363+ reset-names = "reset";6464+ };6565+6666+This represents a device with a single reset signal named "reset".6767+6868+ bus {6969+ resets = <&rst 10> <&rst 11> <&rst 12> <&rst 11>;7070+ reset-names = "i2s1", "i2s2", "dma", "mixer";7171+ };7272+7373+This represents a bus that controls the reset signal of each of four sub-7474+ordinate devices. Consider for example a bus that fails to operate unless no7575+child device has reset asserted.
···3737# regulators early, since some subsystems rely on them to initialize3838obj-$(CONFIG_REGULATOR) += regulator/39394040+# reset controllers early, since gpu drivers might rely on them to initialize4141+obj-$(CONFIG_RESET_CONTROLLER) += reset/4242+4043# tty/ comes before char/ so that the VT console is the boot-time4144# default.4245obj-y += tty/
+13
drivers/reset/Kconfig
···11+config ARCH_HAS_RESET_CONTROLLER22+ bool33+44+menuconfig RESET_CONTROLLER55+ bool "Reset Controller Support"66+ default y if ARCH_HAS_RESET_CONTROLLER77+ help88+ Generic Reset Controller support.99+1010+ This framework is designed to abstract reset handling of devices1111+ via GPIOs or SoC-internal reset controller modules.1212+1313+ If unsure, say no.
···11+/*22+ * Reset Controller framework33+ *44+ * Copyright 2013 Philipp Zabel, Pengutronix55+ *66+ * This program is free software; you can redistribute it and/or modify77+ * it under the terms of the GNU General Public License as published by88+ * the Free Software Foundation; either version 2 of the License, or99+ * (at your option) any later version.1010+ */1111+#include <linux/device.h>1212+#include <linux/err.h>1313+#include <linux/export.h>1414+#include <linux/kernel.h>1515+#include <linux/module.h>1616+#include <linux/of.h>1717+#include <linux/reset.h>1818+#include <linux/reset-controller.h>1919+#include <linux/slab.h>2020+2121+static DEFINE_MUTEX(reset_controller_list_mutex);2222+static LIST_HEAD(reset_controller_list);2323+2424+/**2525+ * struct reset_control - a reset control2626+ * @rcdev: a pointer to the reset controller device2727+ * this reset control belongs to2828+ * @id: ID of the reset controller in the reset2929+ * controller device3030+ */3131+struct reset_control {3232+ struct reset_controller_dev *rcdev;3333+ struct device *dev;3434+ unsigned int id;3535+};3636+3737+/**3838+ * of_reset_simple_xlate - translate reset_spec to the reset line number3939+ * @rcdev: a pointer to the reset controller device4040+ * @reset_spec: reset line specifier as found in the device tree4141+ * @flags: a flags pointer to fill in (optional)4242+ *4343+ * This simple translation function should be used for reset controllers4444+ * with 1:1 mapping, where reset lines can be indexed by number without gaps.4545+ */4646+int of_reset_simple_xlate(struct reset_controller_dev *rcdev,4747+ const struct of_phandle_args *reset_spec)4848+{4949+ if (WARN_ON(reset_spec->args_count != rcdev->of_reset_n_cells))5050+ return -EINVAL;5151+5252+ if (reset_spec->args[0] >= rcdev->nr_resets)5353+ return -EINVAL;5454+5555+ return reset_spec->args[0];5656+}5757+EXPORT_SYMBOL_GPL(of_reset_simple_xlate);5858+5959+/**6060+ * reset_controller_register - register a reset controller device6161+ * @rcdev: a pointer to the initialized reset controller device6262+ */6363+int reset_controller_register(struct reset_controller_dev *rcdev)6464+{6565+ if (!rcdev->of_xlate) {6666+ rcdev->of_reset_n_cells = 1;6767+ rcdev->of_xlate = of_reset_simple_xlate;6868+ }6969+7070+ mutex_lock(&reset_controller_list_mutex);7171+ list_add(&rcdev->list, &reset_controller_list);7272+ mutex_unlock(&reset_controller_list_mutex);7373+7474+ return 0;7575+}7676+EXPORT_SYMBOL_GPL(reset_controller_register);7777+7878+/**7979+ * reset_controller_unregister - unregister a reset controller device8080+ * @rcdev: a pointer to the reset controller device8181+ */8282+void reset_controller_unregister(struct reset_controller_dev *rcdev)8383+{8484+ mutex_lock(&reset_controller_list_mutex);8585+ list_del(&rcdev->list);8686+ mutex_unlock(&reset_controller_list_mutex);8787+}8888+EXPORT_SYMBOL_GPL(reset_controller_unregister);8989+9090+/**9191+ * reset_control_reset - reset the controlled device9292+ * @rstc: reset controller9393+ */9494+int reset_control_reset(struct reset_control *rstc)9595+{9696+ if (rstc->rcdev->ops->reset)9797+ return rstc->rcdev->ops->reset(rstc->rcdev, rstc->id);9898+9999+ return -ENOSYS;100100+}101101+EXPORT_SYMBOL_GPL(reset_control_reset);102102+103103+/**104104+ * reset_control_assert - asserts the reset line105105+ * @rstc: reset controller106106+ */107107+int reset_control_assert(struct reset_control *rstc)108108+{109109+ if (rstc->rcdev->ops->assert)110110+ return rstc->rcdev->ops->assert(rstc->rcdev, rstc->id);111111+112112+ return -ENOSYS;113113+}114114+EXPORT_SYMBOL_GPL(reset_control_assert);115115+116116+/**117117+ * reset_control_deassert - deasserts the reset line118118+ * @rstc: reset controller119119+ */120120+int reset_control_deassert(struct reset_control *rstc)121121+{122122+ if (rstc->rcdev->ops->deassert)123123+ return rstc->rcdev->ops->deassert(rstc->rcdev, rstc->id);124124+125125+ return -ENOSYS;126126+}127127+EXPORT_SYMBOL_GPL(reset_control_deassert);128128+129129+/**130130+ * reset_control_get - Lookup and obtain a reference to a reset controller.131131+ * @dev: device to be reset by the controller132132+ * @id: reset line name133133+ *134134+ * Returns a struct reset_control or IS_ERR() condition containing errno.135135+ *136136+ * Use of id names is optional.137137+ */138138+struct reset_control *reset_control_get(struct device *dev, const char *id)139139+{140140+ struct reset_control *rstc = ERR_PTR(-EPROBE_DEFER);141141+ struct reset_controller_dev *r, *rcdev;142142+ struct of_phandle_args args;143143+ int index = 0;144144+ int rstc_id;145145+ int ret;146146+147147+ if (!dev)148148+ return ERR_PTR(-EINVAL);149149+150150+ if (id)151151+ index = of_property_match_string(dev->of_node,152152+ "reset-names", id);153153+ ret = of_parse_phandle_with_args(dev->of_node, "resets", "#reset-cells",154154+ index, &args);155155+ if (ret)156156+ return ERR_PTR(ret);157157+158158+ mutex_lock(&reset_controller_list_mutex);159159+ rcdev = NULL;160160+ list_for_each_entry(r, &reset_controller_list, list) {161161+ if (args.np == r->of_node) {162162+ rcdev = r;163163+ break;164164+ }165165+ }166166+ of_node_put(args.np);167167+168168+ if (!rcdev) {169169+ mutex_unlock(&reset_controller_list_mutex);170170+ return ERR_PTR(-ENODEV);171171+ }172172+173173+ rstc_id = rcdev->of_xlate(rcdev, &args);174174+ if (rstc_id < 0) {175175+ mutex_unlock(&reset_controller_list_mutex);176176+ return ERR_PTR(rstc_id);177177+ }178178+179179+ try_module_get(rcdev->owner);180180+ mutex_unlock(&reset_controller_list_mutex);181181+182182+ rstc = kzalloc(sizeof(*rstc), GFP_KERNEL);183183+ if (!rstc) {184184+ module_put(rcdev->owner);185185+ return ERR_PTR(-ENOMEM);186186+ }187187+188188+ rstc->dev = dev;189189+ rstc->rcdev = rcdev;190190+ rstc->id = rstc_id;191191+192192+ return rstc;193193+}194194+EXPORT_SYMBOL_GPL(reset_control_get);195195+196196+/**197197+ * reset_control_put - free the reset controller198198+ * @rstc: reset controller199199+ */200200+201201+void reset_control_put(struct reset_control *rstc)202202+{203203+ if (IS_ERR(rstc))204204+ return;205205+206206+ module_put(rstc->rcdev->owner);207207+ kfree(rstc);208208+}209209+EXPORT_SYMBOL_GPL(reset_control_put);210210+211211+static void devm_reset_control_release(struct device *dev, void *res)212212+{213213+ reset_control_put(*(struct reset_control **)res);214214+}215215+216216+/**217217+ * devm_reset_control_get - resource managed reset_control_get()218218+ * @dev: device to be reset by the controller219219+ * @id: reset line name220220+ *221221+ * Managed reset_control_get(). For reset controllers returned from this222222+ * function, reset_control_put() is called automatically on driver detach.223223+ * See reset_control_get() for more information.224224+ */225225+struct reset_control *devm_reset_control_get(struct device *dev, const char *id)226226+{227227+ struct reset_control **ptr, *rstc;228228+229229+ ptr = devres_alloc(devm_reset_control_release, sizeof(*ptr),230230+ GFP_KERNEL);231231+ if (!ptr)232232+ return ERR_PTR(-ENOMEM);233233+234234+ rstc = reset_control_get(dev, id);235235+ if (!IS_ERR(rstc)) {236236+ *ptr = rstc;237237+ devres_add(dev, ptr);238238+ } else {239239+ devres_free(ptr);240240+ }241241+242242+ return rstc;243243+}244244+EXPORT_SYMBOL_GPL(devm_reset_control_get);245245+246246+static int devm_reset_control_match(struct device *dev, void *res, void *data)247247+{248248+ struct reset_control **rstc = res;249249+ if (WARN_ON(!rstc || !*rstc))250250+ return 0;251251+ return *rstc == data;252252+}253253+254254+/**255255+ * devm_reset_control_put - resource managed reset_control_put()256256+ * @rstc: reset controller to free257257+ *258258+ * Deallocate a reset control allocated withd devm_reset_control_get().259259+ * This function will not need to be called normally, as devres will take260260+ * care of freeing the resource.261261+ */262262+void devm_reset_control_put(struct reset_control *rstc)263263+{264264+ int ret;265265+266266+ ret = devres_release(rstc->dev, devm_reset_control_release,267267+ devm_reset_control_match, rstc);268268+ if (ret)269269+ WARN_ON(ret);270270+}271271+EXPORT_SYMBOL_GPL(devm_reset_control_put);272272+273273+/**274274+ * device_reset - find reset controller associated with the device275275+ * and perform reset276276+ * @dev: device to be reset by the controller277277+ *278278+ * Convenience wrapper for reset_control_get() and reset_control_reset().279279+ * This is useful for the common case of devices with single, dedicated reset280280+ * lines.281281+ */282282+int device_reset(struct device *dev)283283+{284284+ struct reset_control *rstc;285285+ int ret;286286+287287+ rstc = reset_control_get(dev, NULL);288288+ if (IS_ERR(rstc))289289+ return PTR_ERR(rstc);290290+291291+ ret = reset_control_reset(rstc);292292+293293+ reset_control_put(rstc);294294+295295+ return ret;296296+}297297+EXPORT_SYMBOL_GPL(device_reset);
+51
include/linux/reset-controller.h
···11+#ifndef _LINUX_RESET_CONTROLLER_H_22+#define _LINUX_RESET_CONTROLLER_H_33+44+#include <linux/list.h>55+66+struct reset_controller_dev;77+88+/**99+ * struct reset_control_ops1010+ *1111+ * @reset: for self-deasserting resets, does all necessary1212+ * things to reset the device1313+ * @assert: manually assert the reset line, if supported1414+ * @deassert: manually deassert the reset line, if supported1515+ */1616+struct reset_control_ops {1717+ int (*reset)(struct reset_controller_dev *rcdev, unsigned long id);1818+ int (*assert)(struct reset_controller_dev *rcdev, unsigned long id);1919+ int (*deassert)(struct reset_controller_dev *rcdev, unsigned long id);2020+};2121+2222+struct module;2323+struct device_node;2424+2525+/**2626+ * struct reset_controller_dev - reset controller entity that might2727+ * provide multiple reset controls2828+ * @ops: a pointer to device specific struct reset_control_ops2929+ * @owner: kernel module of the reset controller driver3030+ * @list: internal list of reset controller devices3131+ * @of_node: corresponding device tree node as phandle target3232+ * @of_reset_n_cells: number of cells in reset line specifiers3333+ * @of_xlate: translation function to translate from specifier as found in the3434+ * device tree to id as given to the reset control ops3535+ * @nr_resets: number of reset controls in this reset controller device3636+ */3737+struct reset_controller_dev {3838+ struct reset_control_ops *ops;3939+ struct module *owner;4040+ struct list_head list;4141+ struct device_node *of_node;4242+ int of_reset_n_cells;4343+ int (*of_xlate)(struct reset_controller_dev *rcdev,4444+ const struct of_phandle_args *reset_spec);4545+ unsigned int nr_resets;4646+};4747+4848+int reset_controller_register(struct reset_controller_dev *rcdev);4949+void reset_controller_unregister(struct reset_controller_dev *rcdev);5050+5151+#endif