Akshu Agrawal | 421bf6a | 2018-05-09 17:59:00 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: MIT |
| 2 | /* |
Ajit Kumar Pandey | 65ab884 | 2021-12-12 23:35:23 +0530 | [diff] [blame] | 3 | * clock framework for AMD FCH controller block |
Akshu Agrawal | 421bf6a | 2018-05-09 17:59:00 +0800 | [diff] [blame] | 4 | * |
| 5 | * Copyright 2018 Advanced Micro Devices, Inc. |
| 6 | */ |
| 7 | |
| 8 | #include <linux/clk.h> |
| 9 | #include <linux/clkdev.h> |
| 10 | #include <linux/clk-provider.h> |
Ajit Kumar Pandey | 65ab884 | 2021-12-12 23:35:23 +0530 | [diff] [blame] | 11 | #include <linux/pci.h> |
Akshu Agrawal | d58669b | 2020-07-31 19:06:01 +0530 | [diff] [blame] | 12 | #include <linux/platform_data/clk-fch.h> |
Akshu Agrawal | 421bf6a | 2018-05-09 17:59:00 +0800 | [diff] [blame] | 13 | #include <linux/platform_device.h> |
| 14 | |
| 15 | /* Clock Driving Strength 2 register */ |
| 16 | #define CLKDRVSTR2 0x28 |
| 17 | /* Clock Control 1 register */ |
| 18 | #define MISCCLKCNTL1 0x40 |
| 19 | /* Auxiliary clock1 enable bit */ |
| 20 | #define OSCCLKENB 2 |
| 21 | /* 25Mhz auxiliary output clock freq bit */ |
| 22 | #define OSCOUT1CLK25MHZ 16 |
| 23 | |
| 24 | #define ST_CLK_48M 0 |
| 25 | #define ST_CLK_25M 1 |
| 26 | #define ST_CLK_MUX 2 |
| 27 | #define ST_CLK_GATE 3 |
| 28 | #define ST_MAX_CLKS 4 |
| 29 | |
Ajit Kumar Pandey | 65ab884 | 2021-12-12 23:35:23 +0530 | [diff] [blame] | 30 | #define CLK_48M_FIXED 0 |
| 31 | #define CLK_GATE_FIXED 1 |
| 32 | #define CLK_MAX_FIXED 2 |
| 33 | |
| 34 | /* List of supported CPU ids for clk mux with 25Mhz clk support */ |
| 35 | #define AMD_CPU_ID_ST 0x1576 |
Akshu Agrawal | 19fe87f | 2020-07-31 19:06:04 +0530 | [diff] [blame] | 36 | |
Akshu Agrawal | 421bf6a | 2018-05-09 17:59:00 +0800 | [diff] [blame] | 37 | static const char * const clk_oscout1_parents[] = { "clk48MHz", "clk25MHz" }; |
| 38 | static struct clk_hw *hws[ST_MAX_CLKS]; |
| 39 | |
Ajit Kumar Pandey | 65ab884 | 2021-12-12 23:35:23 +0530 | [diff] [blame] | 40 | static const struct pci_device_id fch_pci_ids[] = { |
| 41 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, AMD_CPU_ID_ST) }, |
| 42 | { } |
| 43 | }; |
| 44 | |
Akshu Agrawal | d9b7736 | 2020-07-31 19:06:02 +0530 | [diff] [blame] | 45 | static int fch_clk_probe(struct platform_device *pdev) |
Akshu Agrawal | 421bf6a | 2018-05-09 17:59:00 +0800 | [diff] [blame] | 46 | { |
Akshu Agrawal | d9b7736 | 2020-07-31 19:06:02 +0530 | [diff] [blame] | 47 | struct fch_clk_data *fch_data; |
Ajit Kumar Pandey | 65ab884 | 2021-12-12 23:35:23 +0530 | [diff] [blame] | 48 | struct pci_dev *rdev; |
Akshu Agrawal | 421bf6a | 2018-05-09 17:59:00 +0800 | [diff] [blame] | 49 | |
Akshu Agrawal | d9b7736 | 2020-07-31 19:06:02 +0530 | [diff] [blame] | 50 | fch_data = dev_get_platdata(&pdev->dev); |
| 51 | if (!fch_data || !fch_data->base) |
Akshu Agrawal | 421bf6a | 2018-05-09 17:59:00 +0800 | [diff] [blame] | 52 | return -EINVAL; |
| 53 | |
Ajit Kumar Pandey | 65ab884 | 2021-12-12 23:35:23 +0530 | [diff] [blame] | 54 | rdev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(0, 0)); |
| 55 | if (!rdev) { |
| 56 | dev_err(&pdev->dev, "FCH device not found\n"); |
| 57 | return -ENODEV; |
| 58 | } |
| 59 | |
| 60 | if (pci_match_id(fch_pci_ids, rdev)) { |
Akshu Agrawal | 19fe87f | 2020-07-31 19:06:04 +0530 | [diff] [blame] | 61 | hws[ST_CLK_48M] = clk_hw_register_fixed_rate(NULL, "clk48MHz", |
| 62 | NULL, 0, 48000000); |
| 63 | hws[ST_CLK_25M] = clk_hw_register_fixed_rate(NULL, "clk25MHz", |
| 64 | NULL, 0, 25000000); |
Akshu Agrawal | 421bf6a | 2018-05-09 17:59:00 +0800 | [diff] [blame] | 65 | |
Akshu Agrawal | 19fe87f | 2020-07-31 19:06:04 +0530 | [diff] [blame] | 66 | hws[ST_CLK_MUX] = clk_hw_register_mux(NULL, "oscout1_mux", |
| 67 | clk_oscout1_parents, ARRAY_SIZE(clk_oscout1_parents), |
| 68 | 0, fch_data->base + CLKDRVSTR2, OSCOUT1CLK25MHZ, 3, 0, |
| 69 | NULL); |
Akshu Agrawal | 421bf6a | 2018-05-09 17:59:00 +0800 | [diff] [blame] | 70 | |
Akshu Agrawal | 19fe87f | 2020-07-31 19:06:04 +0530 | [diff] [blame] | 71 | clk_set_parent(hws[ST_CLK_MUX]->clk, hws[ST_CLK_48M]->clk); |
Akshu Agrawal | 421bf6a | 2018-05-09 17:59:00 +0800 | [diff] [blame] | 72 | |
Akshu Agrawal | 19fe87f | 2020-07-31 19:06:04 +0530 | [diff] [blame] | 73 | hws[ST_CLK_GATE] = clk_hw_register_gate(NULL, "oscout1", |
| 74 | "oscout1_mux", 0, fch_data->base + MISCCLKCNTL1, |
| 75 | OSCCLKENB, CLK_GATE_SET_TO_DISABLE, NULL); |
Akshu Agrawal | 421bf6a | 2018-05-09 17:59:00 +0800 | [diff] [blame] | 76 | |
Akshu Agrawal | 19fe87f | 2020-07-31 19:06:04 +0530 | [diff] [blame] | 77 | devm_clk_hw_register_clkdev(&pdev->dev, hws[ST_CLK_GATE], |
Ajit Kumar Pandey | c33917b | 2021-12-12 23:35:26 +0530 | [diff] [blame] | 78 | fch_data->name, NULL); |
Akshu Agrawal | 19fe87f | 2020-07-31 19:06:04 +0530 | [diff] [blame] | 79 | } else { |
Ajit Kumar Pandey | 65ab884 | 2021-12-12 23:35:23 +0530 | [diff] [blame] | 80 | hws[CLK_48M_FIXED] = clk_hw_register_fixed_rate(NULL, "clk48MHz", |
Akshu Agrawal | 19fe87f | 2020-07-31 19:06:04 +0530 | [diff] [blame] | 81 | NULL, 0, 48000000); |
| 82 | |
Ajit Kumar Pandey | 65ab884 | 2021-12-12 23:35:23 +0530 | [diff] [blame] | 83 | hws[CLK_GATE_FIXED] = clk_hw_register_gate(NULL, "oscout1", |
Akshu Agrawal | 19fe87f | 2020-07-31 19:06:04 +0530 | [diff] [blame] | 84 | "clk48MHz", 0, fch_data->base + MISCCLKCNTL1, |
Ajit Kumar Pandey | 1fdaaa1 | 2021-12-12 23:35:27 +0530 | [diff] [blame] | 85 | OSCCLKENB, 0, NULL); |
Akshu Agrawal | 19fe87f | 2020-07-31 19:06:04 +0530 | [diff] [blame] | 86 | |
Ajit Kumar Pandey | 65ab884 | 2021-12-12 23:35:23 +0530 | [diff] [blame] | 87 | devm_clk_hw_register_clkdev(&pdev->dev, hws[CLK_GATE_FIXED], |
Ajit Kumar Pandey | c33917b | 2021-12-12 23:35:26 +0530 | [diff] [blame] | 88 | fch_data->name, NULL); |
Akshu Agrawal | 19fe87f | 2020-07-31 19:06:04 +0530 | [diff] [blame] | 89 | } |
Akshu Agrawal | 421bf6a | 2018-05-09 17:59:00 +0800 | [diff] [blame] | 90 | |
Ajit Kumar Pandey | 65ab884 | 2021-12-12 23:35:23 +0530 | [diff] [blame] | 91 | pci_dev_put(rdev); |
Akshu Agrawal | 421bf6a | 2018-05-09 17:59:00 +0800 | [diff] [blame] | 92 | return 0; |
| 93 | } |
| 94 | |
Akshu Agrawal | d9b7736 | 2020-07-31 19:06:02 +0530 | [diff] [blame] | 95 | static int fch_clk_remove(struct platform_device *pdev) |
Akshu Agrawal | 421bf6a | 2018-05-09 17:59:00 +0800 | [diff] [blame] | 96 | { |
Akshu Agrawal | 19fe87f | 2020-07-31 19:06:04 +0530 | [diff] [blame] | 97 | int i, clks; |
Ajit Kumar Pandey | 65ab884 | 2021-12-12 23:35:23 +0530 | [diff] [blame] | 98 | struct pci_dev *rdev; |
Akshu Agrawal | 421bf6a | 2018-05-09 17:59:00 +0800 | [diff] [blame] | 99 | |
Ajit Kumar Pandey | 65ab884 | 2021-12-12 23:35:23 +0530 | [diff] [blame] | 100 | rdev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(0, 0)); |
| 101 | if (!rdev) |
| 102 | return -ENODEV; |
Akshu Agrawal | 19fe87f | 2020-07-31 19:06:04 +0530 | [diff] [blame] | 103 | |
Ajit Kumar Pandey | 65ab884 | 2021-12-12 23:35:23 +0530 | [diff] [blame] | 104 | clks = pci_match_id(fch_pci_ids, rdev) ? CLK_MAX_FIXED : ST_MAX_CLKS; |
Akshu Agrawal | 19fe87f | 2020-07-31 19:06:04 +0530 | [diff] [blame] | 105 | |
| 106 | for (i = 0; i < clks; i++) |
Akshu Agrawal | 421bf6a | 2018-05-09 17:59:00 +0800 | [diff] [blame] | 107 | clk_hw_unregister(hws[i]); |
Akshu Agrawal | 19fe87f | 2020-07-31 19:06:04 +0530 | [diff] [blame] | 108 | |
Ajit Kumar Pandey | 65ab884 | 2021-12-12 23:35:23 +0530 | [diff] [blame] | 109 | pci_dev_put(rdev); |
Akshu Agrawal | 421bf6a | 2018-05-09 17:59:00 +0800 | [diff] [blame] | 110 | return 0; |
| 111 | } |
| 112 | |
Akshu Agrawal | d9b7736 | 2020-07-31 19:06:02 +0530 | [diff] [blame] | 113 | static struct platform_driver fch_clk_driver = { |
Akshu Agrawal | 421bf6a | 2018-05-09 17:59:00 +0800 | [diff] [blame] | 114 | .driver = { |
Akshu Agrawal | d9b7736 | 2020-07-31 19:06:02 +0530 | [diff] [blame] | 115 | .name = "clk-fch", |
Akshu Agrawal | 421bf6a | 2018-05-09 17:59:00 +0800 | [diff] [blame] | 116 | .suppress_bind_attrs = true, |
| 117 | }, |
Akshu Agrawal | d9b7736 | 2020-07-31 19:06:02 +0530 | [diff] [blame] | 118 | .probe = fch_clk_probe, |
| 119 | .remove = fch_clk_remove, |
Akshu Agrawal | 421bf6a | 2018-05-09 17:59:00 +0800 | [diff] [blame] | 120 | }; |
Akshu Agrawal | d9b7736 | 2020-07-31 19:06:02 +0530 | [diff] [blame] | 121 | builtin_platform_driver(fch_clk_driver); |