···11+* Amlogic GXBB AO Clock and Reset Unit22+33+The Amlogic GXBB AO clock controller generates and supplies clock to various44+controllers within the Always-On part of the SoC.55+66+Required Properties:77+88+- compatible: should be "amlogic,gxbb-aoclkc"99+- reg: physical base address of the clock controller and length of memory1010+ mapped region.1111+1212+- #clock-cells: should be 1.1313+1414+Each clock is assigned an identifier and client nodes can use this identifier1515+to specify the clock which they consume. All available clocks are defined as1616+preprocessor macros in the dt-bindings/clock/gxbb-aoclkc.h header and can be1717+used in device tree sources.1818+1919+- #reset-cells: should be 1.2020+2121+Each reset is assigned an identifier and client nodes can use this identifier2222+to specify the reset which they consume. All available resets are defined as2323+preprocessor macros in the dt-bindings/reset/gxbb-aoclkc.h header and can be2424+used in device tree sources.2525+2626+Example: AO Clock controller node:2727+2828+ clkc_AO: clock-controller@040 {2929+ compatible = "amlogic,gxbb-aoclkc";3030+ reg = <0x0 0x040 0x0 0x4>;3131+ #clock-cells = <1>;3232+ #reset-cells = <1>;3333+ };3434+3535+Example: UART controller node that consumes the clock and reset generated3636+ by the clock controller:3737+3838+ uart_AO: serial@4c0 {3939+ compatible = "amlogic,meson-uart";4040+ reg = <0x4c0 0x14>;4141+ interrupts = <0 90 1>;4242+ clocks = <&clkc_AO CLKID_AO_UART1>;4343+ resets = <&clkc_AO RESET_AO_UART1>;4444+ status = "disabled";4545+ };
···11+/*22+ * This file is provided under a dual BSD/GPLv2 license. When using or33+ * redistributing this file, you may do so under either license.44+ *55+ * GPL LICENSE SUMMARY66+ *77+ * Copyright (c) 2016 BayLibre, SAS.88+ * Author: Neil Armstrong <narmstrong@baylibre.com>99+ *1010+ * This program is free software; you can redistribute it and/or modify1111+ * it under the terms of version 2 of the GNU General Public License as1212+ * published by the Free Software Foundation.1313+ *1414+ * This program is distributed in the hope that it will be useful, but1515+ * WITHOUT ANY WARRANTY; without even the implied warranty of1616+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU1717+ * General Public License for more details.1818+ *1919+ * You should have received a copy of the GNU General Public License2020+ * along with this program; if not, see <http://www.gnu.org/licenses/>.2121+ * The full GNU General Public License is included in this distribution2222+ * in the file called COPYING.2323+ *2424+ * BSD LICENSE2525+ *2626+ * Copyright (c) 2016 BayLibre, SAS.2727+ * Author: Neil Armstrong <narmstrong@baylibre.com>2828+ *2929+ * Redistribution and use in source and binary forms, with or without3030+ * modification, are permitted provided that the following conditions3131+ * are met:3232+ *3333+ * * Redistributions of source code must retain the above copyright3434+ * notice, this list of conditions and the following disclaimer.3535+ * * Redistributions in binary form must reproduce the above copyright3636+ * notice, this list of conditions and the following disclaimer in3737+ * the documentation and/or other materials provided with the3838+ * distribution.3939+ * * Neither the name of Intel Corporation nor the names of its4040+ * contributors may be used to endorse or promote products derived4141+ * from this software without specific prior written permission.4242+ *4343+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS4444+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT4545+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR4646+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT4747+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,4848+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT4949+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,5050+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY5151+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT5252+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE5353+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.5454+ */5555+#include <linux/clk-provider.h>5656+#include <linux/of_address.h>5757+#include <linux/platform_device.h>5858+#include <linux/reset-controller.h>5959+#include <linux/init.h>6060+#include <dt-bindings/clock/gxbb-aoclkc.h>6161+#include <dt-bindings/reset/gxbb-aoclkc.h>6262+6363+static DEFINE_SPINLOCK(gxbb_aoclk_lock);6464+6565+struct gxbb_aoclk_reset_controller {6666+ struct reset_controller_dev reset;6767+ unsigned int *data;6868+ void __iomem *base;6969+};7070+7171+static int gxbb_aoclk_do_reset(struct reset_controller_dev *rcdev,7272+ unsigned long id)7373+{7474+ struct gxbb_aoclk_reset_controller *reset =7575+ container_of(rcdev, struct gxbb_aoclk_reset_controller, reset);7676+7777+ writel(BIT(reset->data[id]), reset->base);7878+7979+ return 0;8080+}8181+8282+static const struct reset_control_ops gxbb_aoclk_reset_ops = {8383+ .reset = gxbb_aoclk_do_reset,8484+};8585+8686+#define GXBB_AO_GATE(_name, _bit) \8787+static struct clk_gate _name##_ao = { \8888+ .reg = (void __iomem *)0, \8989+ .bit_idx = (_bit), \9090+ .lock = &gxbb_aoclk_lock, \9191+ .hw.init = &(struct clk_init_data) { \9292+ .name = #_name "_ao", \9393+ .ops = &clk_gate_ops, \9494+ .parent_names = (const char *[]){ "clk81" }, \9595+ .num_parents = 1, \9696+ .flags = (CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED), \9797+ }, \9898+}9999+100100+GXBB_AO_GATE(remote, 0);101101+GXBB_AO_GATE(i2c_master, 1);102102+GXBB_AO_GATE(i2c_slave, 2);103103+GXBB_AO_GATE(uart1, 3);104104+GXBB_AO_GATE(uart2, 5);105105+GXBB_AO_GATE(ir_blaster, 6);106106+107107+static unsigned int gxbb_aoclk_reset[] = {108108+ [RESET_AO_REMOTE] = 16,109109+ [RESET_AO_I2C_MASTER] = 18,110110+ [RESET_AO_I2C_SLAVE] = 19,111111+ [RESET_AO_UART1] = 17,112112+ [RESET_AO_UART2] = 22,113113+ [RESET_AO_IR_BLASTER] = 23,114114+};115115+116116+static struct clk_gate *gxbb_aoclk_gate[] = {117117+ [CLKID_AO_REMOTE] = &remote_ao,118118+ [CLKID_AO_I2C_MASTER] = &i2c_master_ao,119119+ [CLKID_AO_I2C_SLAVE] = &i2c_slave_ao,120120+ [CLKID_AO_UART1] = &uart1_ao,121121+ [CLKID_AO_UART2] = &uart2_ao,122122+ [CLKID_AO_IR_BLASTER] = &ir_blaster_ao,123123+};124124+125125+static struct clk_hw_onecell_data gxbb_aoclk_onecell_data = {126126+ .hws = {127127+ [CLKID_AO_REMOTE] = &remote_ao.hw,128128+ [CLKID_AO_I2C_MASTER] = &i2c_master_ao.hw,129129+ [CLKID_AO_I2C_SLAVE] = &i2c_slave_ao.hw,130130+ [CLKID_AO_UART1] = &uart1_ao.hw,131131+ [CLKID_AO_UART2] = &uart2_ao.hw,132132+ [CLKID_AO_IR_BLASTER] = &ir_blaster_ao.hw,133133+ },134134+ .num = ARRAY_SIZE(gxbb_aoclk_gate),135135+};136136+137137+static int gxbb_aoclkc_probe(struct platform_device *pdev)138138+{139139+ struct resource *res;140140+ void __iomem *base;141141+ int ret, clkid;142142+ struct device *dev = &pdev->dev;143143+ struct gxbb_aoclk_reset_controller *rstc;144144+145145+ rstc = devm_kzalloc(dev, sizeof(rstc), GFP_KERNEL);146146+ if (!rstc)147147+ return -ENOMEM;148148+149149+ /* Generic clocks */150150+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);151151+ base = devm_ioremap_resource(dev, res);152152+ if (IS_ERR(base))153153+ return PTR_ERR(base);154154+155155+ /* Reset Controller */156156+ rstc->base = base;157157+ rstc->data = gxbb_aoclk_reset;158158+ rstc->reset.ops = &gxbb_aoclk_reset_ops;159159+ rstc->reset.nr_resets = ARRAY_SIZE(gxbb_aoclk_reset);160160+ rstc->reset.of_node = dev->of_node;161161+ ret = devm_reset_controller_register(dev, &rstc->reset);162162+163163+ /*164164+ * Populate base address and register all clks165165+ */166166+ for (clkid = 0; clkid < gxbb_aoclk_onecell_data.num; clkid++) {167167+ gxbb_aoclk_gate[clkid]->reg = base;168168+169169+ ret = devm_clk_hw_register(dev,170170+ gxbb_aoclk_onecell_data.hws[clkid]);171171+ if (ret)172172+ return ret;173173+ }174174+175175+ return of_clk_add_hw_provider(dev->of_node, of_clk_hw_onecell_get,176176+ &gxbb_aoclk_onecell_data);177177+}178178+179179+static const struct of_device_id gxbb_aoclkc_match_table[] = {180180+ { .compatible = "amlogic,gxbb-aoclkc" },181181+ { }182182+};183183+184184+static struct platform_driver gxbb_aoclkc_driver = {185185+ .probe = gxbb_aoclkc_probe,186186+ .driver = {187187+ .name = "gxbb-aoclkc",188188+ .of_match_table = gxbb_aoclkc_match_table,189189+ },190190+};191191+builtin_platform_driver(gxbb_aoclkc_driver);
+66
include/dt-bindings/clock/gxbb-aoclkc.h
···11+/*22+ * This file is provided under a dual BSD/GPLv2 license. When using or33+ * redistributing this file, you may do so under either license.44+ *55+ * GPL LICENSE SUMMARY66+ *77+ * Copyright (c) 2016 BayLibre, SAS.88+ * Author: Neil Armstrong <narmstrong@baylibre.com>99+ *1010+ * This program is free software; you can redistribute it and/or modify1111+ * it under the terms of version 2 of the GNU General Public License as1212+ * published by the Free Software Foundation.1313+ *1414+ * This program is distributed in the hope that it will be useful, but1515+ * WITHOUT ANY WARRANTY; without even the implied warranty of1616+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU1717+ * General Public License for more details.1818+ *1919+ * You should have received a copy of the GNU General Public License2020+ * along with this program; if not, see <http://www.gnu.org/licenses/>.2121+ * The full GNU General Public License is included in this distribution2222+ * in the file called COPYING.2323+ *2424+ * BSD LICENSE2525+ *2626+ * Copyright (c) 2016 BayLibre, SAS.2727+ * Author: Neil Armstrong <narmstrong@baylibre.com>2828+ *2929+ * Redistribution and use in source and binary forms, with or without3030+ * modification, are permitted provided that the following conditions3131+ * are met:3232+ *3333+ * * Redistributions of source code must retain the above copyright3434+ * notice, this list of conditions and the following disclaimer.3535+ * * Redistributions in binary form must reproduce the above copyright3636+ * notice, this list of conditions and the following disclaimer in3737+ * the documentation and/or other materials provided with the3838+ * distribution.3939+ * * Neither the name of Intel Corporation nor the names of its4040+ * contributors may be used to endorse or promote products derived4141+ * from this software without specific prior written permission.4242+ *4343+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS4444+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT4545+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR4646+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT4747+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,4848+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT4949+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,5050+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY5151+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT5252+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE5353+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.5454+ */5555+5656+#ifndef DT_BINDINGS_CLOCK_AMLOGIC_MESON_GXBB_AOCLK5757+#define DT_BINDINGS_CLOCK_AMLOGIC_MESON_GXBB_AOCLK5858+5959+#define CLKID_AO_REMOTE 06060+#define CLKID_AO_I2C_MASTER 16161+#define CLKID_AO_I2C_SLAVE 26262+#define CLKID_AO_UART1 36363+#define CLKID_AO_UART2 46464+#define CLKID_AO_IR_BLASTER 56565+6666+#endif
+66
include/dt-bindings/reset/gxbb-aoclkc.h
···11+/*22+ * This file is provided under a dual BSD/GPLv2 license. When using or33+ * redistributing this file, you may do so under either license.44+ *55+ * GPL LICENSE SUMMARY66+ *77+ * Copyright (c) 2016 BayLibre, SAS.88+ * Author: Neil Armstrong <narmstrong@baylibre.com>99+ *1010+ * This program is free software; you can redistribute it and/or modify1111+ * it under the terms of version 2 of the GNU General Public License as1212+ * published by the Free Software Foundation.1313+ *1414+ * This program is distributed in the hope that it will be useful, but1515+ * WITHOUT ANY WARRANTY; without even the implied warranty of1616+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU1717+ * General Public License for more details.1818+ *1919+ * You should have received a copy of the GNU General Public License2020+ * along with this program; if not, see <http://www.gnu.org/licenses/>.2121+ * The full GNU General Public License is included in this distribution2222+ * in the file called COPYING.2323+ *2424+ * BSD LICENSE2525+ *2626+ * Copyright (c) 2016 BayLibre, SAS.2727+ * Author: Neil Armstrong <narmstrong@baylibre.com>2828+ *2929+ * Redistribution and use in source and binary forms, with or without3030+ * modification, are permitted provided that the following conditions3131+ * are met:3232+ *3333+ * * Redistributions of source code must retain the above copyright3434+ * notice, this list of conditions and the following disclaimer.3535+ * * Redistributions in binary form must reproduce the above copyright3636+ * notice, this list of conditions and the following disclaimer in3737+ * the documentation and/or other materials provided with the3838+ * distribution.3939+ * * Neither the name of Intel Corporation nor the names of its4040+ * contributors may be used to endorse or promote products derived4141+ * from this software without specific prior written permission.4242+ *4343+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS4444+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT4545+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR4646+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT4747+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,4848+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT4949+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,5050+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY5151+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT5252+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE5353+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.5454+ */5555+5656+#ifndef DT_BINDINGS_RESET_AMLOGIC_MESON_GXBB_AOCLK5757+#define DT_BINDINGS_RESET_AMLOGIC_MESON_GXBB_AOCLK5858+5959+#define RESET_AO_REMOTE 06060+#define RESET_AO_I2C_MASTER 16161+#define RESET_AO_I2C_SLAVE 26262+#define RESET_AO_UART1 36363+#define RESET_AO_UART2 46464+#define RESET_AO_IR_BLASTER 56565+6666+#endif