aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/atmel-ssc.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/misc/atmel-ssc.c')
-rw-r--r--drivers/misc/atmel-ssc.c145
1 files changed, 97 insertions, 48 deletions
diff --git a/drivers/misc/atmel-ssc.c b/drivers/misc/atmel-ssc.c
index 5bb187781074..3c09cbb70b1d 100644
--- a/drivers/misc/atmel-ssc.c
+++ b/drivers/misc/atmel-ssc.c
@@ -18,6 +18,9 @@
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/module.h> 19#include <linux/module.h>
20 20
21#include <linux/of.h>
22#include <linux/pinctrl/consumer.h>
23
21/* Serialize access to ssc_list and user count */ 24/* Serialize access to ssc_list and user count */
22static DEFINE_SPINLOCK(user_lock); 25static DEFINE_SPINLOCK(user_lock);
23static LIST_HEAD(ssc_list); 26static LIST_HEAD(ssc_list);
@@ -29,7 +32,13 @@ struct ssc_device *ssc_request(unsigned int ssc_num)
29 32
30 spin_lock(&user_lock); 33 spin_lock(&user_lock);
31 list_for_each_entry(ssc, &ssc_list, list) { 34 list_for_each_entry(ssc, &ssc_list, list) {
32 if (ssc->pdev->id == ssc_num) { 35 if (ssc->pdev->dev.of_node) {
36 if (of_alias_get_id(ssc->pdev->dev.of_node, "ssc")
37 == ssc_num) {
38 ssc_valid = 1;
39 break;
40 }
41 } else if (ssc->pdev->id == ssc_num) {
33 ssc_valid = 1; 42 ssc_valid = 1;
34 break; 43 break;
35 } 44 }
@@ -68,39 +77,100 @@ void ssc_free(struct ssc_device *ssc)
68} 77}
69EXPORT_SYMBOL(ssc_free); 78EXPORT_SYMBOL(ssc_free);
70 79
71static int __init ssc_probe(struct platform_device *pdev) 80static struct atmel_ssc_platform_data at91rm9200_config = {
81 .use_dma = 0,
82};
83
84static struct atmel_ssc_platform_data at91sam9g45_config = {
85 .use_dma = 1,
86};
87
88static const struct platform_device_id atmel_ssc_devtypes[] = {
89 {
90 .name = "at91rm9200_ssc",
91 .driver_data = (unsigned long) &at91rm9200_config,
92 }, {
93 .name = "at91sam9g45_ssc",
94 .driver_data = (unsigned long) &at91sam9g45_config,
95 }, {
96 /* sentinel */
97 }
98};
99
100#ifdef CONFIG_OF
101static const struct of_device_id atmel_ssc_dt_ids[] = {
102 {
103 .compatible = "atmel,at91rm9200-ssc",
104 .data = &at91rm9200_config,
105 }, {
106 .compatible = "atmel,at91sam9g45-ssc",
107 .data = &at91sam9g45_config,
108 }, {
109 /* sentinel */
110 }
111};
112MODULE_DEVICE_TABLE(of, atmel_ssc_dt_ids);
113#endif
114
115static inline const struct atmel_ssc_platform_data * __init
116 atmel_ssc_get_driver_data(struct platform_device *pdev)
117{
118 if (pdev->dev.of_node) {
119 const struct of_device_id *match;
120 match = of_match_node(atmel_ssc_dt_ids, pdev->dev.of_node);
121 if (match == NULL)
122 return NULL;
123 return match->data;
124 }
125
126 return (struct atmel_ssc_platform_data *)
127 platform_get_device_id(pdev)->driver_data;
128}
129
130static int ssc_probe(struct platform_device *pdev)
72{ 131{
73 int retval = 0;
74 struct resource *regs; 132 struct resource *regs;
75 struct ssc_device *ssc; 133 struct ssc_device *ssc;
134 const struct atmel_ssc_platform_data *plat_dat;
135 struct pinctrl *pinctrl;
136
137 pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
138 if (IS_ERR(pinctrl)) {
139 dev_err(&pdev->dev, "Failed to request pinctrl\n");
140 return PTR_ERR(pinctrl);
141 }
76 142
77 ssc = kzalloc(sizeof(struct ssc_device), GFP_KERNEL); 143 ssc = devm_kzalloc(&pdev->dev, sizeof(struct ssc_device), GFP_KERNEL);
78 if (!ssc) { 144 if (!ssc) {
79 dev_dbg(&pdev->dev, "out of memory\n"); 145 dev_dbg(&pdev->dev, "out of memory\n");
80 retval = -ENOMEM; 146 return -ENOMEM;
81 goto out;
82 } 147 }
83 148
149 ssc->pdev = pdev;
150
151 plat_dat = atmel_ssc_get_driver_data(pdev);
152 if (!plat_dat)
153 return -ENODEV;
154 ssc->pdata = (struct atmel_ssc_platform_data *)plat_dat;
155
84 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 156 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
85 if (!regs) { 157 if (!regs) {
86 dev_dbg(&pdev->dev, "no mmio resource defined\n"); 158 dev_dbg(&pdev->dev, "no mmio resource defined\n");
87 retval = -ENXIO; 159 return -ENXIO;
88 goto out_free;
89 }
90
91 ssc->clk = clk_get(&pdev->dev, "pclk");
92 if (IS_ERR(ssc->clk)) {
93 dev_dbg(&pdev->dev, "no pclk clock defined\n");
94 retval = -ENXIO;
95 goto out_free;
96 } 160 }
97 161
98 ssc->pdev = pdev; 162 ssc->regs = devm_request_and_ioremap(&pdev->dev, regs);
99 ssc->regs = ioremap(regs->start, resource_size(regs));
100 if (!ssc->regs) { 163 if (!ssc->regs) {
101 dev_dbg(&pdev->dev, "ioremap failed\n"); 164 dev_dbg(&pdev->dev, "ioremap failed\n");
102 retval = -EINVAL; 165 return -EINVAL;
103 goto out_clk; 166 }
167
168 ssc->phybase = regs->start;
169
170 ssc->clk = devm_clk_get(&pdev->dev, "pclk");
171 if (IS_ERR(ssc->clk)) {
172 dev_dbg(&pdev->dev, "no pclk clock defined\n");
173 return -ENXIO;
104 } 174 }
105 175
106 /* disable all interrupts */ 176 /* disable all interrupts */
@@ -112,8 +182,7 @@ static int __init ssc_probe(struct platform_device *pdev)
112 ssc->irq = platform_get_irq(pdev, 0); 182 ssc->irq = platform_get_irq(pdev, 0);
113 if (!ssc->irq) { 183 if (!ssc->irq) {
114 dev_dbg(&pdev->dev, "could not get irq\n"); 184 dev_dbg(&pdev->dev, "could not get irq\n");
115 retval = -ENXIO; 185 return -ENXIO;
116 goto out_unmap;
117 } 186 }
118 187
119 spin_lock(&user_lock); 188 spin_lock(&user_lock);
@@ -125,51 +194,31 @@ static int __init ssc_probe(struct platform_device *pdev)
125 dev_info(&pdev->dev, "Atmel SSC device at 0x%p (irq %d)\n", 194 dev_info(&pdev->dev, "Atmel SSC device at 0x%p (irq %d)\n",
126 ssc->regs, ssc->irq); 195 ssc->regs, ssc->irq);
127 196
128 goto out; 197 return 0;
129
130out_unmap:
131 iounmap(ssc->regs);
132out_clk:
133 clk_put(ssc->clk);
134out_free:
135 kfree(ssc);
136out:
137 return retval;
138} 198}
139 199
140static int __devexit ssc_remove(struct platform_device *pdev) 200static int ssc_remove(struct platform_device *pdev)
141{ 201{
142 struct ssc_device *ssc = platform_get_drvdata(pdev); 202 struct ssc_device *ssc = platform_get_drvdata(pdev);
143 203
144 spin_lock(&user_lock); 204 spin_lock(&user_lock);
145 iounmap(ssc->regs);
146 clk_put(ssc->clk);
147 list_del(&ssc->list); 205 list_del(&ssc->list);
148 kfree(ssc);
149 spin_unlock(&user_lock); 206 spin_unlock(&user_lock);
150 207
151 return 0; 208 return 0;
152} 209}
153 210
154static struct platform_driver ssc_driver = { 211static struct platform_driver ssc_driver = {
155 .remove = __devexit_p(ssc_remove),
156 .driver = { 212 .driver = {
157 .name = "ssc", 213 .name = "ssc",
158 .owner = THIS_MODULE, 214 .owner = THIS_MODULE,
215 .of_match_table = of_match_ptr(atmel_ssc_dt_ids),
159 }, 216 },
217 .id_table = atmel_ssc_devtypes,
218 .probe = ssc_probe,
219 .remove = ssc_remove,
160}; 220};
161 221module_platform_driver(ssc_driver);
162static int __init ssc_init(void)
163{
164 return platform_driver_probe(&ssc_driver, ssc_probe);
165}
166module_init(ssc_init);
167
168static void __exit ssc_exit(void)
169{
170 platform_driver_unregister(&ssc_driver);
171}
172module_exit(ssc_exit);
173 222
174MODULE_AUTHOR("Hans-Christian Egtvedt <hcegtvedt@atmel.com>"); 223MODULE_AUTHOR("Hans-Christian Egtvedt <hcegtvedt@atmel.com>");
175MODULE_DESCRIPTION("SSC driver for Atmel AVR32 and AT91"); 224MODULE_DESCRIPTION("SSC driver for Atmel AVR32 and AT91");