Linux Audio

Check our new training course

Loading...
v3.1
 
  1/*
  2 * c67x00-drv.c: Cypress C67X00 USB Common infrastructure
  3 *
  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.
  7 *
  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.
 12 *
 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.
 17 *
 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,
 21 * MA  02110-1301  USA.
 22 */
 23
 24/*
 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).
 29 *
 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).
 32 *
 33 * Depending on the platform configuration, the SIE's are created and
 34 * the corresponding subdriver is initialized (c67x00_probe_sie).
 35 */
 36
 37#include <linux/device.h>
 38#include <linux/io.h>
 39#include <linux/list.h>
 40#include <linux/slab.h>
 
 41#include <linux/usb.h>
 42#include <linux/usb/c67x00.h>
 43
 44#include "c67x00.h"
 45#include "c67x00-hcd.h"
 46
 47static void c67x00_probe_sie(struct c67x00_sie *sie,
 48			     struct c67x00_device *dev, int sie_num)
 49{
 50	spin_lock_init(&sie->lock);
 51	sie->dev = dev;
 52	sie->sie_num = sie_num;
 53	sie->mode = c67x00_sie_config(dev->pdata->sie_config, sie_num);
 54
 55	switch (sie->mode) {
 56	case C67X00_SIE_HOST:
 57		c67x00_hcd_probe(sie);
 58		break;
 59
 60	case C67X00_SIE_UNUSED:
 61		dev_info(sie_dev(sie),
 62			 "Not using SIE %d as requested\n", sie->sie_num);
 63		break;
 64
 65	default:
 66		dev_err(sie_dev(sie),
 67			"Unsupported configuration: 0x%x for SIE %d\n",
 68			sie->mode, sie->sie_num);
 69		break;
 70	}
 71}
 72
 73static void c67x00_remove_sie(struct c67x00_sie *sie)
 74{
 75	switch (sie->mode) {
 76	case C67X00_SIE_HOST:
 77		c67x00_hcd_remove(sie);
 78		break;
 79
 80	default:
 81		break;
 82	}
 83}
 84
 85static irqreturn_t c67x00_irq(int irq, void *__dev)
 86{
 87	struct c67x00_device *c67x00 = __dev;
 88	struct c67x00_sie *sie;
 89	u16 msg, int_status;
 90	int i, count = 8;
 91
 92	int_status = c67x00_ll_hpi_status(c67x00);
 93	if (!int_status)
 94		return IRQ_NONE;
 95
 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];
