mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-11 12:28:41 +08:00
rtc: bd70528: Do not require parent data
The ROHM BD71828 and BD71815 RTC drivers only need the regmap pointer from parent. Regmap can be obtained via dev_get_regmap() so do not require parent to populate driver data for that. BD70528 on the other hand requires parent data to access the watchdog so leave the parent data for BD70528 here for now. Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com> Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Lee Jones <lee.jones@linaro.org>
This commit is contained in:
parent
a38fd87484
commit
f87c0d2e6c
@ -52,6 +52,7 @@ struct bd70528_rtc_alm {
|
|||||||
|
|
||||||
struct bd70528_rtc {
|
struct bd70528_rtc {
|
||||||
struct rohm_regmap_dev *parent;
|
struct rohm_regmap_dev *parent;
|
||||||
|
struct regmap *regmap;
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
u8 reg_time_start;
|
u8 reg_time_start;
|
||||||
bool has_rtc_timers;
|
bool has_rtc_timers;
|
||||||
@ -234,9 +235,8 @@ static int bd71828_set_alarm(struct device *dev, struct rtc_wkalrm *a)
|
|||||||
int ret;
|
int ret;
|
||||||
struct bd71828_rtc_alm alm;
|
struct bd71828_rtc_alm alm;
|
||||||
struct bd70528_rtc *r = dev_get_drvdata(dev);
|
struct bd70528_rtc *r = dev_get_drvdata(dev);
|
||||||
struct rohm_regmap_dev *parent = r->parent;
|
|
||||||
|
|
||||||
ret = regmap_bulk_read(parent->regmap, BD71828_REG_RTC_ALM_START,
|
ret = regmap_bulk_read(r->regmap, BD71828_REG_RTC_ALM_START,
|
||||||
&alm, sizeof(alm));
|
&alm, sizeof(alm));
|
||||||
if (ret) {
|
if (ret) {
|
||||||
dev_err(dev, "Failed to read alarm regs\n");
|
dev_err(dev, "Failed to read alarm regs\n");
|
||||||
@ -250,7 +250,7 @@ static int bd71828_set_alarm(struct device *dev, struct rtc_wkalrm *a)
|
|||||||
else
|
else
|
||||||
alm.alm_mask |= BD70528_MASK_ALM_EN;
|
alm.alm_mask |= BD70528_MASK_ALM_EN;
|
||||||
|
|
||||||
ret = regmap_bulk_write(parent->regmap, BD71828_REG_RTC_ALM_START,
|
ret = regmap_bulk_write(r->regmap, BD71828_REG_RTC_ALM_START,
|
||||||
&alm, sizeof(alm));
|
&alm, sizeof(alm));
|
||||||
if (ret)
|
if (ret)
|
||||||
dev_err(dev, "Failed to set alarm time\n");
|
dev_err(dev, "Failed to set alarm time\n");
|
||||||
@ -265,17 +265,16 @@ static int bd70528_set_alarm(struct device *dev, struct rtc_wkalrm *a)
|
|||||||
struct bd70528_rtc_alm alm;
|
struct bd70528_rtc_alm alm;
|
||||||
int ret;
|
int ret;
|
||||||
struct bd70528_rtc *r = dev_get_drvdata(dev);
|
struct bd70528_rtc *r = dev_get_drvdata(dev);
|
||||||
struct rohm_regmap_dev *parent = r->parent;
|
|
||||||
|
|
||||||
ret = regmap_bulk_read(parent->regmap, BD70528_REG_RTC_WAKE_START,
|
ret = regmap_bulk_read(r->regmap, BD70528_REG_RTC_WAKE_START, &wake,
|
||||||
&wake, sizeof(wake));
|
sizeof(wake));
|
||||||
if (ret) {
|
if (ret) {
|
||||||
dev_err(dev, "Failed to read wake regs\n");
|
dev_err(dev, "Failed to read wake regs\n");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = regmap_bulk_read(parent->regmap, BD70528_REG_RTC_ALM_START,
|
ret = regmap_bulk_read(r->regmap, BD70528_REG_RTC_ALM_START, &alm,
|
||||||
&alm, sizeof(alm));
|
sizeof(alm));
|
||||||
if (ret) {
|
if (ret) {
|
||||||
dev_err(dev, "Failed to read alarm regs\n");
|
dev_err(dev, "Failed to read alarm regs\n");
|
||||||
return ret;
|
return ret;
|
||||||
@ -292,15 +291,14 @@ static int bd70528_set_alarm(struct device *dev, struct rtc_wkalrm *a)
|
|||||||
wake.ctrl &= ~BD70528_MASK_WAKE_EN;
|
wake.ctrl &= ~BD70528_MASK_WAKE_EN;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = regmap_bulk_write(parent->regmap,
|
ret = regmap_bulk_write(r->regmap, BD70528_REG_RTC_WAKE_START, &wake,
|
||||||
BD70528_REG_RTC_WAKE_START, &wake,
|
|
||||||
sizeof(wake));
|
sizeof(wake));
|
||||||
if (ret) {
|
if (ret) {
|
||||||
dev_err(dev, "Failed to set wake time\n");
|
dev_err(dev, "Failed to set wake time\n");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
ret = regmap_bulk_write(parent->regmap, BD70528_REG_RTC_ALM_START,
|
ret = regmap_bulk_write(r->regmap, BD70528_REG_RTC_ALM_START, &alm,
|
||||||
&alm, sizeof(alm));
|
sizeof(alm));
|
||||||
if (ret)
|
if (ret)
|
||||||
dev_err(dev, "Failed to set alarm time\n");
|
dev_err(dev, "Failed to set alarm time\n");
|
||||||
|
|
||||||
@ -312,9 +310,8 @@ static int bd71828_read_alarm(struct device *dev, struct rtc_wkalrm *a)
|
|||||||
int ret;
|
int ret;
|
||||||
struct bd71828_rtc_alm alm;
|
struct bd71828_rtc_alm alm;
|
||||||
struct bd70528_rtc *r = dev_get_drvdata(dev);
|
struct bd70528_rtc *r = dev_get_drvdata(dev);
|
||||||
struct rohm_regmap_dev *parent = r->parent;
|
|
||||||
|
|
||||||
ret = regmap_bulk_read(parent->regmap, BD71828_REG_RTC_ALM_START,
|
ret = regmap_bulk_read(r->regmap, BD71828_REG_RTC_ALM_START,
|
||||||
&alm, sizeof(alm));
|
&alm, sizeof(alm));
|
||||||
if (ret) {
|
if (ret) {
|
||||||
dev_err(dev, "Failed to read alarm regs\n");
|
dev_err(dev, "Failed to read alarm regs\n");
|
||||||
@ -336,10 +333,9 @@ static int bd70528_read_alarm(struct device *dev, struct rtc_wkalrm *a)
|
|||||||
struct bd70528_rtc_alm alm;
|
struct bd70528_rtc_alm alm;
|
||||||
int ret;
|
int ret;
|
||||||
struct bd70528_rtc *r = dev_get_drvdata(dev);
|
struct bd70528_rtc *r = dev_get_drvdata(dev);
|
||||||
struct rohm_regmap_dev *parent = r->parent;
|
|
||||||
|
|
||||||
ret = regmap_bulk_read(parent->regmap, BD70528_REG_RTC_ALM_START,
|
ret = regmap_bulk_read(r->regmap, BD70528_REG_RTC_ALM_START, &alm,
|
||||||
&alm, sizeof(alm));
|
sizeof(alm));
|
||||||
if (ret) {
|
if (ret) {
|
||||||
dev_err(dev, "Failed to read alarm regs\n");
|
dev_err(dev, "Failed to read alarm regs\n");
|
||||||
return ret;
|
return ret;
|
||||||
@ -360,14 +356,12 @@ static int bd70528_set_time_locked(struct device *dev, struct rtc_time *t)
|
|||||||
int ret, tmpret, old_states;
|
int ret, tmpret, old_states;
|
||||||
struct bd70528_rtc_data rtc_data;
|
struct bd70528_rtc_data rtc_data;
|
||||||
struct bd70528_rtc *r = dev_get_drvdata(dev);
|
struct bd70528_rtc *r = dev_get_drvdata(dev);
|
||||||
struct rohm_regmap_dev *parent = r->parent;
|
|
||||||
|
|
||||||
ret = bd70528_disable_rtc_based_timers(r, &old_states);
|
ret = bd70528_disable_rtc_based_timers(r, &old_states);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
tmpret = regmap_bulk_read(parent->regmap,
|
tmpret = regmap_bulk_read(r->regmap, r->reg_time_start, &rtc_data,
|
||||||
r->reg_time_start, &rtc_data,
|
|
||||||
sizeof(rtc_data));
|
sizeof(rtc_data));
|
||||||
if (tmpret) {
|
if (tmpret) {
|
||||||
dev_err(dev, "Failed to read RTC time registers\n");
|
dev_err(dev, "Failed to read RTC time registers\n");
|
||||||
@ -375,8 +369,7 @@ static int bd70528_set_time_locked(struct device *dev, struct rtc_time *t)
|
|||||||
}
|
}
|
||||||
tm2rtc(t, &rtc_data);
|
tm2rtc(t, &rtc_data);
|
||||||
|
|
||||||
tmpret = regmap_bulk_write(parent->regmap,
|
tmpret = regmap_bulk_write(r->regmap, r->reg_time_start, &rtc_data,
|
||||||
r->reg_time_start, &rtc_data,
|
|
||||||
sizeof(rtc_data));
|
sizeof(rtc_data));
|
||||||
if (tmpret) {
|
if (tmpret) {
|
||||||
dev_err(dev, "Failed to set RTC time\n");
|
dev_err(dev, "Failed to set RTC time\n");
|
||||||
@ -410,13 +403,11 @@ static int bd70528_set_time(struct device *dev, struct rtc_time *t)
|
|||||||
static int bd70528_get_time(struct device *dev, struct rtc_time *t)
|
static int bd70528_get_time(struct device *dev, struct rtc_time *t)
|
||||||
{
|
{
|
||||||
struct bd70528_rtc *r = dev_get_drvdata(dev);
|
struct bd70528_rtc *r = dev_get_drvdata(dev);
|
||||||
struct rohm_regmap_dev *parent = r->parent;
|
|
||||||
struct bd70528_rtc_data rtc_data;
|
struct bd70528_rtc_data rtc_data;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* read the RTC date and time registers all at once */
|
/* read the RTC date and time registers all at once */
|
||||||
ret = regmap_bulk_read(parent->regmap,
|
ret = regmap_bulk_read(r->regmap, r->reg_time_start, &rtc_data,
|
||||||
r->reg_time_start, &rtc_data,
|
|
||||||
sizeof(rtc_data));
|
sizeof(rtc_data));
|
||||||
if (ret) {
|
if (ret) {
|
||||||
dev_err(dev, "Failed to read RTC time (err %d)\n", ret);
|
dev_err(dev, "Failed to read RTC time (err %d)\n", ret);
|
||||||
@ -443,7 +434,7 @@ static int bd70528_alm_enable(struct device *dev, unsigned int enabled)
|
|||||||
dev_err(dev, "Failed to change wake state\n");
|
dev_err(dev, "Failed to change wake state\n");
|
||||||
goto out_unlock;
|
goto out_unlock;
|
||||||
}
|
}
|
||||||
ret = regmap_update_bits(r->parent->regmap, BD70528_REG_RTC_ALM_MASK,
|
ret = regmap_update_bits(r->regmap, BD70528_REG_RTC_ALM_MASK,
|
||||||
BD70528_MASK_ALM_EN, enableval);
|
BD70528_MASK_ALM_EN, enableval);
|
||||||
if (ret)
|
if (ret)
|
||||||
dev_err(dev, "Failed to change alarm state\n");
|
dev_err(dev, "Failed to change alarm state\n");
|
||||||
@ -462,7 +453,7 @@ static int bd71828_alm_enable(struct device *dev, unsigned int enabled)
|
|||||||
if (!enabled)
|
if (!enabled)
|
||||||
enableval = 0;
|
enableval = 0;
|
||||||
|
|
||||||
ret = regmap_update_bits(r->parent->regmap, BD71828_REG_RTC_ALM0_MASK,
|
ret = regmap_update_bits(r->regmap, BD71828_REG_RTC_ALM0_MASK,
|
||||||
BD70528_MASK_ALM_EN, enableval);
|
BD70528_MASK_ALM_EN, enableval);
|
||||||
if (ret)
|
if (ret)
|
||||||
dev_err(dev, "Failed to change alarm state\n");
|
dev_err(dev, "Failed to change alarm state\n");
|
||||||
@ -498,7 +489,6 @@ static int bd70528_probe(struct platform_device *pdev)
|
|||||||
{
|
{
|
||||||
struct bd70528_rtc *bd_rtc;
|
struct bd70528_rtc *bd_rtc;
|
||||||
const struct rtc_class_ops *rtc_ops;
|
const struct rtc_class_ops *rtc_ops;
|
||||||
struct rohm_regmap_dev *parent;
|
|
||||||
const char *irq_name;
|
const char *irq_name;
|
||||||
int ret;
|
int ret;
|
||||||
struct rtc_device *rtc;
|
struct rtc_device *rtc;
|
||||||
@ -508,20 +498,25 @@ static int bd70528_probe(struct platform_device *pdev)
|
|||||||
u8 hour_reg;
|
u8 hour_reg;
|
||||||
enum rohm_chip_type chip = platform_get_device_id(pdev)->driver_data;
|
enum rohm_chip_type chip = platform_get_device_id(pdev)->driver_data;
|
||||||
|
|
||||||
parent = dev_get_drvdata(pdev->dev.parent);
|
|
||||||
if (!parent) {
|
|
||||||
dev_err(&pdev->dev, "No MFD driver data\n");
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
bd_rtc = devm_kzalloc(&pdev->dev, sizeof(*bd_rtc), GFP_KERNEL);
|
bd_rtc = devm_kzalloc(&pdev->dev, sizeof(*bd_rtc), GFP_KERNEL);
|
||||||
if (!bd_rtc)
|
if (!bd_rtc)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
bd_rtc->parent = parent;
|
bd_rtc->regmap = dev_get_regmap(pdev->dev.parent, NULL);
|
||||||
|
if (!bd_rtc->regmap) {
|
||||||
|
dev_err(&pdev->dev, "No regmap\n");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
bd_rtc->dev = &pdev->dev;
|
bd_rtc->dev = &pdev->dev;
|
||||||
|
|
||||||
switch (chip) {
|
switch (chip) {
|
||||||
case ROHM_CHIP_TYPE_BD70528:
|
case ROHM_CHIP_TYPE_BD70528:
|
||||||
|
bd_rtc->parent = dev_get_drvdata(pdev->dev.parent);
|
||||||
|
if (!bd_rtc->parent) {
|
||||||
|
dev_err(&pdev->dev, "No MFD data\n");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
irq_name = "bd70528-rtc-alm";
|
irq_name = "bd70528-rtc-alm";
|
||||||
bd_rtc->has_rtc_timers = true;
|
bd_rtc->has_rtc_timers = true;
|
||||||
bd_rtc->reg_time_start = BD70528_REG_RTC_START;
|
bd_rtc->reg_time_start = BD70528_REG_RTC_START;
|
||||||
@ -547,7 +542,7 @@ static int bd70528_probe(struct platform_device *pdev)
|
|||||||
|
|
||||||
platform_set_drvdata(pdev, bd_rtc);
|
platform_set_drvdata(pdev, bd_rtc);
|
||||||
|
|
||||||
ret = regmap_read(parent->regmap, hour_reg, &hr);
|
ret = regmap_read(bd_rtc->regmap, hour_reg, &hr);
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
dev_err(&pdev->dev, "Failed to reag RTC clock\n");
|
dev_err(&pdev->dev, "Failed to reag RTC clock\n");
|
||||||
@ -595,7 +590,7 @@ static int bd70528_probe(struct platform_device *pdev)
|
|||||||
* from sub-registers when IRQ is disabled or freed.
|
* from sub-registers when IRQ is disabled or freed.
|
||||||
*/
|
*/
|
||||||
if (enable_main_irq) {
|
if (enable_main_irq) {
|
||||||
ret = regmap_update_bits(parent->regmap,
|
ret = regmap_update_bits(bd_rtc->regmap,
|
||||||
BD70528_REG_INT_MAIN_MASK,
|
BD70528_REG_INT_MAIN_MASK,
|
||||||
BD70528_INT_RTC_MASK, 0);
|
BD70528_INT_RTC_MASK, 0);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
Loading…
Reference in New Issue
Block a user