Received: by 10.223.164.202 with SMTP id h10csp4207983wrb; Wed, 29 Nov 2017 02:47:08 -0800 (PST) X-Google-Smtp-Source: AGs4zMaPHXzixDR3LG4wI0b/QrcgSrShzXMoruC+rRhGwYIHeGLlYSY6o1bIpZj75v9LcIqqsMBG X-Received: by 10.99.37.4 with SMTP id l4mr2431826pgl.88.1511952428765; Wed, 29 Nov 2017 02:47:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511952428; cv=none; d=google.com; s=arc-20160816; b=mskvdWG0WHYtIS6f5HKTCOBG+2UwImiwhqW+6xu5+Tb/CrJ8gts7xZjHCNj3EcJRMi 7IVz3Idj3BznBnMKtgXlVjYRrNbtuQbN8kcXTm4fc4eOmEXWmXsBLIEj2fIdd8aDeKvA 6Z9L+dw5C7udKozXY28qOOL4QjV4bTY5vEtaNZ6w5RzidLV/RwrFNaQ8aPAq3d3f9Sae ZQYlOlXvJds4HlOJJhBy7ASb6OSSAlRL4VDZaDk15ZEPpYadfjRt5YARNwRUX3snNqQk fAx1I7Xaqjzg7dW8Q16V//Dai5PrDGbjRLW9L2O/C/5JvQiBfRHXZfAD3Jn1iMAJntAU u+9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=SUxJO/BcEEilvLHKfpEKQ/jiqMC7UddnNHCwnp2SVaE=; b=JULlRGXXfM6pqOh0xL6lVDiGPckxH7WTK9szsZt1zMG0nvCSFSWvKKP9eEAOJIiOPr 5s7Ch5fKQoWCINI5X03pl9YzPJrdVL8hL0Ip/Nyb4RV00o0yMF5B576WOx+a6AyfoJkY BAqQzUboXTry8c8rSrVuTia2FYg/JdDNVxL7mngNJEMGtVjx2DWSM5SpLcaYqKP61lkF 6K4EavPfIwLl5LOscDBdZfqHNAWVV7TzvhZdul7HBowgPOdgjvn6Bz2rfQLfOe7PYCVI AAl8oSassAWfm8KeRpodlxQ0UPN77KAw6qAYNRolFU4QkXPQa0YCs1GIuJGGxykyXcA0 GRWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=B15Z5gSV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p89si1154876pfd.36.2017.11.29.02.46.58; Wed, 29 Nov 2017 02:47:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=B15Z5gSV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754405AbdK2Kpb (ORCPT + 70 others); Wed, 29 Nov 2017 05:45:31 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:36733 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752170AbdK2Kp2 (ORCPT ); Wed, 29 Nov 2017 05:45:28 -0500 Received: by mail-pf0-f195.google.com with SMTP id p84so1377232pfd.3 for ; Wed, 29 Nov 2017 02:45:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=SUxJO/BcEEilvLHKfpEKQ/jiqMC7UddnNHCwnp2SVaE=; b=B15Z5gSVobRn7d8LgA/Uw5Hv7WfG+dSexpn4WEv8Wb3NzRCVH7PwFPpyU69RZG/PhA X175IbT3M6Pi7waO0RG86BoJfoQPl+zD4EkdR2JdylOaIB3d9JviYaTMXlAbBbSNBKT1 U73TgJGju4qAW1gpFnEGltatxjLJHbVpJgVZfct+JZNawMjm53NlYmhOrh1tH3qlRaKG 2DCgrw+gUgTNBHyzVp0lzmRE/8jYHGpOO+w7s0uaIkMv+EN47SsjlAaM7PGmUdtMexIn 4aUuyXRMm8FfGt/K6eAKEszS1upePgPN07n9bmdP5+Zr9pIuUUEVaK6Xp/iLMmTvbRtz Z1Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=SUxJO/BcEEilvLHKfpEKQ/jiqMC7UddnNHCwnp2SVaE=; b=VKJBOASqJ85ZByduZ+Pxzbk8JS73i4X8Smz2FnMshKbWovVSWMzEUFBsOLNGG1yGek a1UfWwEG592aTUCe6BAN9DSQCaMGyk/i7Q4/Xk7Y3+vefS5aeB/WgrR4mXI/RCcIT2gw DLVVpQoYpc8X4qTosabIWs+59zjEM+SzNuNWMYDNqjfZDNVTmTAC5jrq5lQCbKfiwFz5 qQXU2qX9qtnDqFgKlmRxczIm2a5ssAqEGrZPvdWLxYNlcb8X+852QKupm1a+JTnk4pE6 LZQLQ1+fkEgG3uSjHmQxFrkLQV/qqmgzW4iRoiiimQyDpbrPaNF7Hk9XruF1+//VL4Nv TC3w== X-Gm-Message-State: AJaThX6lCD6mwVyFmzDew6jvDLix0wYkyTXaKlu3cLIb0kHtnWo16Exi 8qdzq7zui2q8kVBk14rZ4fbOyw== X-Received: by 10.98.238.8 with SMTP id e8mr2519368pfi.23.1511952328216; Wed, 29 Nov 2017 02:45:28 -0800 (PST) Received: from km1.krizna.com ([183.82.119.88]) by smtp.gmail.com with ESMTPSA id n24sm2987545pfi.33.2017.11.29.02.45.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 29 Nov 2017 02:45:27 -0800 (PST) From: venkat.prashanth2498@gmail.com To: a.zummo@towertech.it, alexandre.belloni@free-electrons.com Cc: rtc-linux@googlegroups.com, linux-kernel@vger.kernel.org, kumba@gentoo.org, Venkat Prashanth B U Subject: [PATCH] rtc: rtc-ds1683 Maxim/Dallas I2C compatible Date: Wed, 29 Nov 2017 16:15:22 +0530 Message-Id: <1511952322-5609-1-git-send-email-venkat.prashanth2498@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Venkat Prashanth B U This is a patch to add support for maxim/dallas I2C rtc ds1683 chip. Signed-off-by: Venkat Prashanth B U --- drivers/rtc/Kconfig | 9 +++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-ds1683.c | 203 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 213 insertions(+) diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index e0e58f3..2528b79 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -294,6 +294,15 @@ config RTC_DRV_DS1672 This driver can also be built as a module. If so, the module will be called rtc-ds1672. +config RTC_DRV_DS1683 + tristate "Dallas/Maxim DS1683" + help + If you say yes here you get support for the + Dallas/Maxim DS1683 I2C timekeeping chip. + + This driver can also be built as a module. If so, the module + will be called rtc-ds1683. + config RTC_DRV_HYM8563 tristate "Haoyu Microelectronics HYM8563" depends on OF diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index 0bf1fc0..a6f4419 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile @@ -62,6 +62,7 @@ obj-$(CONFIG_RTC_DRV_DS1390) += rtc-ds1390.o obj-$(CONFIG_RTC_DRV_DS1511) += rtc-ds1511.o obj-$(CONFIG_RTC_DRV_DS1553) += rtc-ds1553.o obj-$(CONFIG_RTC_DRV_DS1672) += rtc-ds1672.o +obj-$(CONFIG_RTC_DRV_DS1683) += rtc-ds1683.o obj-$(CONFIG_RTC_DRV_DS1685_FAMILY) += rtc-ds1685.o obj-$(CONFIG_RTC_DRV_DS1742) += rtc-ds1742.o obj-$(CONFIG_RTC_DRV_DS2404) += rtc-ds2404.o diff --git a/drivers/rtc/rtc-ds1683.c b/drivers/rtc/rtc-ds1683.c index e69de29..7b6dac3 100644 --- a/drivers/rtc/rtc-ds1683.c +++ b/drivers/rtc/rtc-ds1683.c @@ -0,0 +1,203 @@ +/* rtc-ds1683.c + * + * Driver for Maxim/Dallas ds1683, I2C Compatible + * Real Time Clock + * + * Author : Venkat Prashanth B U + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ + +#include +#include +#include + +/* Registers */ + +#define ds1683_REG_CNT_BASE 0 +#define ds1683_REG_EVENT 4 + +#define ds1683_REG_CONTROL_EOSC 0x80 + +static struct i2c_driver ds1683_driver; + +static int ds1683_get_datetime(struct i2c_client *client, struct rtc_time *tm) +{ + unsigned long time; + unsigned char addr = ds1683_REG_CNT_BASE; + unsigned char buf[4]; + + struct i2c_msg msgs[] = { + { /* setup read pointer */ + .addr = client->addr, + .len = 1, + .buf = &addr + }, + {/* read date */ + .addr = client->addr, + .flags = I2C_M_RD, + .len = 4, + .buf = buf + }, + }; + + /* read date registers */ + if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { + dev_err(&client->dev, "%s: read error\n", __func__); + return -EIO; + } + + time = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; + + rtc_time_to_tm(time, tm); + + return 0; +} + +static int ds1683_set_mmss(struct i2c_client *client, unsigned long secs) +{ + int xfer; + unsigned char buf[6]; + + buf[0] = ds1683_REG_CNT_BASE; + buf[1] = secs & 0x000000FF; + buf[2] = (secs & 0x0000FF00) >> 8; + buf[3] = (secs & 0x00FF0000) >> 16; + buf[4] = (secs & 0xFF000000) >> 24; + buf[5] = 0; /* set control reg to enable counting */ + + xfer = i2c_master_send(client, buf, 6); + if (xfer != 6) { + dev_err(&client->dev, "%s: send: %d\n", __func__, xfer); + return -EIO; + } + + return 0; +} + +static int ds1683_rtc_read_time(struct device *dev, struct rtc_time *tm) +{ + return ds1683_get_datetime(to_i2c_client(dev), tm); +} + +static int ds1683_rtc_set_mmss(struct device *dev, unsigned long secs) +{ + return ds1683_set_mmss(to_i2c_client(dev), secs); +} + +static int ds1683_get_control(struct i2c_client *client, u8 *status) +{ + unsigned char addr = ds1683_REG_CONTROL; + + struct i2c_msg msgs[] = { + {/* setup read pointer */ + .addr = client->addr, + .len = 1, + .buf = &addr + }, + {/* read control */ + .addr = client->addr, + .flags = I2C_M_RD, + .len = 1, + .buf = status + }, + }; + + /* read control register */ + if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { + dev_err(&client->dev, "%s: read error\n", __func__); + return -EIO; + } + + return 0; +} + +/* sysfs callback functions */ +static ssize_t show_control(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct i2c_client *client = to_i2c_client(dev); + u8 control; + int err; + + err = ds1683_get_control(client, &control); + if (err) + return err; + + return sprintf(buf, "%s\n", (control & ds1683_REG_CONTROL_EOSC) + ? "disabled" : "enabled"); +} + +static DEVICE_ATTR(control, 0444, show_control, NULL); + +static const struct rtc_class_ops ds1683_rtc_ops = { + .read_time = ds1683_rtc_read_time, + .set_mmss = ds1683_rtc_set_mmss, +}; + +static int ds1683_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + int err = 0; + u8 control; + struct rtc_device *rtc; + + dev_dbg(&client->dev, "%s\n", __func__); + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) + return -ENODEV; + + rtc = devm_rtc_device_register(&client->dev, ds1683_driver.driver.name, + &ds1683_rtc_ops, THIS_MODULE); + + if (IS_ERR(rtc)) + return PTR_ERR(rtc); + + i2c_set_clientdata(client, rtc); + + /* read control register */ + err = ds1683_get_control(client, &control); + if (err) + dev_warn(&client->dev, "Unable to read the control register\n"); + + if (control & ds1683_REG_CONTROL_EOSC) + dev_warn(&client->dev, "Oscillator not enabled Set time to enable.\n"); + + /* Register sysfs hooks */ + err = device_create_file(&client->dev, &dev_attr_control); + if (err) + dev_err(&client->dev, "Unable to create sysfs entry: %s\n", + dev_attr_control.attr.name); + + return 0; +} + +static const struct i2c_device_id ds1683_id[] = { + { "ds1683", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, ds1683_id); + +static const struct of_device_id ds1683_of_match[] = { + { "dallas,ds1683", 0 }, + { } +}; +MODULE_DEVICE_TABLE(of, ds1683_of_match); + +static struct i2c_driver ds1683_driver = { + .driver = { + .name = "rtc-ds1683", + .of_match_table = of_match_ptr(ds1683_of_match), + }, + .probe = &ds1683_probe, + .id_table = ds1683_id, +}; + +module_i2c_driver(ds1683_driver); + +MODULE_AUTHOR("Venkat Prashanth B U "); +MODULE_DESCRIPTION("Dallas/Maxim ds1683 I2C driver"); +MODULE_LICENSE("GPL"); -- 1.9.1 From 1585397025098195658@xxx Wed Nov 29 10:47:04 +0000 2017 X-GM-THRID: 1583312994983533232 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread