rtc-88pm860x.c (9a64e8e0ace51b309fdcff4b4754b3649250382a) rtc-88pm860x.c (2e57d56747e601b3e0ff6697e524025d0504d161)
1/*
2 * Real Time Clock driver for Marvell 88PM860x PMIC
3 *
4 * Copyright (c) 2010 Marvell International Ltd.
5 * Author: Haojian Zhuang <haojian.zhuang@marvell.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/kernel.h>
13#include <linux/module.h>
1/*
2 * Real Time Clock driver for Marvell 88PM860x PMIC
3 *
4 * Copyright (c) 2010 Marvell International Ltd.
5 * Author: Haojian Zhuang <haojian.zhuang@marvell.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/of.h>
14#include <linux/platform_device.h>
15#include <linux/slab.h>
16#include <linux/mutex.h>
17#include <linux/rtc.h>
18#include <linux/delay.h>
19#include <linux/mfd/core.h>
20#include <linux/mfd/88pm860x.h>
21

--- 257 unchanged lines hidden (view full) ---

279out:
280 /* disable measurement */
281 pm860x_set_bits(info->i2c, PM8607_MEAS_EN2, MEAS2_VRTC, 0);
282 dev_dbg(info->dev, "finish VRTC calibration\n");
283 return;
284}
285#endif
286
15#include <linux/platform_device.h>
16#include <linux/slab.h>
17#include <linux/mutex.h>
18#include <linux/rtc.h>
19#include <linux/delay.h>
20#include <linux/mfd/core.h>
21#include <linux/mfd/88pm860x.h>
22

--- 257 unchanged lines hidden (view full) ---

