platform.c (597473720f4dc69749542bfcfed4a927a43d935e) | platform.c (b3757413b91ecf4a227c5f075446afe8126d882f) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Platform driver for the Synopsys DesignWare DMA Controller 4 * 5 * Copyright (C) 2007-2008 Atmel Corporation 6 * Copyright (C) 2010-2011 ST Microelectronics 7 * Copyright (C) 2013 Intel Corporation 8 * --- 154 unchanged lines hidden (view full) --- 163dw_dma_parse_dt(struct platform_device *pdev) 164{ 165 return NULL; 166} 167#endif 168 169static int dw_probe(struct platform_device *pdev) 170{ | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Platform driver for the Synopsys DesignWare DMA Controller 4 * 5 * Copyright (C) 2007-2008 Atmel Corporation 6 * Copyright (C) 2010-2011 ST Microelectronics 7 * Copyright (C) 2013 Intel Corporation 8 * --- 154 unchanged lines hidden (view full) --- 163dw_dma_parse_dt(struct platform_device *pdev) 164{ 165 return NULL; 166} 167#endif 168 169static int dw_probe(struct platform_device *pdev) 170{ |
171 const struct dw_dma_chip_pdata *match; 172 struct dw_dma_chip_pdata *data; |
|
171 struct dw_dma_chip *chip; 172 struct device *dev = &pdev->dev; 173 struct resource *mem; 174 const struct dw_dma_platform_data *pdata; 175 int err; 176 | 173 struct dw_dma_chip *chip; 174 struct device *dev = &pdev->dev; 175 struct resource *mem; 176 const struct dw_dma_platform_data *pdata; 177 int err; 178 |
179 match = device_get_match_data(dev); 180 if (!match) 181 return -ENODEV; 182 183 data = devm_kmemdup(&pdev->dev, match, sizeof(*match), GFP_KERNEL); 184 if (!data) 185 return -ENOMEM; 186 |
|
177 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); 178 if (!chip) 179 return -ENOMEM; 180 181 chip->irq = platform_get_irq(pdev, 0); 182 if (chip->irq < 0) 183 return chip->irq; 184 --- 9 unchanged lines hidden (view full) --- 194 pdata = dev_get_platdata(dev); 195 if (!pdata) 196 pdata = dw_dma_parse_dt(pdev); 197 198 chip->dev = dev; 199 chip->id = pdev->id; 200 chip->pdata = pdata; 201 | 187 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); 188 if (!chip) 189 return -ENOMEM; 190 191 chip->irq = platform_get_irq(pdev, 0); 192 if (chip->irq < 0) 193 return chip->irq; 194 --- 9 unchanged lines hidden (view full) --- 204 pdata = dev_get_platdata(dev); 205 if (!pdata) 206 pdata = dw_dma_parse_dt(pdev); 207 208 chip->dev = dev; 209 chip->id = pdev->id; 210 chip->pdata = pdata; 211 |
212 data->chip = chip; 213 |
|
202 chip->clk = devm_clk_get(chip->dev, "hclk"); 203 if (IS_ERR(chip->clk)) 204 return PTR_ERR(chip->clk); 205 err = clk_prepare_enable(chip->clk); 206 if (err) 207 return err; 208 209 pm_runtime_enable(&pdev->dev); 210 | 214 chip->clk = devm_clk_get(chip->dev, "hclk"); 215 if (IS_ERR(chip->clk)) 216 return PTR_ERR(chip->clk); 217 err = clk_prepare_enable(chip->clk); 218 if (err) 219 return err; 220 221 pm_runtime_enable(&pdev->dev); 222 |
211 err = dw_dma_probe(chip); | 223 err = data->probe(chip); |
212 if (err) 213 goto err_dw_dma_probe; 214 | 224 if (err) 225 goto err_dw_dma_probe; 226 |
215 platform_set_drvdata(pdev, chip); | 227 platform_set_drvdata(pdev, data); |
216 217 if (pdev->dev.of_node) { 218 err = of_dma_controller_register(pdev->dev.of_node, 219 dw_dma_of_xlate, chip->dw); 220 if (err) 221 dev_err(&pdev->dev, 222 "could not register of_dma_controller\n"); 223 } --- 6 unchanged lines hidden (view full) --- 230err_dw_dma_probe: 231 pm_runtime_disable(&pdev->dev); 232 clk_disable_unprepare(chip->clk); 233 return err; 234} 235 236static int dw_remove(struct platform_device *pdev) 237{ | 228 229 if (pdev->dev.of_node) { 230 err = of_dma_controller_register(pdev->dev.of_node, 231 dw_dma_of_xlate, chip->dw); 232 if (err) 233 dev_err(&pdev->dev, 234 "could not register of_dma_controller\n"); 235 } --- 6 unchanged lines hidden (view full) --- 242err_dw_dma_probe: 243 pm_runtime_disable(&pdev->dev); 244 clk_disable_unprepare(chip->clk); 245 return err; 246} 247 248static int dw_remove(struct platform_device *pdev) 249{ |
238 struct dw_dma_chip *chip = platform_get_drvdata(pdev); | 250 struct dw_dma_chip_pdata *data = platform_get_drvdata(pdev); 251 struct dw_dma_chip *chip = data->chip; 252 int ret; |
239 240 if (pdev->dev.of_node) 241 of_dma_controller_free(pdev->dev.of_node); 242 | 253 254 if (pdev->dev.of_node) 255 of_dma_controller_free(pdev->dev.of_node); 256 |
243 dw_dma_remove(chip); | 257 ret = data->remove(chip); 258 if (ret) 259 dev_warn(chip->dev, "can't remove device properly: %d\n", ret); 260 |
244 pm_runtime_disable(&pdev->dev); 245 clk_disable_unprepare(chip->clk); 246 247 return 0; 248} 249 250static void dw_shutdown(struct platform_device *pdev) 251{ | 261 pm_runtime_disable(&pdev->dev); 262 clk_disable_unprepare(chip->clk); 263 264 return 0; 265} 266 267static void dw_shutdown(struct platform_device *pdev) 268{ |
252 struct dw_dma_chip *chip = platform_get_drvdata(pdev); | 269 struct dw_dma_chip_pdata *data = platform_get_drvdata(pdev); 270 struct dw_dma_chip *chip = data->chip; |
253 254 /* 255 * We have to call do_dw_dma_disable() to stop any ongoing transfer. On 256 * some platforms we can't do that since DMA device is powered off. 257 * Moreover we have no possibility to check if the platform is affected 258 * or not. That's why we call pm_runtime_get_sync() / pm_runtime_put() 259 * unconditionally. On the other hand we can't use 260 * pm_runtime_suspended() because runtime PM framework is not fully 261 * used by the driver. 262 */ 263 pm_runtime_get_sync(chip->dev); 264 do_dw_dma_disable(chip); 265 pm_runtime_put_sync_suspend(chip->dev); 266 267 clk_disable_unprepare(chip->clk); 268} 269 270#ifdef CONFIG_OF 271static const struct of_device_id dw_dma_of_id_table[] = { | 271 272 /* 273 * We have to call do_dw_dma_disable() to stop any ongoing transfer. On 274 * some platforms we can't do that since DMA device is powered off. 275 * Moreover we have no possibility to check if the platform is affected 276 * or not. That's why we call pm_runtime_get_sync() / pm_runtime_put() 277 * unconditionally. On the other hand we can't use 278 * pm_runtime_suspended() because runtime PM framework is not fully 279 * used by the driver. 280 */ 281 pm_runtime_get_sync(chip->dev); 282 do_dw_dma_disable(chip); 283 pm_runtime_put_sync_suspend(chip->dev); 284 285 clk_disable_unprepare(chip->clk); 286} 287 288#ifdef CONFIG_OF 289static const struct of_device_id dw_dma_of_id_table[] = { |
272 { .compatible = "snps,dma-spear1340" }, | 290 { .compatible = "snps,dma-spear1340", .data = &dw_dma_chip_pdata }, |
273 {} 274}; 275MODULE_DEVICE_TABLE(of, dw_dma_of_id_table); 276#endif 277 278#ifdef CONFIG_ACPI 279static const struct acpi_device_id dw_dma_acpi_id_table[] = { | 291 {} 292}; 293MODULE_DEVICE_TABLE(of, dw_dma_of_id_table); 294#endif 295 296#ifdef CONFIG_ACPI 297static const struct acpi_device_id dw_dma_acpi_id_table[] = { |
280 { "INTL9C60", 0 }, 281 { "80862286", 0 }, 282 { "808622C0", 0 }, | 298 { "INTL9C60", (kernel_ulong_t)&dw_dma_chip_pdata }, 299 { "80862286", (kernel_ulong_t)&dw_dma_chip_pdata }, 300 { "808622C0", (kernel_ulong_t)&dw_dma_chip_pdata }, |
283 { } 284}; 285MODULE_DEVICE_TABLE(acpi, dw_dma_acpi_id_table); 286#endif 287 288#ifdef CONFIG_PM_SLEEP 289 290static int dw_suspend_late(struct device *dev) 291{ | 301 { } 302}; 303MODULE_DEVICE_TABLE(acpi, dw_dma_acpi_id_table); 304#endif 305 306#ifdef CONFIG_PM_SLEEP 307 308static int dw_suspend_late(struct device *dev) 309{ |
292 struct dw_dma_chip *chip = dev_get_drvdata(dev); | 310 struct dw_dma_chip_pdata *data = dev_get_drvdata(dev); 311 struct dw_dma_chip *chip = data->chip; |
293 294 do_dw_dma_disable(chip); 295 clk_disable_unprepare(chip->clk); 296 297 return 0; 298} 299 300static int dw_resume_early(struct device *dev) 301{ | 312 313 do_dw_dma_disable(chip); 314 clk_disable_unprepare(chip->clk); 315 316 return 0; 317} 318 319static int dw_resume_early(struct device *dev) 320{ |
302 struct dw_dma_chip *chip = dev_get_drvdata(dev); | 321 struct dw_dma_chip_pdata *data = dev_get_drvdata(dev); 322 struct dw_dma_chip *chip = data->chip; |
303 int ret; 304 305 ret = clk_prepare_enable(chip->clk); 306 if (ret) 307 return ret; 308 309 return do_dw_dma_enable(chip); 310} --- 34 unchanged lines hidden --- | 323 int ret; 324 325 ret = clk_prepare_enable(chip->clk); 326 if (ret) 327 return ret; 328 329 return do_dw_dma_enable(chip); 330} --- 34 unchanged lines hidden --- |