Commit | Line | Data |
---|---|---|
f7b6fd6d | 1 | /* |
ca632f55 | 2 | * Memory-mapped interface driver for DW SPI Core |
f7b6fd6d JHD |
3 | * |
4 | * Copyright (c) 2010, Octasic semiconductor. | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify it | |
7 | * under the terms and conditions of the GNU General Public License, | |
8 | * version 2, as published by the Free Software Foundation. | |
9 | */ | |
10 | ||
11 | #include <linux/clk.h> | |
50c01fc3 | 12 | #include <linux/err.h> |
f7b6fd6d JHD |
13 | #include <linux/interrupt.h> |
14 | #include <linux/platform_device.h> | |
5a0e3ad6 | 15 | #include <linux/slab.h> |
f7b6fd6d | 16 | #include <linux/spi/spi.h> |
568a60ed | 17 | #include <linux/scatterlist.h> |
d7614de4 | 18 | #include <linux/module.h> |
568a60ed | 19 | |
ca632f55 | 20 | #include "spi-dw.h" |
f7b6fd6d JHD |
21 | |
22 | #define DRIVER_NAME "dw_spi_mmio" | |
23 | ||
24 | struct dw_spi_mmio { | |
0a4c1d7d JHD |
25 | struct dw_spi dws; |
26 | struct clk *clk; | |
f7b6fd6d JHD |
27 | }; |
28 | ||
fd4a319b | 29 | static int dw_spi_mmio_probe(struct platform_device *pdev) |
f7b6fd6d JHD |
30 | { |
31 | struct dw_spi_mmio *dwsmmio; | |
32 | struct dw_spi *dws; | |
04f421e7 | 33 | struct resource *mem; |
f7b6fd6d JHD |
34 | int ret; |
35 | ||
04f421e7 BS |
36 | dwsmmio = devm_kzalloc(&pdev->dev, sizeof(struct dw_spi_mmio), |
37 | GFP_KERNEL); | |
38 | if (!dwsmmio) | |
39 | return -ENOMEM; | |
f7b6fd6d JHD |
40 | |
41 | dws = &dwsmmio->dws; | |
42 | ||
43 | /* Get basic io resource and map it */ | |
44 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | |
45 | if (!mem) { | |
46 | dev_err(&pdev->dev, "no mem resource?\n"); | |
04f421e7 | 47 | return -EINVAL; |
f7b6fd6d JHD |
48 | } |
49 | ||
04f421e7 BS |
50 | dws->regs = devm_ioremap_resource(&pdev->dev, mem); |
51 | if (IS_ERR(dws->regs)) { | |
52 | dev_err(&pdev->dev, "SPI region map failed\n"); | |
53 | return PTR_ERR(dws->regs); | |
f7b6fd6d JHD |
54 | } |
55 | ||
56 | dws->irq = platform_get_irq(pdev, 0); | |
57 | if (dws->irq < 0) { | |
58 | dev_err(&pdev->dev, "no irq resource?\n"); | |
04f421e7 | 59 | return dws->irq; /* -ENXIO */ |
f7b6fd6d JHD |
60 | } |
61 | ||
04f421e7 BS |
62 | dwsmmio->clk = devm_clk_get(&pdev->dev, NULL); |
63 | if (IS_ERR(dwsmmio->clk)) | |
64 | return PTR_ERR(dwsmmio->clk); | |
020fe3fe | 65 | ret = clk_prepare_enable(dwsmmio->clk); |
04f421e7 BS |
66 | if (ret) |
67 | return ret; | |
f7b6fd6d | 68 | |
2418991e | 69 | dws->bus_num = pdev->id; |
f7b6fd6d JHD |
70 | dws->num_cs = 4; |
71 | dws->max_freq = clk_get_rate(dwsmmio->clk); | |
72 | ||
04f421e7 | 73 | ret = dw_spi_add_host(&pdev->dev, dws); |
f7b6fd6d | 74 | if (ret) |
04f421e7 | 75 | goto out; |
f7b6fd6d JHD |
76 | |
77 | platform_set_drvdata(pdev, dwsmmio); | |
78 | return 0; | |
79 | ||
04f421e7 | 80 | out: |
020fe3fe | 81 | clk_disable_unprepare(dwsmmio->clk); |
f7b6fd6d JHD |
82 | return ret; |
83 | } | |
84 | ||
fd4a319b | 85 | static int dw_spi_mmio_remove(struct platform_device *pdev) |
f7b6fd6d JHD |
86 | { |
87 | struct dw_spi_mmio *dwsmmio = platform_get_drvdata(pdev); | |
f7b6fd6d | 88 | |
020fe3fe | 89 | clk_disable_unprepare(dwsmmio->clk); |
f7b6fd6d | 90 | dw_spi_remove_host(&dwsmmio->dws); |
f7b6fd6d | 91 | |
f7b6fd6d JHD |
92 | return 0; |
93 | } | |
94 | ||
95 | static struct platform_driver dw_spi_mmio_driver = { | |
940ab889 | 96 | .probe = dw_spi_mmio_probe, |
fd4a319b | 97 | .remove = dw_spi_mmio_remove, |
f7b6fd6d JHD |
98 | .driver = { |
99 | .name = DRIVER_NAME, | |
100 | .owner = THIS_MODULE, | |
101 | }, | |
102 | }; | |
940ab889 | 103 | module_platform_driver(dw_spi_mmio_driver); |
f7b6fd6d JHD |
104 | |
105 | MODULE_AUTHOR("Jean-Hugues Deschenes <jean-hugues.deschenes@octasic.com>"); | |
106 | MODULE_DESCRIPTION("Memory-mapped I/O interface driver for DW SPI Core"); | |
107 | MODULE_LICENSE("GPL v2"); |