static int eth_initialize(struct device *dev) { const struct eth_sam_dev_cfg *const cfg = DEV_CFG(dev); cfg->config_func(); /* Enable GMAC module's clock */ soc_pmc_peripheral_enable(cfg->periph_id); /* Connect pins to the peripheral */ soc_gpio_list_configure(cfg->pin_list, cfg->pin_list_size); return 0; }
static int i2c_sam_twi_initialize(struct device *dev) { const struct i2c_sam_twi_dev_cfg *const dev_cfg = DEV_CFG(dev); struct i2c_sam_twi_dev_data *const dev_data = DEV_DATA(dev); Twi *const twi = dev_cfg->regs; u32_t bitrate_cfg; int ret; /* Configure interrupts */ dev_cfg->irq_config(); /* Initialize semaphore */ k_sem_init(&dev_data->sem, 0, 1); /* Connect pins to the peripheral */ soc_gpio_list_configure(dev_cfg->pin_list, dev_cfg->pin_list_size); /* Enable module's clock */ soc_pmc_peripheral_enable(dev_cfg->periph_id); /* Reset TWI module */ twi->TWI_CR = TWI_CR_SWRST; bitrate_cfg = _i2c_map_dt_bitrate(dev_cfg->bitrate); ret = i2c_sam_twi_configure(dev, I2C_MODE_MASTER | bitrate_cfg); if (ret < 0) { LOG_ERR("Failed to initialize %s device", DEV_NAME(dev)); return ret; } /* Enable module's IRQ */ irq_enable(dev_cfg->irq_id); LOG_INF("Device %s initialized", DEV_NAME(dev)); return 0; }