コード例 #1
0
/**
 * mid_thermal_probe - mfld thermal initialize
 * @pdev: platform device structure
 *
 * mid thermal probe initializes the hardware and registers
 * all the sensors with the generic thermal framework. Can sleep.
 */
static int mid_thermal_probe(struct platform_device *pdev)
{
	static char *name[MSIC_THERMAL_SENSORS] = {
		"skin0", "skin1", "sys", "msicdie"
	};

	int ret;
	int i;
	struct platform_info *pinfo;

	pinfo = kzalloc(sizeof(struct platform_info), GFP_KERNEL);
	if (!pinfo)
		return -ENOMEM;

	/* Initializing the hardware */
	ret = mid_initialize_adc(&pdev->dev);
	if (ret) {
		dev_err(&pdev->dev, "ADC init failed");
		kfree(pinfo);
		return ret;
	}

	/* Register each sensor with the generic thermal framework*/
	for (i = 0; i < MSIC_THERMAL_SENSORS; i++) {
		struct thermal_device_info *td_info = initialize_sensor(i);

		if (!td_info) {
			ret = -ENOMEM;
			goto err;
		}
		pinfo->tzd[i] = thermal_zone_device_register(name[i],
				0, 0, td_info, &tzd_ops, NULL, 0, 0);
		if (IS_ERR(pinfo->tzd[i])) {
			kfree(td_info);
			ret = PTR_ERR(pinfo->tzd[i]);
			goto err;
		}
	}

	pinfo->pdev = pdev;
	platform_set_drvdata(pdev, pinfo);
	return 0;

err:
	while (--i >= 0) {
		kfree(pinfo->tzd[i]->devdata);
		thermal_zone_device_unregister(pinfo->tzd[i]);
	}
	configure_adc(0);
	kfree(pinfo);
	return ret;
}
コード例 #2
0
/**
 * mid_thermal_probe - mfld thermal initialize
 * @ipcdev: ipc device structure
 *
 * mid thermal probe initializes the hardware and registers
 * all the sensors with the generic thermal framework. Can sleep.
 */
static int mid_thermal_probe(struct ipc_device *ipcdev)
{
	int ret;
	int i;
	ipcinfo = kzalloc(sizeof(struct ipc_info), GFP_KERNEL);
	if (!ipcinfo)
		return -ENOMEM;

	/* initialize mutex locks */
	mutex_init(&ipcinfo->cacheinfo.lock);

#ifdef CONFIG_BOARD_CTP
	/* Allocate ADC channels for all sensors */
	ipcinfo->therm_adc_handle = intel_mid_gpadc_alloc(MSIC_THERMAL_SENSORS,
					0x04 | CH_NEED_VREF | CH_NEED_VCALIB,
					0x04 | CH_NEED_VREF | CH_NEED_VCALIB,
					0x03 | CH_NEED_VCALIB,
					0x09 | CH_NEED_VREF | CH_NEED_VCALIB);
#else
	/* Allocate ADC channels for all sensors */
	ipcinfo->therm_adc_handle = intel_mid_gpadc_alloc(MSIC_THERMAL_SENSORS,
					0x08 | CH_NEED_VREF | CH_NEED_VCALIB,
					0x08 | CH_NEED_VREF | CH_NEED_VCALIB,
					0x0A | CH_NEED_VREF | CH_NEED_VCALIB,
					0x03 | CH_NEED_VCALIB);
#endif
	if (!ipcinfo->therm_adc_handle) {
		ret = -ENOMEM;
		goto alloc_fail;
	}

	/* Register each sensor with the generic thermal framework*/
	for (i = 0; i < MSIC_THERMAL_SENSORS; i++) {
		ipcinfo->tzd[i] = thermal_zone_device_register(name[i],
					0, 0, initialize_sensor(i),
					&tzd_ops, 0, 0, 0, 0);
		if (IS_ERR(ipcinfo->tzd[i]))
			goto reg_fail;
	}

	ipcinfo->ipcdev = ipcdev;
	ipc_set_drvdata(ipcdev, ipcinfo);
	return 0;

reg_fail:
	ret = PTR_ERR(ipcinfo->tzd[i]);
	while (--i >= 0)
		thermal_zone_device_unregister(ipcinfo->tzd[i]);
alloc_fail:
	kfree(ipcinfo);
	return ret;
}