Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rtc: pm8xxx: add support for devicetree

Add support for describing the PM8921/PM8058 RTC in device tree.

Additionally:
- drop support for describing the RTC using platform data,
as there are no current in tree users who do so.
- make allow_set_time a device-specific flag, instead of mucking
with the rtc_ops

Signed-off-by: Josh Cartwright <joshc@codeaurora.org>
Reviewed-by: Stephen Boyd <sboyd@codeaurora.org>
Acked-by: Lee Jones <lee.jones@linaro.org>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Josh Cartwright and committed by
Linus Torvalds
5a418558 bffcbc08

+29 -48
+29 -23
drivers/rtc/rtc-pm8xxx.c
··· 9 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 10 * GNU General Public License for more details. 11 11 */ 12 - 12 + #include <linux/of.h> 13 13 #include <linux/module.h> 14 14 #include <linux/init.h> 15 15 #include <linux/rtc.h> ··· 18 18 #include <linux/regmap.h> 19 19 #include <linux/slab.h> 20 20 #include <linux/spinlock.h> 21 - 22 - #include <linux/mfd/pm8xxx/rtc.h> 23 - 24 21 25 22 /* RTC Register offsets from RTC CTRL REG */ 26 23 #define PM8XXX_ALARM_CTRL_OFFSET 0x01 ··· 36 39 * struct pm8xxx_rtc - rtc driver internal structure 37 40 * @rtc: rtc device for this driver. 38 41 * @regmap: regmap used to access RTC registers 42 + * @allow_set_time: indicates whether writing to the RTC is allowed 39 43 * @rtc_alarm_irq: rtc alarm irq number. 40 44 * @rtc_base: address of rtc control register. 41 45 * @rtc_read_base: base address of read registers. ··· 49 51 struct pm8xxx_rtc { 50 52 struct rtc_device *rtc; 51 53 struct regmap *regmap; 54 + bool allow_set_time; 52 55 int rtc_alarm_irq; 53 56 int rtc_base; 54 57 int rtc_read_base; ··· 73 74 unsigned long secs, irq_flags; 74 75 u8 value[NUM_8_BIT_RTC_REGS], alarm_enabled = 0, ctrl_reg; 75 76 struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev); 77 + 78 + if (!rtc_dd->allow_set_time) 79 + return -EACCES; 76 80 77 81 rtc_tm_to_time(tm, &secs); 78 82 ··· 300 298 return rc; 301 299 } 302 300 303 - static struct rtc_class_ops pm8xxx_rtc_ops = { 301 + static const struct rtc_class_ops pm8xxx_rtc_ops = { 304 302 .read_time = pm8xxx_rtc_read_time, 303 + .set_time = pm8xxx_rtc_set_time, 305 304 .set_alarm = pm8xxx_rtc_set_alarm, 306 305 .read_alarm = pm8xxx_rtc_read_alarm, 307 306 .alarm_irq_enable = pm8xxx_rtc_alarm_irq_enable, ··· 356 353 return IRQ_HANDLED; 357 354 } 358 355 356 + /* 357 + * Hardcoded RTC bases until IORESOURCE_REG mapping is figured out 358 + */ 359 + static const struct of_device_id pm8xxx_id_table[] = { 360 + { .compatible = "qcom,pm8921-rtc", .data = (void *) 0x11D }, 361 + { .compatible = "qcom,pm8058-rtc", .data = (void *) 0x1E8 }, 362 + { }, 363 + }; 364 + MODULE_DEVICE_TABLE(of, pm8xxx_id_table); 365 + 359 366 static int pm8xxx_rtc_probe(struct platform_device *pdev) 360 367 { 361 368 int rc; 362 369 unsigned int ctrl_reg; 363 - bool rtc_write_enable = false; 364 370 struct pm8xxx_rtc *rtc_dd; 365 - struct resource *rtc_resource; 366 - const struct pm8xxx_rtc_platform_data *pdata = 367 - dev_get_platdata(&pdev->dev); 371 + const struct of_device_id *match; 368 372 369 - if (pdata != NULL) 370 - rtc_write_enable = pdata->rtc_write_enable; 373 + match = of_match_node(pm8xxx_id_table, pdev->dev.of_node); 374 + if (!match) 375 + return -ENXIO; 371 376 372 377 rtc_dd = devm_kzalloc(&pdev->dev, sizeof(*rtc_dd), GFP_KERNEL); 373 378 if (rtc_dd == NULL) ··· 396 385 return -ENXIO; 397 386 } 398 387 399 - rtc_resource = platform_get_resource_byname(pdev, IORESOURCE_IO, 400 - "pmic_rtc_base"); 401 - if (!(rtc_resource && rtc_resource->start)) { 402 - dev_err(&pdev->dev, "RTC IO resource absent!\n"); 403 - return -ENXIO; 404 - } 388 + rtc_dd->allow_set_time = of_property_read_bool(pdev->dev.of_node, 389 + "allow-set-time"); 405 390 406 - rtc_dd->rtc_base = rtc_resource->start; 391 + rtc_dd->rtc_base = (long) match->data; 407 392 408 393 /* Setup RTC register addresses */ 409 394 rtc_dd->rtc_write_base = rtc_dd->rtc_base + PM8XXX_RTC_WRITE_OFFSET; ··· 426 419 } 427 420 428 421 rtc_dd->ctrl_reg = ctrl_reg; 429 - if (rtc_write_enable) 430 - pm8xxx_rtc_ops.set_time = pm8xxx_rtc_set_time; 431 422 432 423 platform_set_drvdata(pdev, rtc_dd); 433 424 ··· 484 479 static struct platform_driver pm8xxx_rtc_driver = { 485 480 .probe = pm8xxx_rtc_probe, 486 481 .driver = { 487 - .name = PM8XXX_RTC_DEV_NAME, 488 - .owner = THIS_MODULE, 489 - .pm = &pm8xxx_rtc_pm_ops, 482 + .name = "rtc-pm8xxx", 483 + .owner = THIS_MODULE, 484 + .pm = &pm8xxx_rtc_pm_ops, 485 + .of_match_table = pm8xxx_id_table, 490 486 }, 491 487 }; 492 488
-25
include/linux/mfd/pm8xxx/rtc.h
··· 1 - /* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved. 2 - * 3 - * This program is free software; you can redistribute it and/or modify 4 - * it under the terms of the GNU General Public License version 2 and 5 - * only version 2 as published by the Free Software Foundation. 6 - * 7 - * This program is distributed in the hope that it will be useful, 8 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 - * GNU General Public License for more details. 11 - */ 12 - 13 - #ifndef __RTC_PM8XXX_H__ 14 - #define __RTC_PM8XXX_H__ 15 - 16 - #define PM8XXX_RTC_DEV_NAME "rtc-pm8xxx" 17 - /** 18 - * struct pm8xxx_rtc_pdata - RTC driver platform data 19 - * @rtc_write_enable: variable stating RTC write capability 20 - */ 21 - struct pm8xxx_rtc_platform_data { 22 - bool rtc_write_enable; 23 - }; 24 - 25 - #endif /* __RTC_PM8XXX_H__ */