コード例 #1
0
ファイル: rtc-pcf8523.c プロジェクト: AiWinters/linux
static int pcf8523_probe(struct i2c_client *client,
			 const struct i2c_device_id *id)
{
	struct pcf8523 *pcf;
	int err;

	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
		return -ENODEV;

	pcf = devm_kzalloc(&client->dev, sizeof(*pcf), GFP_KERNEL);
	if (!pcf)
		return -ENOMEM;

	err = pcf8523_select_capacitance(client, true);
	if (err < 0)
		return err;

	err = pcf8523_set_pm(client, 0);
	if (err < 0)
		return err;

	pcf->rtc = rtc_device_register(DRIVER_NAME, &client->dev,
				       &pcf8523_rtc_ops, THIS_MODULE);
	if (IS_ERR(pcf->rtc))
		return PTR_ERR(pcf->rtc);

	i2c_set_clientdata(client, pcf);

	return 0;
}
コード例 #2
0
ファイル: rtc-pcf8523.c プロジェクト: michabs/linux-imx6-3.14
static int pcf8523_probe(struct i2c_client *client,
			 const struct i2c_device_id *id)
{
	struct pcf8523 *pcf;
	u8 value;
	int err;

	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
		return -ENODEV;

	pcf = devm_kzalloc(&client->dev, sizeof(*pcf), GFP_KERNEL);
	if (!pcf)
		return -ENOMEM;

	/* Check whether the RTC reports battery low */
	err = pcf8523_read(client, REG_CONTROL3, &value);
	if (err < 0)
		return err;

	if (value & REG_CONTROL3_BLF)
		dev_warn(&client->dev, "RTC reports battery is low\n");

	err = pcf8523_enable_oscillator(client);
	if (err < 0) {
		dev_warn(&client->dev, "RTC reports oscillator is not running\n");
		return err;
	}

	err = pcf8523_set_pm(client, 0);
	if (err < 0)
		return err;

	pcf->rtc = devm_rtc_device_register(&client->dev, DRIVER_NAME,
				       &pcf8523_rtc_ops, THIS_MODULE);
	if (IS_ERR(pcf->rtc))
		return PTR_ERR(pcf->rtc);

	i2c_set_clientdata(client, pcf);

	return 0;
}