100			msg = 0;
101			if (int_status & SIEMSG_FLG(i))
102				msg = c67x00_ll_fetch_siemsg(c67x00, i);
103			if (sie->irq)
104				sie->irq(sie, int_status, msg);
105		}
106		int_status = c67x00_ll_hpi_status(c67x00);
107	}
108
109	if (int_status)
110		dev_warn(&c67x00->pdev->dev, "Not all interrupts handled! "
111			 "status = 0x%04x\n", int_status);
112
113	return IRQ_HANDLED;
114}
115
116/* ------------------------------------------------------------------------- */
117
118static int __devinit c67x00_drv_probe(struct platform_device *pdev)
119{
120	struct c67x00_device *c67x00;
121	struct c67x00_platform_data *pdata;
122	struct resource *res, *res2;
123	int ret, i;
124
125	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
126	if (!res)
127		return -ENODEV;
128
129	res2 = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
130	if (!res2)
131		return -ENODEV;
132
133	pdata = pdev->dev.platform_data;
134	if (!pdata)
135		return -ENODEV;
136
137	c67x00 = kzalloc(sizeof(*c67x00), GFP_KERNEL);
138	if (!c67x00)
139		return -ENOMEM;
140
141	if (!request_mem_region(res->start, resource_size(res),
142				pdev->name)) {
143		dev_err(&pdev->dev, "Memory region busy\n");
144		ret = -EBUSY;
145		goto request_mem_failed;
146	}
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");
150		ret = -EIO;
151		goto map_failed;
152	}
153
154	spin_lock_init(&c67x00->hpi.lock);
155	c67x00->hpi.regstep = pdata->hpi_regstep;
156	c67x00->pdata = pdev->dev.platform_data;
157	c67x00->pdev = pdev;
158
159	c67x00_ll_init(c67x00);
160	c67x00_ll_hpi_reg_init(c67x00);
161
162	ret = request_irq(res2->start, c67x00_irq, 0, pdev->name, c67x00);
163	if (ret) {
164		dev_err(&pdev->dev, "Cannot claim IRQ\n");
165		goto request_irq_failed;
166	}
167
168	ret = c67x00_ll_reset(c67x00);
169	if (ret) {
170		dev_err(&pdev->dev, "Device reset failed\n");
171		goto reset_failed;
172	}
173
174	for (i = 0; i < C67X00_SIES; i++)
175		c67x00_probe_sie(&c67x00->sie[i], c67x00, i);
176
177	platform_set_drvdata(pdev, c67x00);
178
179	return 0;
180
181 reset_failed:
182	free_irq(res2->start, c67x00);
183 request_irq_failed:
184	iounmap(c67x00->hpi.base);
185 map_failed:
186	release_mem_region(res->start, resource_size(res));
187 request_mem_failed:
188	kfree(c67x00);
189
190	return ret;
191}
192
193static int __devexit c67x00_drv_remove(struct platform_device *pdev)
194{
195	struct c67x00_device *c67x00 = platform_get_drvdata(pdev);
196	struct resource *res;
197	int i;
198
199	for (i = 0; i < C67X00_SIES; i++)
200		c67x00_remove_sie(&c67x00->sie[i]);
201
202	c67x00_ll_release(c67x00);
203
204	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
205	if (res)
206		free_irq(res->start, c67x00);
207
208	iounmap(c67x00->hpi.base);
209
210	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
211	if (res)
212		release_mem_region(res->start, resource_size(res));
213
214	kfree(c67x00);
215
216	return 0;
217}
218
219static struct platform_driver c67x00_driver = {
220	.probe	= c67x00_drv_probe,
221	.remove	= __devexit_p(c67x00_drv_remove),
222	.driver	= {
223		.owner = THIS_MODULE,
224		.name = "c67x00",
225	},
226};
227MODULE_ALIAS("platform:c67x00");
228
229static int __init c67x00_init(void)
230{
231	return platform_driver_register(&c67x00_driver);
232}
233
234static void __exit c67x00_exit(void)
235{
236	platform_driver_unregister(&c67x00_driver);
237}
238
239module_init(c67x00_init);
240module_exit(c67x00_exit);
241
242MODULE_AUTHOR("Peter Korsgaard, Jan Veldeman, Grant Likely");
243MODULE_DESCRIPTION("Cypress C67X00 USB Controller Driver");
244MODULE_LICENSE("GPL");
v5.9
  1// SPDX-License-Identifier: GPL-2.0+
  2/*
  3 * c67x00-drv.c: Cypress C67X00 USB Common infrastructure
  4 *
  5 * Copyright (C) 2006-2008 Barco N.V.
  6 *    Derived from the Cypress cy7c67200/300 ezusb linux driver and
  7 *    based on multiple host controller drivers inside the linux kernel.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  8 */
  9
 10/*
 11 * This file implements the common infrastructure for using the c67x00.
 12 * It is both the link between the platform configuration and subdrivers and
 13 * the link between the common hardware parts and the subdrivers (e.g.
 14 * interrupt handling).
 15 *
 16 * The c67x00 has 2 SIE's (serial interface engine) which can be configured
 17 * to be host, device or OTG (with some limitations, E.G. only SIE1 can be OTG).
 18 *
 19 * Depending on the platform configuration, the SIE's are created and
 20 * the corresponding subdriver is initialized (c67x00_probe_sie).
 21 */
 22
 23#include <linux/device.h>
 24#include <linux/io.h>
 25#include <linux/list.h>
 26#include <linux/slab.h>
 27#include <linux/module.h>
 28#include <linux/usb.h>
 29#include <linux/usb/c67x00.h>
 30
 31#include "c67x00.h"
 32#include "c67x00-hcd.h"
 33
 34static void c67x00_probe_sie(struct c67x00_sie *sie,
 35			     struct c67x00_device *dev, int sie_num)
 36{
 37	spin_lock_init(&sie->lock);
 38	sie->dev = dev;
 39	sie->sie_num = sie_num;
 40	sie->mode = c67x00_sie_config(dev->pdata->sie_config, sie_num);
 41
 42	switch (sie->mode) {
 43	case C67X00_SIE_HOST:
 44		c67x00_hcd_probe(sie);
 45		break;
 46
 47	case C67X00_SIE_UNUSED:
 48		dev_info(sie_dev(sie),
 49			 "Not using SIE %d as requested\n", sie->sie_num);
 50		break;
 51
 52	default:
 53		dev_err(sie_dev(sie),
 54			"Unsupported configuration: 0x%x for SIE %d\n",
 55			sie->mode, sie->sie_num);
 56		break;
 57	}
 58}
 59
 60static void c67x00_remove_sie(struct c67x00_sie *sie)
 61{
 62	switch (sie->mode) {
 63	case C67X00_SIE_HOST:
 64		c67x00_hcd_remove(sie);
 65		break;
 66
 67	default:
 68		break;
 69	}
 70}
 71
 72static irqreturn_t c67x00_irq(int irq, void *__dev)
 73{
 74	struct c67x00_device *c67x00 = __dev;
 75	struct c67x00_sie *sie;
 76	u16 msg, int_status;
 77	int i, count = 8;
 78
 79	int_status = c67x00_ll_hpi_status(c67x00);
 80	if (!int_status)
 81		return IRQ_NONE;
 82
 83	while (int_status != 0 && (count-- >= 0)) {
 84		c67x00_ll_irq(c67x00, int_status);
 85		for (i = 0; i < C67X00_SIES; i++) {
 86			sie = &c67x00->sie[i];
 87			msg = 0;
 88			if (int_status & SIEMSG_FLG(i))
 89				msg = c67x00_ll_fetch_siemsg(c67x00, i);
 90			if (sie->irq)
 91				sie->irq(sie, int_status, msg);
 92		}
 93		int_status = c67x00_ll_hpi_status(c67x00);
 94	}
 95
 96	if (int_status)
 97		dev_warn(&c67x00->pdev->dev, "Not all interrupts handled! "
 98			 "status = 0x%04x\n", int_status);
 99
100	return IRQ_HANDLED;
101}
102
103/* ------------------------------------------------------------------------- */
104
105static int c67x00_drv_probe(struct platform_device *pdev)
106{
107	struct c67x00_device *c67x00;
108	struct c67x00_platform_data *pdata;
109	struct resource *res, *res2;
110	int ret, i;
111
112	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
113	if (!res)
114		return -ENODEV;
115
116	res2 = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
117	if (!res2)
118		return -ENODEV;
119
120	pdata = dev_get_platdata(&pdev->dev);
121	if (!pdata)
122		return -ENODEV;
123
124	c67x00 = kzalloc(sizeof(*c67x00), GFP_KERNEL);
125	if (!c67x00)
126		return -ENOMEM;
127
128	if (!request_mem_region(res->start, resource_size(res),
129				pdev->name)) {
130		dev_err(&pdev->dev, "Memory region busy\n");
131		ret = -EBUSY;
132		goto request_mem_failed;
133	}
134	c67x00->hpi.base = ioremap(res->start, resource_size(res));
135	if (!c67x00->hpi.base) {
136		dev_err(&pdev->dev, "Unable to map HPI registers\n");
137		ret = -EIO;
138		goto map_failed;
139	}
140
141	spin_lock_init(&c67x00->hpi.lock);
142	c67x00->hpi.regstep = pdata->hpi_regstep;
143	c67x00->pdata = dev_get_platdata(&pdev->dev);
144	c67x00->pdev = pdev;
145
146	c67x00_ll_init(c67x00);
147	c67x00_ll_hpi_reg_init(c67x00);
148
149	ret = request_irq(res2->start, c67x00_irq, 0, pdev->name, c67x00);
150	if (ret) {
151		dev_err(&pdev->dev, "Cannot claim IRQ\n");
152		goto request_irq_failed;
153	}
154
155	ret = c67x00_ll_reset(c67x00);
156	if (ret) {
157		dev_err(&pdev->dev, "Device reset failed\n");
158		goto reset_failed;
159	}
160
161	for (i = 0; i < C67X00_SIES; i++)
162		c67x00_probe_sie(&c67x00->sie[i], c67x00, i);
163
164	platform_set_drvdata(pdev, c67x00);
165
166	return 0;
167
168 reset_failed:
169	free_irq(res2->start, c67x00);
170 request_irq_failed:
171	iounmap(c67x00->hpi.base);
172 map_failed:
173	release_mem_region(res->start, resource_size(res));
174 request_mem_failed:
175	kfree(c67x00);
176
177	return ret;
178}
179
180static int c67x00_drv_remove(struct platform_device *pdev)
181{
182	struct c67x00_device *c67x00 = platform_get_drvdata(pdev);
183	struct resource *res;
184	int i;
185
186	for (i = 0; i < C67X00_SIES; i++)
187		c67x00_remove_sie(&c67x00->sie[i]);
188
189	c67x00_ll_release(c67x00);
190
191	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
192	if (res)
193		free_irq(res->start, c67x00);
194
195	iounmap(c67x00->hpi.base);
196
197	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
198	if (res)
199		release_mem_region(res->start, resource_size(res));
200
201	kfree(c67x00);
202
203	return 0;
204}
205
206static struct platform_driver c67x00_driver = {
207	.probe	= c67x00_drv_probe,
208	.remove	= c67x00_drv_remove,
209	.driver	= {
 
210		.name = "c67x00",
211	},
212};
 
213
214module_platform_driver(c67x00_driver);
 
 
 
 
 
 
 
 
 
 
 
215
216MODULE_AUTHOR("Peter Korsgaard, Jan Veldeman, Grant Likely");
217MODULE_DESCRIPTION("Cypress C67X00 USB Controller Driver");
218MODULE_LICENSE("GPL");
219MODULE_ALIAS("platform:c67x00");