280out:
281 /* disable measurement */
282 pm860x_set_bits(info->i2c, PM8607_MEAS_EN2, MEAS2_VRTC, 0);
283 dev_dbg(info->dev, "finish VRTC calibration\n");
284 return;
285}
286#endif
287
288#ifdef CONFIG_OF
289static int __devinit pm860x_rtc_dt_init(struct platform_device *pdev,
290 struct pm860x_rtc_info *info)
291{
292 struct device_node *np = pdev->dev.parent->of_node;
293 int ret;
294 if (!np)
295 return -ENODEV;
296 np = of_find_node_by_name(np, "rtc");
297 if (!np) {
298 dev_err(&pdev->dev, "failed to find rtc node\n");
299 return -ENODEV;
300 }
301 ret = of_property_read_u32(np, "marvell,88pm860x-vrtc", &info->vrtc);
302 if (ret)
303 info->vrtc = 0;
304 return 0;
305}
306#else
307#define pm860x_rtc_dt_init(x, y) (-1)
308#endif
309
287static int __devinit pm860x_rtc_probe(struct platform_device *pdev)
288{
289 struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
290 struct pm860x_rtc_pdata *pdata = NULL;
291 struct pm860x_rtc_info *info;
292 struct rtc_time tm;
293 unsigned long ticks = 0;
294 int ret;
295
296 pdata = pdev->dev.platform_data;
310static int __devinit pm860x_rtc_probe(struct platform_device *pdev)
311{
312 struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
313 struct pm860x_rtc_pdata *pdata = NULL;
314 struct pm860x_rtc_info *info;
315 struct rtc_time tm;
316 unsigned long ticks = 0;
317 int ret;
318
319 pdata = pdev->dev.platform_data;
297 if (pdata == NULL)
298 dev_warn(&pdev->dev, "No platform data!\n");
299
300 info = kzalloc(sizeof(struct pm860x_rtc_info), GFP_KERNEL);
301 if (!info)
302 return -ENOMEM;
303 info->irq = platform_get_irq(pdev, 0);
304 if (info->irq < 0) {
305 dev_err(&pdev->dev, "No IRQ resource!\n");
306 ret = -EINVAL;

--- 33 unchanged lines hidden (view full) ---

340 tm.tm_sec = 0;
341 ret = pm860x_rtc_set_time(&pdev->dev, &tm);
342 if (ret < 0) {
343 dev_err(&pdev->dev, "Failed to set initial time.\n");
344 goto out_rtc;
345 }
346 }
347 rtc_tm_to_time(&tm, &ticks);
320
321 info = kzalloc(sizeof(struct pm860x_rtc_info), GFP_KERNEL);
322 if (!info)
323 return -ENOMEM;
324 info->irq = platform_get_irq(pdev, 0);
325 if (info->irq < 0) {
326 dev_err(&pdev->dev, "No IRQ resource!\n");
327 ret = -EINVAL;

--- 33 unchanged lines hidden (view full) ---

361 tm.tm_sec = 0;
362 ret = pm860x_rtc_set_time(&pdev->dev, &tm);
363 if (ret < 0) {
364 dev_err(&pdev->dev, "Failed to set initial time.\n");
365 goto out_rtc;
366 }
367 }
368 rtc_tm_to_time(&tm, &ticks);
348 if (pdata && pdata->sync) {
349 pdata->sync(ticks);
350 info->sync = pdata->sync;
369 if (pm860x_rtc_dt_init(pdev, info)) {
370 if (pdata && pdata->sync) {
371 pdata->sync(ticks);
372 info->sync = pdata->sync;
373 }
351 }
352
353 info->rtc_dev = rtc_device_register("88pm860x-rtc", &pdev->dev,
354 &pm860x_rtc_ops, THIS_MODULE);
355 ret = PTR_ERR(info->rtc_dev);
356 if (IS_ERR(info->rtc_dev)) {
357 dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret);
358 goto out_rtc;
359 }
360
361 /*
362 * enable internal XO instead of internal 3.25MHz clock since it can
363 * free running in PMIC power-down state.
364 */
365 pm860x_set_bits(info->i2c, PM8607_RTC1, RTC1_USE_XO, RTC1_USE_XO);
366
367#ifdef VRTC_CALIBRATION
368 /* <00> -- 2.7V, <01> -- 2.9V, <10> -- 3.1V, <11> -- 3.3V */
374 }
375
376 info->rtc_dev = rtc_device_register("88pm860x-rtc", &pdev->dev,
377 &pm860x_rtc_ops, THIS_MODULE);
378 ret = PTR_ERR(info->rtc_dev);
379 if (IS_ERR(info->rtc_dev)) {
380 dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret);
381 goto out_rtc;
382 }
383
384 /*
385 * enable internal XO instead of internal 3.25MHz clock since it can
386 * free running in PMIC power-down state.
387 */
388 pm860x_set_bits(info->i2c, PM8607_RTC1, RTC1_USE_XO, RTC1_USE_XO);
389
390#ifdef VRTC_CALIBRATION
391 /* <00> -- 2.7V, <01> -- 2.9V, <10> -- 3.1V, <11> -- 3.3V */
369 if (pdata && pdata->vrtc)
370 info->vrtc = pdata->vrtc & 0x3;
371 else
372 info->vrtc = 1;
392 if (pm860x_rtc_dt_init(pdev, info)) {
393 if (pdata && pdata->vrtc)
394 info->vrtc = pdata->vrtc & 0x3;
395 else
396 info->vrtc = 1;
397 }
373 pm860x_set_bits(info->i2c, PM8607_MEAS_EN2, MEAS2_VRTC, MEAS2_VRTC);
374
375 /* calibrate VRTC */
376 INIT_DELAYED_WORK(&info->calib_work, calibrate_vrtc_work);
377 schedule_delayed_work(&info->calib_work, VRTC_CALIB_INTERVAL);
378#endif /* VRTC_CALIBRATION */
379
380 device_init_wakeup(&pdev->dev, 1);

--- 64 unchanged lines hidden ---
398 pm860x_set_bits(info->i2c, PM8607_MEAS_EN2, MEAS2_VRTC, MEAS2_VRTC);
399
400 /* calibrate VRTC */
401 INIT_DELAYED_WORK(&info->calib_work, calibrate_vrtc_work);
402 schedule_delayed_work(&info->calib_work, VRTC_CALIB_INTERVAL);
403#endif /* VRTC_CALIBRATION */
404
405 device_init_wakeup(&pdev->dev, 1);

--- 64 unchanged lines hidden ---