Exemple #1
0
static int anatop_thermal_get_calibration_data(unsigned int *fuse)
{
	int ret = -EINVAL;
	int fd;
	char fuse_data[11];

	if (fuse == NULL) {
		printk(KERN_ERR "%s: NULL pointer!\n", __func__);
		return ret;
	}

	fd = sys_open((const char __user __force *)THERMAL_FUSE_NAME,
		O_RDWR, 0700);
	if (fd < 0)
		return ret;

	sys_read(fd, fuse_data, sizeof(fuse_data));
	sys_close(fd);
	ret = 0;

	*fuse = simple_strtol(fuse_data, NULL, 0);
	pr_info("Thermal: fuse data 0x%x\n", *fuse);
	anatop_thermal_counting_ratio(*fuse);

	return ret;
}
Exemple #2
0
static int anatop_thermal_probe(struct platform_device *pdev)
{
	int retval = 0;
	struct resource *res_io, *res_irq, *res_calibration;
	void __iomem *base, *calibration_addr;
	struct anatop_device *device;

	device = kzalloc(sizeof(*device), GFP_KERNEL);
	if (!device) {
		retval = -ENOMEM;
		goto device_alloc_failed;
	}

	platform_set_drvdata(pdev, device);

	/* ioremap the base address */
	res_io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	if (res_io == NULL) {
		dev_err(&pdev->dev, "No anatop base address provided!\n");
		goto anatop_failed;
	}

	base = ioremap(res_io->start, res_io->end - res_io->start);
	if (base == NULL) {
		dev_err(&pdev->dev, "failed to remap anatop base address!\n");
		goto anatop_failed;
	}
	anatop_base = (unsigned long)base;
	/* ioremap the calibration data address */
	res_calibration = platform_get_resource(pdev, IORESOURCE_MEM, 1);
	if (res_calibration == NULL) {
		dev_err(&pdev->dev, "No anatop calibration data address provided!\n");
		goto anatop_failed;
	}

	calibration_addr = ioremap(res_calibration->start,
		res_calibration->end - res_calibration->start);
	if (calibration_addr == NULL) {
		dev_err(&pdev->dev, "failed to remap anatop calibration data address!\n");
		goto anatop_failed;
	}

	pll3_clk = clk_get(NULL, "pll3_main_clk");
	if (IS_ERR(pll3_clk)) {
		retval = -ENOENT;
		goto anatop_failed;
	}

	raw_n40c = DEFAULT_N40C;
	/* use calibration data to get ratio */
	anatop_thermal_counting_ratio(__raw_readl(calibration_addr));

	res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
	if (res_irq == NULL) {
		dev_err(&pdev->dev, "No anatop thermal irq provided!\n");
		goto anatop_failed;
	}
	retval = request_irq(res_irq->start, anatop_thermal_alarm_handler, 0, "THERMAL_ALARM_IRQ",
			  NULL);
	thermal_irq = res_irq->start;


	anatop_thermal_add(device);
	anatop_thermal_cpufreq_init();
	retval = device_create_file(&pdev->dev, &anatop_thermal_flag_dev_attr);
	if (retval)
		dev_err(&pdev->dev, "create device file failed!\n");
	pr_info("%s: default cooling device is cpufreq!\n", __func__);

	goto success;
anatop_failed:
	kfree(device);
device_alloc_failed:
success:

	return retval;
}