source: mainline/uspace/drv/bus/usb/uhci/res.c@ c898236

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since c898236 was 57c8fc9, checked in by Jan Vesely <jano.vesely@…>, 12 years ago

libusbhost: Move interrupt enabling to library.

Reduce code duplication.

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/*
2 * Copyright (c) 2011 Vojtech Horky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28/**
29 * @addtogroup drvusbuhcihc
30 * @{
31 */
32/**
33 * @file
34 * PCI related functions needed by the UHCI driver.
35 */
36
37#include <errno.h>
38#include <assert.h>
39#include <devman.h>
40#include <device/hw_res_parsed.h>
41#include <device/pci.h>
42
43#include "res.h"
44
45/** Get I/O address of registers and IRQ for given device.
46 *
47 * @param[in] dev Device asking for the addresses.
48 * @param[out] io_regs_p Pointer to register I/O range.
49 * @param[out] irq_no IRQ assigned to the device.
50 * @return Error code.
51 */
52int get_my_registers(ddf_dev_t *dev, addr_range_t *io_regs_p, int *irq_no)
53{
54 assert(dev);
55
56 async_sess_t *parent_sess =
57 devman_parent_device_connect(EXCHANGE_SERIALIZE,
58 ddf_dev_get_handle(dev), IPC_FLAG_BLOCKING);
59 if (!parent_sess)
60 return ENOMEM;
61
62 hw_res_list_parsed_t hw_res;
63 hw_res_list_parsed_init(&hw_res);
64 const int ret = hw_res_get_list_parsed(parent_sess, &hw_res, 0);
65 async_hangup(parent_sess);
66 if (ret != EOK) {
67 return ret;
68 }
69
70 /* We want one irq and one io range. */
71 if (hw_res.irqs.count != 1 || hw_res.io_ranges.count != 1) {
72 hw_res_list_parsed_clean(&hw_res);
73 return EINVAL;
74 }
75
76 if (io_regs_p)
77 *io_regs_p = hw_res.io_ranges.ranges[0];
78 if (irq_no)
79 *irq_no = hw_res.irqs.irqs[0];
80
81 hw_res_list_parsed_clean(&hw_res);
82 return EOK;
83}
84
85/** Call the PCI driver with a request to clear legacy support register
86 *
87 * @param[in] device Device asking to disable interrupts
88 * @return Error code.
89 */
90int disable_legacy(ddf_dev_t *device)
91{
92 assert(device);
93
94 async_sess_t *parent_sess = devman_parent_device_connect(
95 EXCHANGE_SERIALIZE, ddf_dev_get_handle(device), IPC_FLAG_BLOCKING);
96 if (!parent_sess)
97 return ENOMEM;
98
99 /* See UHCI design guide page 45 for these values.
100 * Write all WC bits in USB legacy register */
101 const int rc = pci_config_space_write_16(parent_sess, 0xc0, 0xaf00);
102
103 async_hangup(parent_sess);
104 return rc;
105}
106
107/**
108 * @}
109 */
Note: See TracBrowser for help on using the repository browser.