Jerome Brunet | 22f65a3 | 2018-05-16 10:50:40 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 2 | /* |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 3 | * Copyright (c) 2016 BayLibre, SAS. |
| 4 | * Author: Neil Armstrong <narmstrong@baylibre.com> |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 5 | */ |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 6 | #include <linux/platform_device.h> |
Neil Armstrong | ffb13e3 | 2017-08-01 13:56:57 +0200 | [diff] [blame] | 7 | #include <linux/mfd/syscon.h> |
Jerome Brunet | 81c7fca | 2018-02-12 15:58:33 +0100 | [diff] [blame] | 8 | #include "clk-regmap.h" |
Yixun Lan | 88e2da8 | 2018-05-03 21:26:20 +0800 | [diff] [blame] | 9 | #include "meson-aoclk.h" |
Neil Armstrong | ffb13e3 | 2017-08-01 13:56:57 +0200 | [diff] [blame] | 10 | #include "gxbb-aoclk.h" |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 11 | |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 12 | #define GXBB_AO_GATE(_name, _bit) \ |
Jerome Brunet | 81c7fca | 2018-02-12 15:58:33 +0100 | [diff] [blame] | 13 | static 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 Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 18 | .hw.init = &(struct clk_init_data) { \ |
| 19 | .name = #_name "_ao", \ |
Jerome Brunet | 81c7fca | 2018-02-12 15:58:33 +0100 | [diff] [blame] | 20 | .ops = &clk_regmap_gate_ops, \ |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 21 | .parent_names = (const char *[]){ "clk81" }, \ |
| 22 | .num_parents = 1, \ |
Yixun Lan | 24a2e67 | 2018-05-03 21:26:24 +0800 | [diff] [blame] | 23 | .flags = CLK_IGNORE_UNUSED, \ |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 24 | }, \ |
| 25 | } |
| 26 | |
| 27 | GXBB_AO_GATE(remote, 0); |
| 28 | GXBB_AO_GATE(i2c_master, 1); |
| 29 | GXBB_AO_GATE(i2c_slave, 2); |
| 30 | GXBB_AO_GATE(uart1, 3); |
| 31 | GXBB_AO_GATE(uart2, 5); |
| 32 | GXBB_AO_GATE(ir_blaster, 6); |
| 33 | |
Neil Armstrong | 62ec0b9 | 2017-08-01 13:56:59 +0200 | [diff] [blame] | 34 | static struct aoclk_cec_32k cec_32k_ao = { |
Neil Armstrong | 62ec0b9 | 2017-08-01 13:56:59 +0200 | [diff] [blame] | 35 | .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 Lan | 88e2da8 | 2018-05-03 21:26:20 +0800 | [diff] [blame] | 44 | static const unsigned int gxbb_aoclk_reset[] = { |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 45 | [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 Brunet | 81c7fca | 2018-02-12 15:58:33 +0100 | [diff] [blame] | 53 | static struct clk_regmap *gxbb_aoclk_gate[] = { |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 54 | [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 Lan | 88e2da8 | 2018-05-03 21:26:20 +0800 | [diff] [blame] | 62 | static const struct clk_hw_onecell_data gxbb_aoclk_onecell_data = { |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 63 | .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 Armstrong | 62ec0b9 | 2017-08-01 13:56:59 +0200 | [diff] [blame] | 70 | [CLKID_AO_CEC_32K] = &cec_32k_ao.hw, |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 71 | }, |
Yixun Lan | 88e2da8 | 2018-05-03 21:26:20 +0800 | [diff] [blame] | 72 | .num = NR_CLKS, |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 73 | }; |
| 74 | |
Yixun Lan | 88e2da8 | 2018-05-03 21:26:20 +0800 | [diff] [blame] | 75 | static int gxbb_register_cec_ao_32k(struct platform_device *pdev) |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 76 | { |
Neil Armstrong | ffb13e3 | 2017-08-01 13:56:57 +0200 | [diff] [blame] | 77 | struct device *dev = &pdev->dev; |
| 78 | struct regmap *regmap; |
Yixun Lan | 88e2da8 | 2018-05-03 21:26:20 +0800 | [diff] [blame] | 79 | int ret; |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 80 | |
Neil Armstrong | ffb13e3 | 2017-08-01 13:56:57 +0200 | [diff] [blame] | 81 | 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 Lan | 88e2da8 | 2018-05-03 21:26:20 +0800 | [diff] [blame] | 84 | return PTR_ERR(regmap); |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 85 | } |
| 86 | |
Neil Armstrong | 62ec0b9 | 2017-08-01 13:56:59 +0200 | [diff] [blame] | 87 | /* Specific clocks */ |
| 88 | cec_32k_ao.regmap = regmap; |
| 89 | ret = devm_clk_hw_register(dev, &cec_32k_ao.hw); |
Yixun Lan | 88e2da8 | 2018-05-03 21:26:20 +0800 | [diff] [blame] | 90 | if (ret) { |
| 91 | dev_err(&pdev->dev, "clk cec_32k_ao register failed.\n"); |
| 92 | return ret; |
| 93 | } |
| 94 | |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | static 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 | |
| 107 | static int gxbb_aoclkc_probe(struct platform_device *pdev) |
| 108 | { |
| 109 | int ret = gxbb_register_cec_ao_32k(pdev); |
Neil Armstrong | 62ec0b9 | 2017-08-01 13:56:59 +0200 | [diff] [blame] | 110 | if (ret) |
| 111 | return ret; |
| 112 | |
Yixun Lan | 88e2da8 | 2018-05-03 21:26:20 +0800 | [diff] [blame] | 113 | return meson_aoclkc_probe(pdev); |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | static const struct of_device_id gxbb_aoclkc_match_table[] = { |
Yixun Lan | 88e2da8 | 2018-05-03 21:26:20 +0800 | [diff] [blame] | 117 | { |
| 118 | .compatible = "amlogic,meson-gx-aoclkc", |
| 119 | .data = &gxbb_aoclkc_data, |
| 120 | }, |
Neil Armstrong | f8c11f7 | 2016-08-18 12:08:46 +0200 | [diff] [blame] | 121 | { } |
| 122 | }; |
| 123 | |
| 124 | static 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 | }; |
| 131 | builtin_platform_driver(gxbb_aoclkc_driver); |