static int pxa_irda_probe(struct platform_device *pdev) { struct net_device *dev; struct pxa_irda *si; unsigned int baudrate_mask; int err; if (!pdev->dev.platform_data) return -ENODEV; err = request_mem_region(__PREG(STUART), 0x24, "IrDA") ? 0 : -EBUSY; if (err) goto err_mem_1; err = request_mem_region(__PREG(FICP), 0x1c, "IrDA") ? 0 : -EBUSY; if (err) goto err_mem_2; dev = alloc_irdadev(sizeof(struct pxa_irda)); if (!dev) goto err_mem_3; si = netdev_priv(dev); si->dev = &pdev->dev; si->pdata = pdev->dev.platform_data; si->sir_clk = clk_get(&pdev->dev, "UARTCLK"); si->fir_clk = clk_get(&pdev->dev, "FICPCLK"); if (IS_ERR(si->sir_clk) || IS_ERR(si->fir_clk)) { err = PTR_ERR(IS_ERR(si->sir_clk) ? si->sir_clk : si->fir_clk); goto err_mem_4; } /* * Initialise the SIR buffers */ err = pxa_irda_init_iobuf(&si->rx_buff, 14384); if (err) goto err_mem_4; err = pxa_irda_init_iobuf(&si->tx_buff, 4000); if (err) goto err_mem_5; if (si->pdata->startup) err = si->pdata->startup(si->dev); if (err) goto err_startup; dev->hard_start_xmit = pxa_irda_hard_xmit; dev->open = pxa_irda_start; dev->stop = pxa_irda_stop; dev->do_ioctl = pxa_irda_ioctl; dev->get_stats = pxa_irda_stats; irda_init_max_qos_capabilies(&si->qos); baudrate_mask = 0; if (si->pdata->transceiver_cap & IR_SIRMODE) baudrate_mask |= IR_9600|IR_19200|IR_38400|IR_57600|IR_115200; if (si->pdata->transceiver_cap & IR_FIRMODE) baudrate_mask |= IR_4000000 << 8; si->qos.baud_rate.bits &= baudrate_mask; si->qos.min_turn_time.bits = 7; /* 1ms or more */ irda_qos_bits_to_value(&si->qos); err = register_netdev(dev); if (err == 0) dev_set_drvdata(&pdev->dev, dev); if (err) { if (si->pdata->shutdown) si->pdata->shutdown(si->dev); err_startup: kfree(si->tx_buff.head); err_mem_5: kfree(si->rx_buff.head); err_mem_4: if (si->sir_clk && !IS_ERR(si->sir_clk)) clk_put(si->sir_clk); if (si->fir_clk && !IS_ERR(si->fir_clk)) clk_put(si->fir_clk); free_netdev(dev); err_mem_3: release_mem_region(__PREG(FICP), 0x1c); err_mem_2: release_mem_region(__PREG(STUART), 0x24); } err_mem_1: return err; }
static int pxa_irda_probe(struct platform_device *pdev) { struct net_device *dev; struct pxa_irda *si; unsigned int baudrate_mask; int err; if (!pdev->dev.platform_data) return -ENODEV; err = request_mem_region(__PREG(STUART), 0x24, "IrDA") ? 0 : -EBUSY; if (err) goto err_mem_1; err = request_mem_region(__PREG(FICP), 0x1c, "IrDA") ? 0 : -EBUSY; if (err) goto err_mem_2; dev = alloc_irdadev(sizeof(struct pxa_irda)); if (!dev) goto err_mem_3; SET_NETDEV_DEV(dev, &pdev->dev); si = netdev_priv(dev); si->dev = &pdev->dev; si->pdata = pdev->dev.platform_data; si->sir_clk = clk_get(&pdev->dev, "UARTCLK"); si->fir_clk = clk_get(&pdev->dev, "FICPCLK"); if (IS_ERR(si->sir_clk) || IS_ERR(si->fir_clk)) { err = PTR_ERR(IS_ERR(si->sir_clk) ? si->sir_clk : si->fir_clk); goto err_mem_4; } /* * Initialise the SIR buffers */ err = pxa_irda_init_iobuf(&si->rx_buff, 14384); if (err) goto err_mem_4; err = pxa_irda_init_iobuf(&si->tx_buff, 4000); if (err) goto err_mem_5; if (gpio_is_valid(si->pdata->gpio_pwdown)) { err = gpio_request(si->pdata->gpio_pwdown, "IrDA switch"); if (err) goto err_startup; err = gpio_direction_output(si->pdata->gpio_pwdown, !si->pdata->gpio_pwdown_inverted); if (err) { gpio_free(si->pdata->gpio_pwdown); goto err_startup; } } if (si->pdata->startup) { err = si->pdata->startup(si->dev); if (err) goto err_startup; } if (gpio_is_valid(si->pdata->gpio_pwdown) && si->pdata->startup) dev_warn(si->dev, "gpio_pwdown and startup() both defined!\n"); dev->netdev_ops = &pxa_irda_netdev_ops; irda_init_max_qos_capabilies(&si->qos); baudrate_mask = 0; if (si->pdata->transceiver_cap & IR_SIRMODE) baudrate_mask |= IR_9600|IR_19200|IR_38400|IR_57600|IR_115200; if (si->pdata->transceiver_cap & IR_FIRMODE) baudrate_mask |= IR_4000000 << 8; si->qos.baud_rate.bits &= baudrate_mask; si->qos.min_turn_time.bits = 7; /* 1ms or more */ irda_qos_bits_to_value(&si->qos); err = register_netdev(dev); if (err == 0) dev_set_drvdata(&pdev->dev, dev); if (err) { if (si->pdata->shutdown) si->pdata->shutdown(si->dev); err_startup: kfree(si->tx_buff.head); err_mem_5: kfree(si->rx_buff.head); err_mem_4: if (si->sir_clk && !IS_ERR(si->sir_clk)) clk_put(si->sir_clk); if (si->fir_clk && !IS_ERR(si->fir_clk)) clk_put(si->fir_clk); free_netdev(dev); err_mem_3: release_mem_region(__PREG(FICP), 0x1c); err_mem_2: release_mem_region(__PREG(STUART), 0x24); } err_mem_1: return err; }