aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH Hartley Sweeten <hsweeten@visionengravers.com>2017-02-15 11:35:23 -0500
committerAlexandre Belloni <alexandre.belloni@free-electrons.com>2017-02-21 12:16:31 -0500
commit3ea07127d9367250321df33bf9fee2ada362400c (patch)
treea90a7ad421fda70d1d36118cc0ba1cfa11c7bf08
parentb180cf8b0bce3e0e1eb9c5d78bfc9ef2559a0b22 (diff)
rtc: m48t86: verify that the RTC is actually present
The RTC is an optional feature at purchase time on some Technologic Systems boards. Verify that it actually exists by checking if the last two bytes of the NVRAM can be changed. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
-rw-r--r--drivers/rtc/rtc-m48t86.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/drivers/rtc/rtc-m48t86.c b/drivers/rtc/rtc-m48t86.c
index 4dc4af41c03d..491e8e4b300b 100644
--- a/drivers/rtc/rtc-m48t86.c
+++ b/drivers/rtc/rtc-m48t86.c
@@ -201,6 +201,37 @@ static ssize_t m48t86_nvram_write(struct file *filp, struct kobject *kobj,
201static BIN_ATTR(nvram, 0644, m48t86_nvram_read, m48t86_nvram_write, 201static BIN_ATTR(nvram, 0644, m48t86_nvram_read, m48t86_nvram_write,
202 M48T86_NVRAM_LEN); 202 M48T86_NVRAM_LEN);
203 203
204/*
205 * The RTC is an optional feature at purchase time on some Technologic Systems
206 * boards. Verify that it actually exists by checking if the last two bytes
207 * of the NVRAM can be changed.
208 *
209 * This is based on the method used in their rtc7800.c example.
210 */
211static bool m48t86_verify_chip(struct platform_device *pdev)
212{
213 unsigned int offset0 = M48T86_NVRAM(M48T86_NVRAM_LEN - 2);
214 unsigned int offset1 = M48T86_NVRAM(M48T86_NVRAM_LEN - 1);
215 unsigned char tmp0, tmp1;
216
217 tmp0 = m48t86_readb(&pdev->dev, offset0);
218 tmp1 = m48t86_readb(&pdev->dev, offset1);
219
220 m48t86_writeb(&pdev->dev, 0x00, offset0);
221 m48t86_writeb(&pdev->dev, 0x55, offset1);
222 if (m48t86_readb(&pdev->dev, offset1) == 0x55) {
223 m48t86_writeb(&pdev->dev, 0xaa, offset1);
224 if (m48t86_readb(&pdev->dev, offset1) == 0xaa &&
225 m48t86_readb(&pdev->dev, offset0) == 0x00) {
226 m48t86_writeb(&pdev->dev, tmp0, offset0);
227 m48t86_writeb(&pdev->dev, tmp1, offset1);
228
229 return true;
230 }
231 }
232 return false;
233}
234
204static int m48t86_rtc_probe(struct platform_device *pdev) 235static int m48t86_rtc_probe(struct platform_device *pdev)
205{ 236{
206 struct m48t86_rtc_info *info; 237 struct m48t86_rtc_info *info;
@@ -231,6 +262,11 @@ static int m48t86_rtc_probe(struct platform_device *pdev)
231 262
232 dev_set_drvdata(&pdev->dev, info); 263 dev_set_drvdata(&pdev->dev, info);
233 264
265 if (!m48t86_verify_chip(pdev)) {
266 dev_info(&pdev->dev, "RTC not present\n");
267 return -ENODEV;
268 }
269
234 info->rtc = devm_rtc_device_register(&pdev->dev, "m48t86", 270 info->rtc = devm_rtc_device_register(&pdev->dev, "m48t86",
235 &m48t86_rtc_ops, THIS_MODULE); 271 &m48t86_rtc_ops, THIS_MODULE);
236 if (IS_ERR(info->rtc)) 272 if (IS_ERR(info->rtc))