static int __init ix8_platform_init()

in platform/broadcom/sonic-platform-modules-quanta/ix8-56x/modules/qci_platform_ix8.c [162:371]


static int __init ix8_platform_init(void)
{
	struct i2c_adapter *adapter;
	int ret, i;

	ret = platform_driver_register(&ix8_platform_driver);
	if (ret < 0)
		return ret;

	/* Register platform stuff */
	ix8_device = platform_device_alloc("qci-ix8", -1);
	if (!ix8_device) {
		ret = -ENOMEM;
		goto fail_platform_driver;
	}

	ret = platform_device_add(ix8_device);
	if (ret)
		goto fail_platform_device;

	g_client = kmalloc(sizeof(*g_client) * numof_i2c_devices, GFP_KERNEL);
	for (i = 0; i < numof_i2c_devices; i++) g_client[i] = NULL;

	g_client_port = kmalloc(sizeof(*g_client_port) * numof_ports, GFP_KERNEL);
	for (i = 0; i < numof_ports; i++) g_client_port[i] = NULL;

	adapter = i2c_get_adapter_wait(0);
	if (adapter == NULL)
	{
		printk("[%s] get i2c adapter fail at line %d", __FUNCTION__, __LINE__);
	}
	else
	{
		g_client[0] = i2c_new_client_device(adapter, &ix8_i2c_devices[0]);		// pca9546
		g_client[1] = i2c_new_client_device(adapter, &ix8_i2c_devices[1]);		// pca9548
		g_client[2] = i2c_new_client_device(adapter, &ix8_i2c_devices[16]);		// pca9546cpu
		i2c_put_adapter(adapter);
	}

	adapter = i2c_get_adapter_wait(13);
	if (adapter == NULL)
	{
		printk("[%s] get i2c adapter fail at line %d", __FUNCTION__, __LINE__);
	}
	else
	{
		g_client[3] = i2c_new_client_device(adapter, &ix8_i2c_devices[17]);		// CPU Board Data
		i2c_put_adapter(adapter);
	}

	adapter = i2c_get_adapter_wait(1);
	if (adapter == NULL)
	{
		printk("[%s] get i2c adapter fail at line %d", __FUNCTION__, __LINE__);
	}
	else
	{
		g_client[4] = i2c_new_client_device(adapter, &ix8_i2c_devices[10]);		// CPLD_1
		g_client[5] = i2c_new_client_device(adapter, &ix8_i2c_devices[18]);		// CPLD_4
		g_client[6] = i2c_new_client_device(adapter, &ix8_i2c_devices[19]);		// CPLD_6
		i2c_put_adapter(adapter);
	}

	adapter = i2c_get_adapter_wait(2);
	if (adapter == NULL)
	{
		printk("[%s] get i2c adapter fail at line %d", __FUNCTION__, __LINE__);
	}
	else
	{
		g_client[7] = i2c_new_client_device(adapter, &ix8_i2c_devices[11]);		// CPLD_2
		i2c_put_adapter(adapter);
	}

	adapter = i2c_get_adapter_wait(3);
	if (adapter == NULL)
	{
		printk("[%s] get i2c adapter fail at line %d", __FUNCTION__, __LINE__);
	}
	else
	{
		g_client[8] = i2c_new_client_device(adapter, &ix8_i2c_devices[12]);		// CPLD_3
		g_client[9] = i2c_new_client_device(adapter, &ix8_i2c_devices[2]);		// MB_BOARDINFO_EEPROM
		i2c_put_adapter(adapter);
	}

	adapter = i2c_get_adapter_wait(4);
	if (adapter == NULL)
	{
		printk("[%s] get i2c adapter fail at line %d", __FUNCTION__, __LINE__);
	}
	else
	{
		g_client[10] = i2c_new_client_device(adapter, &ix8_i2c_devices[13]);		// MB Board Data
		g_client[11] = i2c_new_client_device(adapter, &ix8_i2c_devices[14]);		// QSFP:49~52
		i2c_put_adapter(adapter);
	}

	adapter = i2c_get_adapter_wait(5);
	if (adapter == NULL)
	{
		printk("[%s] get i2c adapter fail at line %d", __FUNCTION__, __LINE__);
	}
	else
	{
		g_client[12] = i2c_new_client_device(adapter, &ix8_i2c_devices[3]);		// pca9548_1 SFP
		i2c_put_adapter(adapter);
	}

	adapter = i2c_get_adapter_wait(6);
	if (adapter == NULL)
	{
		printk("[%s] get i2c adapter fail at line %d", __FUNCTION__, __LINE__);
	}
	else
	{
		g_client[13] = i2c_new_client_device(adapter, &ix8_i2c_devices[4]);		// pca9548_2 SFP
		i2c_put_adapter(adapter);
	}

	adapter = i2c_get_adapter_wait(7);
	if (adapter == NULL)
	{
		printk("[%s] get i2c adapter fail at line %d", __FUNCTION__, __LINE__);
	}
	else
	{
		g_client[14] = i2c_new_client_device(adapter, &ix8_i2c_devices[5]);		// pca9548_3 SFP
		i2c_put_adapter(adapter);
	}

	adapter = i2c_get_adapter_wait(8);
	if (adapter == NULL)
	{
		printk("[%s] get i2c adapter fail at line %d", __FUNCTION__, __LINE__);
	}
	else
	{
		g_client[15] = i2c_new_client_device(adapter, &ix8_i2c_devices[6]);		// pca9548_4 SFP
		i2c_put_adapter(adapter);
	}

	adapter = i2c_get_adapter_wait(9);
	if (adapter == NULL)
	{
		printk("[%s] get i2c adapter fail at line %d", __FUNCTION__, __LINE__);
	}
	else
	{
		g_client[16] = i2c_new_client_device(adapter, &ix8_i2c_devices[7]);		// pca9548_5 SFP
		i2c_put_adapter(adapter);
	}

	adapter = i2c_get_adapter_wait(10);
	if (adapter == NULL)
	{
		printk("[%s] get i2c adapter fail at line %d", __FUNCTION__, __LINE__);
	}
	else
	{
		g_client[17] = i2c_new_client_device(adapter, &ix8_i2c_devices[8]);		// pca9548_6 SFP
		i2c_put_adapter(adapter);
	}

	adapter = i2c_get_adapter_wait(11);
	if (adapter == NULL)
	{
		printk("[%s] get i2c adapter fail at line %d", __FUNCTION__, __LINE__);
	}
	else
	{
		g_client[18] = i2c_new_client_device(adapter, &ix8_i2c_devices[9]);		// pca9548_7 QSFP
		i2c_put_adapter(adapter);
	}

	for(i = 65; i < 73; i ++){									// QSFP 49~56 EEPROM
		adapter = i2c_get_adapter_wait(i);
		if (adapter == NULL)
		{
			printk("[%s] get i2c adapter fail at line %d", __FUNCTION__, __LINE__);
		}
		else
		{
			g_client_port[i - 17] = i2c_new_client_device(adapter, &ix8_i2c_devices[15]);
			i2c_put_adapter(adapter);
		}
	}

	for(i = 17; i < 65; i ++){									// SFP28 1~48 EEPROM
		if (adapter == NULL)
		{
			printk("[%s] get i2c adapter fail at line %d", __FUNCTION__, __LINE__);
		}
		else
		{
			adapter = i2c_get_adapter_wait(i);
			g_client_port[i - 17] = i2c_new_client_device(adapter, &ix8_i2c_devices[20]);
			i2c_put_adapter(adapter);
		}
	}

	return 0;

fail_platform_device:
	platform_device_put(ix8_device);

fail_platform_driver:
	platform_driver_unregister(&ix8_platform_driver);
	return ret;
}