Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/uhci/main.c

    r920d0fc r9f6cb910  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup drvusbuhcihc
     28/** @addtogroup drvusbuhci
    2929 * @{
    3030 */
     
    3232 * @brief UHCI driver initialization
    3333 */
     34
     35#include <assert.h>
    3436#include <ddf/driver.h>
     37#include <devman.h>
    3538#include <errno.h>
     39#include <io/log.h>
     40#include <pci_dev_iface.h>
     41#include <stdio.h>
    3642#include <str_error.h>
     43#include <usb/debug.h>
     44#include <usb/host/ddf_helpers.h>
    3745
    38 #include <usb/ddfiface.h>
    39 #include <usb/debug.h>
    40 
    41 #include "uhci.h"
     46#include "hc.h"
    4247
    4348#define NAME "uhci"
    4449
     50static int uhci_driver_init(hcd_t *hcd, const hw_res_list_parsed_t *res, bool irq)
     51{
     52        assert(hcd);
     53        assert(hcd->driver.data == NULL);
     54
     55        hc_t *instance = malloc(sizeof(hc_t));
     56        if (!instance)
     57                return ENOMEM;
     58
     59        const int ret =  hc_init(instance, res, irq);
     60        if (ret == EOK)
     61                hcd_set_implementation(hcd, instance, uhci_hc_schedule, NULL,
     62                    NULL, uhci_hc_interrupt, uhci_hc_status);
     63        return ret;
     64}
     65
     66static void uhci_driver_fini(hcd_t *hcd)
     67{
     68        assert(hcd);
     69        if (hcd->driver.data)
     70                hc_fini(hcd->driver.data);
     71
     72        free(hcd->driver.data);
     73        hcd_set_implementation(hcd, NULL, NULL, NULL, NULL, NULL, NULL);
     74}
     75
    4576static int uhci_dev_add(ddf_dev_t *device);
    4677
    47 static driver_ops_t uhci_driver_ops = {
     78static const driver_ops_t uhci_driver_ops = {
    4879        .dev_add = uhci_dev_add,
    4980};
    5081
    51 static driver_t uhci_driver = {
     82static const driver_t uhci_driver = {
    5283        .name = NAME,
    5384        .driver_ops = &uhci_driver_ops
    5485};
     86
     87/** Call the PCI driver with a request to clear legacy support register
     88 *
     89 * @param[in] device Device asking to disable interrupts
     90 * @return Error code.
     91 */
     92static int disable_legacy(ddf_dev_t *device)
     93{
     94        assert(device);
     95
     96        async_sess_t *parent_sess = devman_parent_device_connect(
     97            EXCHANGE_SERIALIZE, ddf_dev_get_handle(device), IPC_FLAG_BLOCKING);
     98        if (!parent_sess)
     99                return ENOMEM;
     100
     101        /* See UHCI design guide page 45 for these values.
     102         * Write all WC bits in USB legacy register */
     103        const int rc = pci_config_space_write_16(parent_sess, 0xc0, 0xaf00);
     104
     105        async_hangup(parent_sess);
     106        return rc;
     107}
    55108
    56109/** Initialize a new ddf driver instance for uhci hc and hub.
     
    64117        assert(device);
    65118
    66         const int ret = device_setup_uhci(device);
     119        int ret = disable_legacy(device);
     120        if (ret != EOK) {
     121                usb_log_error("Failed to disable legacy USB: %s.\n",
     122                    str_error(ret));
     123                return ret;
     124        }
     125
     126
     127        ret = ddf_hcd_device_setup_all(device, USB_SPEED_FULL,
     128            BANDWIDTH_AVAILABLE_USB11, bandwidth_count_usb11,
     129            ddf_hcd_gen_irq_handler, uhci_hc_gen_irq_code,
     130            uhci_driver_init, uhci_driver_fini);
    67131        if (ret != EOK) {
    68132                usb_log_error("Failed to initialize UHCI driver: %s.\n",
Note: See TracChangeset for help on using the changeset viewer.