2 * c67x00-drv.c: Cypress C67X00 USB Common infrastructure
4 * Copyright (C) 2006-2008 Barco N.V.
5 * Derived from the Cypress cy7c67200/300 ezusb linux driver and
6 * based on multiple host controller drivers inside the linux kernel.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25 * This file implements the common infrastructure for using the c67x00.
26 * It is both the link between the platform configuration and subdrivers and
27 * the link between the common hardware parts and the subdrivers (e.g.
28 * interrupt handling).
30 * The c67x00 has 2 SIE's (serial interface engine) which can be configured
31 * to be host, device or OTG (with some limitations, E.G. only SIE1 can be OTG).
33 * Depending on the platform configuration, the SIE's are created and
34 * the corresponding subdriver is initialized (c67x00_probe_sie).
37 #include <linux/device.h>
39 #include <linux/list.h>
40 #include <linux/slab.h>
41 #include <linux/usb.h>
42 #include <linux/usb/c67x00.h>
45 #include "c67x00-hcd.h"
47 static void c67x00_probe_sie(struct c67x00_sie
*sie
,
48 struct c67x00_device
*dev
, int sie_num
)
50 spin_lock_init(&sie
->lock
);
52 sie
->sie_num
= sie_num
;
53 sie
->mode
= c67x00_sie_config(dev
->pdata
->sie_config
, sie_num
);
57 c67x00_hcd_probe(sie
);
60 case C67X00_SIE_UNUSED
:
61 dev_info(sie_dev(sie
),
62 "Not using SIE %d as requested\n", sie
->sie_num
);
67 "Unsupported configuration: 0x%x for SIE %d\n",
68 sie
->mode
, sie
->sie_num
);
73 static void c67x00_remove_sie(struct c67x00_sie
*sie
)
77 c67x00_hcd_remove(sie
);
85 static irqreturn_t
c67x00_irq(int irq
, void *__dev
)
87 struct c67x00_device
*c67x00
= __dev
;
88 struct c67x00_sie
*sie
;
92 int_status
= c67x00_ll_hpi_status(c67x00
);
96 while (int_status
!= 0 && (count
-- >= 0)) {
97 c67x00_ll_irq(c67x00
, int_status
);
98 for (i
= 0; i
< C67X00_SIES
; i
++) {
99 sie
= &c67x00
->sie
[i
];
101 if (int_status
& SIEMSG_FLG(i
))
102 msg
= c67x00_ll_fetch_siemsg(c67x00
, i
);
104 sie
->irq(sie
, int_status
, msg
);
106 int_status
= c67x00_ll_hpi_status(c67x00
);
110 dev_warn(&c67x00
->pdev
->dev
, "Not all interrupts handled! "
111 "status = 0x%04x\n", int_status
);
116 /* ------------------------------------------------------------------------- */
118 static int __devinit
c67x00_drv_probe(struct platform_device
*pdev
)
120 struct c67x00_device
*c67x00
;
121 struct c67x00_platform_data
*pdata
;
122 struct resource
*res
, *res2
;
125 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
129 res2
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
133 pdata
= pdev
->dev
.platform_data
;
137 c67x00
= kzalloc(sizeof(*c67x00
), GFP_KERNEL
);
141 if (!request_mem_region(res
->start
, resource_size(res
),
143 dev_err(&pdev
->dev
, "Memory region busy\n");
145 goto request_mem_failed
;
147 c67x00
->hpi
.base
= ioremap(res
->start
, resource_size(res
));
148 if (!c67x00
->hpi
.base
) {
149 dev_err(&pdev
->dev
, "Unable to map HPI registers\n");
154 spin_lock_init(&c67x00
->hpi
.lock
);
155 c67x00
->hpi
.regstep
= pdata
->hpi_regstep
;
156 c67x00
->pdata
= pdev
->dev
.platform_data
;
159 c67x00_ll_init(c67x00
);
160 c67x00_ll_hpi_reg_init(c67x00
);
162 ret
= request_irq(res2
->start
, c67x00_irq
, 0, pdev
->name
, c67x00
);
164 dev_err(&pdev
->dev
, "Cannot claim IRQ\n");
165 goto request_irq_failed
;
168 ret
= c67x00_ll_reset(c67x00
);
170 dev_err(&pdev
->dev
, "Device reset failed\n");
174 for (i
= 0; i
< C67X00_SIES
; i
++)
175 c67x00_probe_sie(&c67x00
->sie
[i
], c67x00
, i
);
177 platform_set_drvdata(pdev
, c67x00
);
182 free_irq(res2
->start
, c67x00
);
184 iounmap(c67x00
->hpi
.base
);
186 release_mem_region(res
->start
, resource_size(res
));
193 static int __devexit
c67x00_drv_remove(struct platform_device
*pdev
)
195 struct c67x00_device
*c67x00
= platform_get_drvdata(pdev
);
196 struct resource
*res
;
199 for (i
= 0; i
< C67X00_SIES
; i
++)
200 c67x00_remove_sie(&c67x00
->sie
[i
]);
202 c67x00_ll_release(c67x00
);
204 res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
206 free_irq(res
->start
, c67x00
);
208 iounmap(c67x00
->hpi
.base
);
210 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
212 release_mem_region(res
->start
, resource_size(res
));
219 static struct platform_driver c67x00_driver
= {
220 .probe
= c67x00_drv_probe
,
221 .remove
= __devexit_p(c67x00_drv_remove
),
223 .owner
= THIS_MODULE
,
227 MODULE_ALIAS("platform:c67x00");
229 static int __init
c67x00_init(void)
231 return platform_driver_register(&c67x00_driver
);
234 static void __exit
c67x00_exit(void)
236 platform_driver_unregister(&c67x00_driver
);
239 module_init(c67x00_init
);
240 module_exit(c67x00_exit
);
242 MODULE_AUTHOR("Peter Korsgaard, Jan Veldeman, Grant Likely");
243 MODULE_DESCRIPTION("Cypress C67X00 USB Controller Driver");
244 MODULE_LICENSE("GPL");