Lines Matching +full:read +full:- +full:out

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.
20 #include <linux/dma-mapping.h>
53 "maximum read burst (default: ACPI/DT value)");
63 "maximum number of read transactions (default: ACPI/DT value)");
70 if (!is_power_of_2(mgmtdev->max_write_request) || in hidma_mgmt_setup()
71 (mgmtdev->max_write_request < 128) || in hidma_mgmt_setup()
72 (mgmtdev->max_write_request > 1024)) { in hidma_mgmt_setup()
73 dev_err(&mgmtdev->pdev->dev, "invalid write request %d\n", in hidma_mgmt_setup()
74 mgmtdev->max_write_request); in hidma_mgmt_setup()
75 return -EINVAL; in hidma_mgmt_setup()
78 if (!is_power_of_2(mgmtdev->max_read_request) || in hidma_mgmt_setup()
79 (mgmtdev->max_read_request < 128) || in hidma_mgmt_setup()
80 (mgmtdev->max_read_request > 1024)) { in hidma_mgmt_setup()
81 dev_err(&mgmtdev->pdev->dev, "invalid read request %d\n", in hidma_mgmt_setup()
82 mgmtdev->max_read_request); in hidma_mgmt_setup()
83 return -EINVAL; in hidma_mgmt_setup()
86 if (mgmtdev->max_wr_xactions > HIDMA_MAX_WR_XACTIONS_MASK) { in hidma_mgmt_setup()
87 dev_err(&mgmtdev->pdev->dev, in hidma_mgmt_setup()
90 return -EINVAL; in hidma_mgmt_setup()
93 if (mgmtdev->max_rd_xactions > HIDMA_MAX_RD_XACTIONS_MASK) { in hidma_mgmt_setup()
94 dev_err(&mgmtdev->pdev->dev, in hidma_mgmt_setup()
97 return -EINVAL; in hidma_mgmt_setup()
100 for (i = 0; i < mgmtdev->dma_channels; i++) { in hidma_mgmt_setup()
101 if (mgmtdev->priority[i] > 1) { in hidma_mgmt_setup()
102 dev_err(&mgmtdev->pdev->dev, in hidma_mgmt_setup()
104 return -EINVAL; in hidma_mgmt_setup()
107 if (mgmtdev->weight[i] > HIDMA_MAX_CHANNEL_WEIGHT) { in hidma_mgmt_setup()
108 dev_err(&mgmtdev->pdev->dev, in hidma_mgmt_setup()
111 return -EINVAL; in hidma_mgmt_setup()
115 if (mgmtdev->weight[i] == 0) in hidma_mgmt_setup()
116 mgmtdev->weight[i] = 1; in hidma_mgmt_setup()
119 pm_runtime_get_sync(&mgmtdev->pdev->dev); in hidma_mgmt_setup()
120 val = readl(mgmtdev->virtaddr + HIDMA_MAX_BUS_REQ_LEN_OFFSET); in hidma_mgmt_setup()
122 val |= mgmtdev->max_write_request << HIDMA_MAX_BUS_WR_REQ_BIT_POS; in hidma_mgmt_setup()
124 val |= mgmtdev->max_read_request; in hidma_mgmt_setup()
125 writel(val, mgmtdev->virtaddr + HIDMA_MAX_BUS_REQ_LEN_OFFSET); in hidma_mgmt_setup()
127 val = readl(mgmtdev->virtaddr + HIDMA_MAX_XACTIONS_OFFSET); in hidma_mgmt_setup()
129 val |= mgmtdev->max_wr_xactions << HIDMA_MAX_WR_XACTIONS_BIT_POS; in hidma_mgmt_setup()
131 val |= mgmtdev->max_rd_xactions; in hidma_mgmt_setup()
132 writel(val, mgmtdev->virtaddr + HIDMA_MAX_XACTIONS_OFFSET); in hidma_mgmt_setup()
134 mgmtdev->hw_version = in hidma_mgmt_setup()
135 readl(mgmtdev->virtaddr + HIDMA_HW_VERSION_OFFSET); in hidma_mgmt_setup()
136 mgmtdev->hw_version_major = (mgmtdev->hw_version >> 28) & 0xF; in hidma_mgmt_setup()
137 mgmtdev->hw_version_minor = (mgmtdev->hw_version >> 16) & 0xF; in hidma_mgmt_setup()
139 for (i = 0; i < mgmtdev->dma_channels; i++) { in hidma_mgmt_setup()
140 u32 weight = mgmtdev->weight[i]; in hidma_mgmt_setup()
141 u32 priority = mgmtdev->priority[i]; in hidma_mgmt_setup()
143 val = readl(mgmtdev->virtaddr + HIDMA_QOS_N_OFFSET + (4 * i)); in hidma_mgmt_setup()
148 writel(val, mgmtdev->virtaddr + HIDMA_QOS_N_OFFSET + (4 * i)); in hidma_mgmt_setup()
151 val = readl(mgmtdev->virtaddr + HIDMA_CHRESET_TIMEOUT_OFFSET); in hidma_mgmt_setup()
153 val |= mgmtdev->chreset_timeout_cycles & HIDMA_CHRESET_TIMEOUT_MASK; in hidma_mgmt_setup()
154 writel(val, mgmtdev->virtaddr + HIDMA_CHRESET_TIMEOUT_OFFSET); in hidma_mgmt_setup()
156 pm_runtime_mark_last_busy(&mgmtdev->pdev->dev); in hidma_mgmt_setup()
157 pm_runtime_put_autosuspend(&mgmtdev->pdev->dev); in hidma_mgmt_setup()
171 pm_runtime_set_autosuspend_delay(&pdev->dev, HIDMA_AUTOSUSPEND_TIMEOUT); in hidma_mgmt_probe()
172 pm_runtime_use_autosuspend(&pdev->dev); in hidma_mgmt_probe()
173 pm_runtime_set_active(&pdev->dev); in hidma_mgmt_probe()
174 pm_runtime_enable(&pdev->dev); in hidma_mgmt_probe()
175 pm_runtime_get_sync(&pdev->dev); in hidma_mgmt_probe()
178 virtaddr = devm_ioremap_resource(&pdev->dev, res); in hidma_mgmt_probe()
180 rc = -ENOMEM; in hidma_mgmt_probe()
181 goto out; in hidma_mgmt_probe()
187 goto out; in hidma_mgmt_probe()
190 mgmtdev = devm_kzalloc(&pdev->dev, sizeof(*mgmtdev), GFP_KERNEL); in hidma_mgmt_probe()
192 rc = -ENOMEM; in hidma_mgmt_probe()
193 goto out; in hidma_mgmt_probe()
196 mgmtdev->pdev = pdev; in hidma_mgmt_probe()
197 mgmtdev->addrsize = resource_size(res); in hidma_mgmt_probe()
198 mgmtdev->virtaddr = virtaddr; in hidma_mgmt_probe()
200 rc = device_property_read_u32(&pdev->dev, "dma-channels", in hidma_mgmt_probe()
201 &mgmtdev->dma_channels); in hidma_mgmt_probe()
203 dev_err(&pdev->dev, "number of channels missing\n"); in hidma_mgmt_probe()
204 goto out; in hidma_mgmt_probe()
207 rc = device_property_read_u32(&pdev->dev, in hidma_mgmt_probe()
208 "channel-reset-timeout-cycles", in hidma_mgmt_probe()
209 &mgmtdev->chreset_timeout_cycles); in hidma_mgmt_probe()
211 dev_err(&pdev->dev, "channel reset timeout missing\n"); in hidma_mgmt_probe()
212 goto out; in hidma_mgmt_probe()
215 rc = device_property_read_u32(&pdev->dev, "max-write-burst-bytes", in hidma_mgmt_probe()
216 &mgmtdev->max_write_request); in hidma_mgmt_probe()
218 dev_err(&pdev->dev, "max-write-burst-bytes missing\n"); in hidma_mgmt_probe()
219 goto out; in hidma_mgmt_probe()
223 (max_write_request != mgmtdev->max_write_request)) { in hidma_mgmt_probe()
224 dev_info(&pdev->dev, "overriding max-write-burst-bytes: %d\n", in hidma_mgmt_probe()
226 mgmtdev->max_write_request = max_write_request; in hidma_mgmt_probe()
228 max_write_request = mgmtdev->max_write_request; in hidma_mgmt_probe()
230 rc = device_property_read_u32(&pdev->dev, "max-read-burst-bytes", in hidma_mgmt_probe()
231 &mgmtdev->max_read_request); in hidma_mgmt_probe()
233 dev_err(&pdev->dev, "max-read-burst-bytes missing\n"); in hidma_mgmt_probe()
234 goto out; in hidma_mgmt_probe()
237 (max_read_request != mgmtdev->max_read_request)) { in hidma_mgmt_probe()
238 dev_info(&pdev->dev, "overriding max-read-burst-bytes: %d\n", in hidma_mgmt_probe()
240 mgmtdev->max_read_request = max_read_request; in hidma_mgmt_probe()
242 max_read_request = mgmtdev->max_read_request; in hidma_mgmt_probe()
244 rc = device_property_read_u32(&pdev->dev, "max-write-transactions", in hidma_mgmt_probe()
245 &mgmtdev->max_wr_xactions); in hidma_mgmt_probe()
247 dev_err(&pdev->dev, "max-write-transactions missing\n"); in hidma_mgmt_probe()
248 goto out; in hidma_mgmt_probe()
251 (max_wr_xactions != mgmtdev->max_wr_xactions)) { in hidma_mgmt_probe()
252 dev_info(&pdev->dev, "overriding max-write-transactions: %d\n", in hidma_mgmt_probe()
254 mgmtdev->max_wr_xactions = max_wr_xactions; in hidma_mgmt_probe()
256 max_wr_xactions = mgmtdev->max_wr_xactions; in hidma_mgmt_probe()
258 rc = device_property_read_u32(&pdev->dev, "max-read-transactions", in hidma_mgmt_probe()
259 &mgmtdev->max_rd_xactions); in hidma_mgmt_probe()
261 dev_err(&pdev->dev, "max-read-transactions missing\n"); in hidma_mgmt_probe()
262 goto out; in hidma_mgmt_probe()
265 (max_rd_xactions != mgmtdev->max_rd_xactions)) { in hidma_mgmt_probe()
266 dev_info(&pdev->dev, "overriding max-read-transactions: %d\n", in hidma_mgmt_probe()
268 mgmtdev->max_rd_xactions = max_rd_xactions; in hidma_mgmt_probe()
270 max_rd_xactions = mgmtdev->max_rd_xactions; in hidma_mgmt_probe()
272 mgmtdev->priority = devm_kcalloc(&pdev->dev, in hidma_mgmt_probe()
273 mgmtdev->dma_channels, in hidma_mgmt_probe()
274 sizeof(*mgmtdev->priority), in hidma_mgmt_probe()
276 if (!mgmtdev->priority) { in hidma_mgmt_probe()
277 rc = -ENOMEM; in hidma_mgmt_probe()
278 goto out; in hidma_mgmt_probe()
281 mgmtdev->weight = devm_kcalloc(&pdev->dev, in hidma_mgmt_probe()
282 mgmtdev->dma_channels, in hidma_mgmt_probe()
283 sizeof(*mgmtdev->weight), GFP_KERNEL); in hidma_mgmt_probe()
284 if (!mgmtdev->weight) { in hidma_mgmt_probe()
285 rc = -ENOMEM; in hidma_mgmt_probe()
286 goto out; in hidma_mgmt_probe()
291 dev_err(&pdev->dev, "setup failed\n"); in hidma_mgmt_probe()
292 goto out; in hidma_mgmt_probe()
296 val = readl(mgmtdev->virtaddr + HIDMA_CFG_OFFSET); in hidma_mgmt_probe()
298 writel(val, mgmtdev->virtaddr + HIDMA_CFG_OFFSET); in hidma_mgmt_probe()
302 dev_err(&pdev->dev, "sysfs setup failed\n"); in hidma_mgmt_probe()
303 goto out; in hidma_mgmt_probe()
306 dev_info(&pdev->dev, in hidma_mgmt_probe()
308 mgmtdev->hw_version_major, mgmtdev->hw_version_minor, in hidma_mgmt_probe()
309 &res->start, mgmtdev->dma_channels); in hidma_mgmt_probe()
312 pm_runtime_mark_last_busy(&pdev->dev); in hidma_mgmt_probe()
313 pm_runtime_put_autosuspend(&pdev->dev); in hidma_mgmt_probe()
315 out: in hidma_mgmt_probe()
316 pm_runtime_put_sync_suspend(&pdev->dev); in hidma_mgmt_probe()
317 pm_runtime_disable(&pdev->dev); in hidma_mgmt_probe()
330 {.compatible = "qcom,hidma-mgmt-1.0",},
338 .name = "hidma-mgmt",
358 return -ENOMEM; in hidma_mgmt_of_populate_channels()
365 goto out; in hidma_mgmt_of_populate_channels()
369 goto out; in hidma_mgmt_of_populate_channels()
373 goto out; in hidma_mgmt_of_populate_channels()
376 pdevinfo.fwnode = &child->fwnode; in hidma_mgmt_of_populate_channels()
377 pdevinfo.parent = pdev_parent ? &pdev_parent->dev : NULL; in hidma_mgmt_of_populate_channels()
378 pdevinfo.name = child->name; in hidma_mgmt_of_populate_channels()
388 goto out; in hidma_mgmt_of_populate_channels()
390 new_pdev->dev.of_node = child; in hidma_mgmt_of_populate_channels()
391 of_dma_configure(&new_pdev->dev, child, true); in hidma_mgmt_of_populate_channels()
396 of_msi_configure(&new_pdev->dev, child); in hidma_mgmt_of_populate_channels()
403 out: in hidma_mgmt_of_populate_channels()
429 * be cleaned up - this is not a trivial exercise. in hidma_mgmt_init()