18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: MIT 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * clock framework for AMD Stoney based clocks 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright 2018 Advanced Micro Devices, Inc. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <linux/clk.h> 98c2ecf20Sopenharmony_ci#include <linux/clkdev.h> 108c2ecf20Sopenharmony_ci#include <linux/clk-provider.h> 118c2ecf20Sopenharmony_ci#include <linux/platform_data/clk-fch.h> 128c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci/* Clock Driving Strength 2 register */ 158c2ecf20Sopenharmony_ci#define CLKDRVSTR2 0x28 168c2ecf20Sopenharmony_ci/* Clock Control 1 register */ 178c2ecf20Sopenharmony_ci#define MISCCLKCNTL1 0x40 188c2ecf20Sopenharmony_ci/* Auxiliary clock1 enable bit */ 198c2ecf20Sopenharmony_ci#define OSCCLKENB 2 208c2ecf20Sopenharmony_ci/* 25Mhz auxiliary output clock freq bit */ 218c2ecf20Sopenharmony_ci#define OSCOUT1CLK25MHZ 16 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define ST_CLK_48M 0 248c2ecf20Sopenharmony_ci#define ST_CLK_25M 1 258c2ecf20Sopenharmony_ci#define ST_CLK_MUX 2 268c2ecf20Sopenharmony_ci#define ST_CLK_GATE 3 278c2ecf20Sopenharmony_ci#define ST_MAX_CLKS 4 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci#define RV_CLK_48M 0 308c2ecf20Sopenharmony_ci#define RV_CLK_GATE 1 318c2ecf20Sopenharmony_ci#define RV_MAX_CLKS 2 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_cistatic const char * const clk_oscout1_parents[] = { "clk48MHz", "clk25MHz" }; 348c2ecf20Sopenharmony_cistatic struct clk_hw *hws[ST_MAX_CLKS]; 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_cistatic int fch_clk_probe(struct platform_device *pdev) 378c2ecf20Sopenharmony_ci{ 388c2ecf20Sopenharmony_ci struct fch_clk_data *fch_data; 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci fch_data = dev_get_platdata(&pdev->dev); 418c2ecf20Sopenharmony_ci if (!fch_data || !fch_data->base) 428c2ecf20Sopenharmony_ci return -EINVAL; 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci if (!fch_data->is_rv) { 458c2ecf20Sopenharmony_ci hws[ST_CLK_48M] = clk_hw_register_fixed_rate(NULL, "clk48MHz", 468c2ecf20Sopenharmony_ci NULL, 0, 48000000); 478c2ecf20Sopenharmony_ci hws[ST_CLK_25M] = clk_hw_register_fixed_rate(NULL, "clk25MHz", 488c2ecf20Sopenharmony_ci NULL, 0, 25000000); 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci hws[ST_CLK_MUX] = clk_hw_register_mux(NULL, "oscout1_mux", 518c2ecf20Sopenharmony_ci clk_oscout1_parents, ARRAY_SIZE(clk_oscout1_parents), 528c2ecf20Sopenharmony_ci 0, fch_data->base + CLKDRVSTR2, OSCOUT1CLK25MHZ, 3, 0, 538c2ecf20Sopenharmony_ci NULL); 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci clk_set_parent(hws[ST_CLK_MUX]->clk, hws[ST_CLK_48M]->clk); 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci hws[ST_CLK_GATE] = clk_hw_register_gate(NULL, "oscout1", 588c2ecf20Sopenharmony_ci "oscout1_mux", 0, fch_data->base + MISCCLKCNTL1, 598c2ecf20Sopenharmony_ci OSCCLKENB, CLK_GATE_SET_TO_DISABLE, NULL); 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci devm_clk_hw_register_clkdev(&pdev->dev, hws[ST_CLK_GATE], 628c2ecf20Sopenharmony_ci "oscout1", NULL); 638c2ecf20Sopenharmony_ci } else { 648c2ecf20Sopenharmony_ci hws[RV_CLK_48M] = clk_hw_register_fixed_rate(NULL, "clk48MHz", 658c2ecf20Sopenharmony_ci NULL, 0, 48000000); 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci hws[RV_CLK_GATE] = clk_hw_register_gate(NULL, "oscout1", 688c2ecf20Sopenharmony_ci "clk48MHz", 0, fch_data->base + MISCCLKCNTL1, 698c2ecf20Sopenharmony_ci OSCCLKENB, CLK_GATE_SET_TO_DISABLE, NULL); 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci devm_clk_hw_register_clkdev(&pdev->dev, hws[RV_CLK_GATE], 728c2ecf20Sopenharmony_ci "oscout1", NULL); 738c2ecf20Sopenharmony_ci } 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci return 0; 768c2ecf20Sopenharmony_ci} 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_cistatic int fch_clk_remove(struct platform_device *pdev) 798c2ecf20Sopenharmony_ci{ 808c2ecf20Sopenharmony_ci int i, clks; 818c2ecf20Sopenharmony_ci struct fch_clk_data *fch_data; 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci fch_data = dev_get_platdata(&pdev->dev); 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci clks = fch_data->is_rv ? RV_MAX_CLKS : ST_MAX_CLKS; 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci for (i = 0; i < clks; i++) 888c2ecf20Sopenharmony_ci clk_hw_unregister(hws[i]); 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci return 0; 918c2ecf20Sopenharmony_ci} 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_cistatic struct platform_driver fch_clk_driver = { 948c2ecf20Sopenharmony_ci .driver = { 958c2ecf20Sopenharmony_ci .name = "clk-fch", 968c2ecf20Sopenharmony_ci .suppress_bind_attrs = true, 978c2ecf20Sopenharmony_ci }, 988c2ecf20Sopenharmony_ci .probe = fch_clk_probe, 998c2ecf20Sopenharmony_ci .remove = fch_clk_remove, 1008c2ecf20Sopenharmony_ci}; 1018c2ecf20Sopenharmony_cibuiltin_platform_driver(fch_clk_driver); 102