blob: 42ed61d3c3fba2c50187c45e5e2d612b49843e2f [file] [log] [blame]
Jerome Brunet22f65a32018-05-16 10:50:40 +02001// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
Neil Armstrongf8c11f72016-08-18 12:08:46 +02002/*
Neil Armstrongf8c11f72016-08-18 12:08:46 +02003 * Copyright (c) 2016 BayLibre, SAS.
4 * Author: Neil Armstrong <narmstrong@baylibre.com>
Neil Armstrongf8c11f72016-08-18 12:08:46 +02005 */
Neil Armstrongf8c11f72016-08-18 12:08:46 +02006#include <linux/platform_device.h>
Neil Armstrongffb13e32017-08-01 13:56:57 +02007#include <linux/mfd/syscon.h>
Jerome Brunet81c7fca2018-02-12 15:58:33 +01008#include "clk-regmap.h"
Yixun Lan88e2da82018-05-03 21:26:20 +08009#include "meson-aoclk.h"
Neil Armstrongffb13e32017-08-01 13:56:57 +020010#include "gxbb-aoclk.h"
Neil Armstrongf8c11f72016-08-18 12:08:46 +020011
Neil Armstrongf8c11f72016-08-18 12:08:46 +020012#define GXBB_AO_GATE(_name, _bit) \
Jerome Brunet81c7fca2018-02-12 15:58:33 +010013static struct clk_regmap _name##_ao = { \
14 .data = &(struct clk_regmap_gate_data) { \
15 .offset = AO_RTI_GEN_CNTL_REG0, \
16 .bit_idx = (_bit), \
17 }, \
Neil Armstrongf8c11f72016-08-18 12:08:46 +020018 .hw.init = &(struct clk_init_data) { \
19 .name = #_name "_ao", \
Jerome Brunet81c7fca2018-02-12 15:58:33 +010020 .ops = &clk_regmap_gate_ops, \
Neil Armstrongf8c11f72016-08-18 12:08:46 +020021 .parent_names = (const char *[]){ "clk81" }, \
22 .num_parents = 1, \
Yixun Lan24a2e672018-05-03 21:26:24 +080023 .flags = CLK_IGNORE_UNUSED, \
Neil Armstrongf8c11f72016-08-18 12:08:46 +020024 }, \
25}
26
27GXBB_AO_GATE(remote, 0);
28GXBB_AO_GATE(i2c_master, 1);
29GXBB_AO_GATE(i2c_slave, 2);
30GXBB_AO_GATE(uart1, 3);
31GXBB_AO_GATE(uart2, 5);
32GXBB_AO_GATE(ir_blaster, 6);
33
Neil Armstrong62ec0b92017-08-01 13:56:59 +020034static struct aoclk_cec_32k cec_32k_ao = {
Neil Armstrong62ec0b92017-08-01 13:56:59 +020035 .hw.init = &(struct clk_init_data) {
36 .name = "cec_32k_ao",
37 .ops = &meson_aoclk_cec_32k_ops,
38 .parent_names = (const char *[]){ "xtal" },
39 .num_parents = 1,
40 .flags = CLK_IGNORE_UNUSED,
41 },
42};
43
Yixun Lan88e2da82018-05-03 21:26:20 +080044static const unsigned int gxbb_aoclk_reset[] = {
Neil Armstrongf8c11f72016-08-18 12:08:46 +020045 [RESET_AO_REMOTE] = 16,
46 [RESET_AO_I2C_MASTER] = 18,
47 [RESET_AO_I2C_SLAVE] = 19,
48 [RESET_AO_UART1] = 17,
49 [RESET_AO_UART2] = 22,
50 [RESET_AO_IR_BLASTER] = 23,
51};
52
Jerome Brunet81c7fca2018-02-12 15:58:33 +010053static struct clk_regmap *gxbb_aoclk_gate[] = {
Neil Armstrongf8c11f72016-08-18 12:08:46 +020054 [CLKID_AO_REMOTE] = &remote_ao,
55 [CLKID_AO_I2C_MASTER] = &i2c_master_ao,
56 [CLKID_AO_I2C_SLAVE] = &i2c_slave_ao,
57 [CLKID_AO_UART1] = &uart1_ao,
58 [CLKID_AO_UART2] = &uart2_ao,
59 [CLKID_AO_IR_BLASTER] = &ir_blaster_ao,
60};
61
Yixun Lan88e2da82018-05-03 21:26:20 +080062static const struct clk_hw_onecell_data gxbb_aoclk_onecell_data = {
Neil Armstrongf8c11f72016-08-18 12:08:46 +020063 .hws = {
64 [CLKID_AO_REMOTE] = &remote_ao.hw,
65 [CLKID_AO_I2C_MASTER] = &i2c_master_ao.hw,
66 [CLKID_AO_I2C_SLAVE] = &i2c_slave_ao.hw,
67 [CLKID_AO_UART1] = &uart1_ao.hw,
68 [CLKID_AO_UART2] = &uart2_ao.hw,
69 [CLKID_AO_IR_BLASTER] = &ir_blaster_ao.hw,
Neil Armstrong62ec0b92017-08-01 13:56:59 +020070 [CLKID_AO_CEC_32K] = &cec_32k_ao.hw,
Neil Armstrongf8c11f72016-08-18 12:08:46 +020071 },
Yixun Lan88e2da82018-05-03 21:26:20 +080072 .num = NR_CLKS,
Neil Armstrongf8c11f72016-08-18 12:08:46 +020073};
74
Yixun Lan88e2da82018-05-03 21:26:20 +080075static int gxbb_register_cec_ao_32k(struct platform_device *pdev)
Neil Armstrongf8c11f72016-08-18 12:08:46 +020076{
Neil Armstrongffb13e32017-08-01 13:56:57 +020077 struct device *dev = &pdev->dev;
78 struct regmap *regmap;
Yixun Lan88e2da82018-05-03 21:26:20 +080079 int ret;
Neil Armstrongf8c11f72016-08-18 12:08:46 +020080
Neil Armstrongffb13e32017-08-01 13:56:57 +020081 regmap = syscon_node_to_regmap(of_get_parent(dev->of_node));
82 if (IS_ERR(regmap)) {
83 dev_err(dev, "failed to get regmap\n");
Yixun Lan88e2da82018-05-03 21:26:20 +080084 return PTR_ERR(regmap);
Neil Armstrongf8c11f72016-08-18 12:08:46 +020085 }
86
Neil Armstrong62ec0b92017-08-01 13:56:59 +020087 /* Specific clocks */
88 cec_32k_ao.regmap = regmap;
89 ret = devm_clk_hw_register(dev, &cec_32k_ao.hw);
Yixun Lan88e2da82018-05-03 21:26:20 +080090 if (ret) {
91 dev_err(&pdev->dev, "clk cec_32k_ao register failed.\n");
92 return ret;
93 }
94
95 return 0;
96}
97
98static const struct meson_aoclk_data gxbb_aoclkc_data = {
99 .reset_reg = AO_RTI_GEN_CNTL_REG0,
100 .num_reset = ARRAY_SIZE(gxbb_aoclk_reset),
101 .reset = gxbb_aoclk_reset,
102 .num_clks = ARRAY_SIZE(gxbb_aoclk_gate),
103 .clks = gxbb_aoclk_gate,
104 .hw_data = &gxbb_aoclk_onecell_data,
105};
106
107static int gxbb_aoclkc_probe(struct platform_device *pdev)
108{
109 int ret = gxbb_register_cec_ao_32k(pdev);
Neil Armstrong62ec0b92017-08-01 13:56:59 +0200110 if (ret)
111 return ret;
112
Yixun Lan88e2da82018-05-03 21:26:20 +0800113 return meson_aoclkc_probe(pdev);
Neil Armstrongf8c11f72016-08-18 12:08:46 +0200114}
115
116static const struct of_device_id gxbb_aoclkc_match_table[] = {
Yixun Lan88e2da82018-05-03 21:26:20 +0800117 {
118 .compatible = "amlogic,meson-gx-aoclkc",
119 .data = &gxbb_aoclkc_data,
120 },
Neil Armstrongf8c11f72016-08-18 12:08:46 +0200121 { }
122};
123
124static struct platform_driver gxbb_aoclkc_driver = {
125 .probe = gxbb_aoclkc_probe,
126 .driver = {
127 .name = "gxbb-aoclkc",
128 .of_match_table = gxbb_aoclkc_match_table,
129 },
130};
131builtin_platform_driver(gxbb_aoclkc_driver);