Lines Matching +full:ast2500 +full:- +full:scu
1 // SPDX-License-Identifier: GPL-2.0-or-later
17 #include <linux/aspeed-lpc-ctrl.h>
19 #define DEVICE_NAME "aspeed-lpc-ctrl"
40 struct regmap *scu; member
45 return container_of(file->private_data, struct aspeed_lpc_ctrl, in file_aspeed_lpc_ctrl()
52 unsigned long vsize = vma->vm_end - vma->vm_start; in aspeed_lpc_ctrl_mmap()
53 pgprot_t prot = vma->vm_page_prot; in aspeed_lpc_ctrl_mmap()
55 if (vma->vm_pgoff + vma_pages(vma) > lpc_ctrl->mem_size >> PAGE_SHIFT) in aspeed_lpc_ctrl_mmap()
56 return -EINVAL; in aspeed_lpc_ctrl_mmap()
61 if (remap_pfn_range(vma, vma->vm_start, in aspeed_lpc_ctrl_mmap()
62 (lpc_ctrl->mem_base >> PAGE_SHIFT) + vma->vm_pgoff, in aspeed_lpc_ctrl_mmap()
64 return -EAGAIN; in aspeed_lpc_ctrl_mmap()
73 struct device *dev = file->private_data; in aspeed_lpc_ctrl_ioctl()
81 return -EFAULT; in aspeed_lpc_ctrl_ioctl()
84 return -EINVAL; in aspeed_lpc_ctrl_ioctl()
90 return -EINVAL; in aspeed_lpc_ctrl_ioctl()
94 return -EINVAL; in aspeed_lpc_ctrl_ioctl()
96 /* If memory-region is not described in device tree */ in aspeed_lpc_ctrl_ioctl()
97 if (!lpc_ctrl->mem_size) { in aspeed_lpc_ctrl_ioctl()
99 return -ENXIO; in aspeed_lpc_ctrl_ioctl()
102 map.size = lpc_ctrl->mem_size; in aspeed_lpc_ctrl_ioctl()
104 return copy_to_user(p, &map, sizeof(map)) ? -EFAULT : 0; in aspeed_lpc_ctrl_ioctl()
128 return -EINVAL; in aspeed_lpc_ctrl_ioctl()
134 if (map.offset & (map.size - 1)) in aspeed_lpc_ctrl_ioctl()
135 return -EINVAL; in aspeed_lpc_ctrl_ioctl()
138 if (!lpc_ctrl->pnor_size) { in aspeed_lpc_ctrl_ioctl()
140 return -ENXIO; in aspeed_lpc_ctrl_ioctl()
142 addr = lpc_ctrl->pnor_base; in aspeed_lpc_ctrl_ioctl()
143 size = lpc_ctrl->pnor_size; in aspeed_lpc_ctrl_ioctl()
145 /* If memory-region is not described in device tree */ in aspeed_lpc_ctrl_ioctl()
146 if (!lpc_ctrl->mem_size) { in aspeed_lpc_ctrl_ioctl()
148 return -ENXIO; in aspeed_lpc_ctrl_ioctl()
150 addr = lpc_ctrl->mem_base; in aspeed_lpc_ctrl_ioctl()
151 size = lpc_ctrl->mem_size; in aspeed_lpc_ctrl_ioctl()
153 return -EINVAL; in aspeed_lpc_ctrl_ioctl()
159 return -EINVAL; in aspeed_lpc_ctrl_ioctl()
162 return -EINVAL; in aspeed_lpc_ctrl_ioctl()
175 rc = regmap_write(lpc_ctrl->regmap, HICR7, in aspeed_lpc_ctrl_ioctl()
180 rc = regmap_write(lpc_ctrl->regmap, HICR8, in aspeed_lpc_ctrl_ioctl()
181 (~(map.size - 1)) | ((map.size >> 16) - 1)); in aspeed_lpc_ctrl_ioctl()
188 if (lpc_ctrl->fwh2ahb) { in aspeed_lpc_ctrl_ioctl()
190 * Enable FWH2AHB in SCU debug control register 2. This in aspeed_lpc_ctrl_ioctl()
194 regmap_update_bits(lpc_ctrl->scu, 0x0D8, BIT(2), 0); in aspeed_lpc_ctrl_ioctl()
201 regmap_write(lpc_ctrl->regmap, HICR6, SW_FWH2AHB); in aspeed_lpc_ctrl_ioctl()
208 return regmap_update_bits(lpc_ctrl->regmap, HICR5, in aspeed_lpc_ctrl_ioctl()
213 return -EINVAL; in aspeed_lpc_ctrl_ioctl()
231 dev = &pdev->dev; in aspeed_lpc_ctrl_probe()
235 return -ENOMEM; in aspeed_lpc_ctrl_probe()
238 node = of_parse_phandle(dev->of_node, "flash", 0); in aspeed_lpc_ctrl_probe()
249 lpc_ctrl->pnor_size = resource_size(&resm); in aspeed_lpc_ctrl_probe()
250 lpc_ctrl->pnor_base = resm.start; in aspeed_lpc_ctrl_probe()
254 dev_set_drvdata(&pdev->dev, lpc_ctrl); in aspeed_lpc_ctrl_probe()
256 /* If memory-region is described in device tree then store */ in aspeed_lpc_ctrl_probe()
257 node = of_parse_phandle(dev->of_node, "memory-region", 0); in aspeed_lpc_ctrl_probe()
265 return -ENXIO; in aspeed_lpc_ctrl_probe()
268 lpc_ctrl->mem_size = resource_size(&resm); in aspeed_lpc_ctrl_probe()
269 lpc_ctrl->mem_base = resm.start; in aspeed_lpc_ctrl_probe()
271 if (!is_power_of_2(lpc_ctrl->mem_size)) { in aspeed_lpc_ctrl_probe()
273 (unsigned int)lpc_ctrl->mem_size); in aspeed_lpc_ctrl_probe()
274 return -EINVAL; in aspeed_lpc_ctrl_probe()
277 if (!IS_ALIGNED(lpc_ctrl->mem_base, lpc_ctrl->mem_size)) { in aspeed_lpc_ctrl_probe()
279 (unsigned int)lpc_ctrl->mem_size); in aspeed_lpc_ctrl_probe()
280 return -EINVAL; in aspeed_lpc_ctrl_probe()
284 np = pdev->dev.parent->of_node; in aspeed_lpc_ctrl_probe()
285 if (!of_device_is_compatible(np, "aspeed,ast2400-lpc-v2") && in aspeed_lpc_ctrl_probe()
286 !of_device_is_compatible(np, "aspeed,ast2500-lpc-v2") && in aspeed_lpc_ctrl_probe()
287 !of_device_is_compatible(np, "aspeed,ast2600-lpc-v2")) { in aspeed_lpc_ctrl_probe()
289 return -ENODEV; in aspeed_lpc_ctrl_probe()
292 lpc_ctrl->regmap = syscon_node_to_regmap(np); in aspeed_lpc_ctrl_probe()
293 if (IS_ERR(lpc_ctrl->regmap)) { in aspeed_lpc_ctrl_probe()
295 return -ENODEV; in aspeed_lpc_ctrl_probe()
298 if (of_device_is_compatible(dev->of_node, "aspeed,ast2600-lpc-ctrl")) { in aspeed_lpc_ctrl_probe()
299 lpc_ctrl->fwh2ahb = true; in aspeed_lpc_ctrl_probe()
301 lpc_ctrl->scu = syscon_regmap_lookup_by_compatible("aspeed,ast2600-scu"); in aspeed_lpc_ctrl_probe()
302 if (IS_ERR(lpc_ctrl->scu)) { in aspeed_lpc_ctrl_probe()
303 dev_err(dev, "couldn't find scu\n"); in aspeed_lpc_ctrl_probe()
304 return PTR_ERR(lpc_ctrl->scu); in aspeed_lpc_ctrl_probe()
308 lpc_ctrl->clk = devm_clk_get(dev, NULL); in aspeed_lpc_ctrl_probe()
309 if (IS_ERR(lpc_ctrl->clk)) in aspeed_lpc_ctrl_probe()
310 return dev_err_probe(dev, PTR_ERR(lpc_ctrl->clk), in aspeed_lpc_ctrl_probe()
312 rc = clk_prepare_enable(lpc_ctrl->clk); in aspeed_lpc_ctrl_probe()
318 lpc_ctrl->miscdev.minor = MISC_DYNAMIC_MINOR; in aspeed_lpc_ctrl_probe()
319 lpc_ctrl->miscdev.name = DEVICE_NAME; in aspeed_lpc_ctrl_probe()
320 lpc_ctrl->miscdev.fops = &aspeed_lpc_ctrl_fops; in aspeed_lpc_ctrl_probe()
321 lpc_ctrl->miscdev.parent = dev; in aspeed_lpc_ctrl_probe()
322 rc = misc_register(&lpc_ctrl->miscdev); in aspeed_lpc_ctrl_probe()
331 clk_disable_unprepare(lpc_ctrl->clk); in aspeed_lpc_ctrl_probe()
337 struct aspeed_lpc_ctrl *lpc_ctrl = dev_get_drvdata(&pdev->dev); in aspeed_lpc_ctrl_remove()
339 misc_deregister(&lpc_ctrl->miscdev); in aspeed_lpc_ctrl_remove()
340 clk_disable_unprepare(lpc_ctrl->clk); in aspeed_lpc_ctrl_remove()
344 { .compatible = "aspeed,ast2400-lpc-ctrl" },
345 { .compatible = "aspeed,ast2500-lpc-ctrl" },
346 { .compatible = "aspeed,ast2600-lpc-ctrl" },