From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752833AbcEDLxb (ORCPT ); Wed, 4 May 2016 07:53:31 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:35186 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750714AbcEDLxa (ORCPT ); Wed, 4 May 2016 07:53:30 -0400 Date: Wed, 4 May 2016 13:51:45 +0200 From: Marcus Folkesson To: venkat.prashanth2498@gmail.com Cc: linux-kernel@vger.kernel.org Subject: Re: [PATCH] rtc:add support for maxim rtc max6916 Message-ID: <20160504115145.GA10802@gmail.com> References: <1462357817-11133-1-git-send-email-venkat.prashanth2498@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="AqsLC8rIMeq19msA" Content-Disposition: inline In-Reply-To: <1462357817-11133-1-git-send-email-venkat.prashanth2498@gmail.com> User-Agent: Mutt/1.6.0 (2016-04-01) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --AqsLC8rIMeq19msA Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, May 04, 2016 at 03:30:17AM -0700, venkat.prashanth2498@gmail.com wr= ote: > From: venkat-prashanth >=20 > This is a patch to add support for > maxim rtc max6916 > Signed-off-by:Venkat Prashanth B U > --- > Kconfig | 9 ++++ > Makefile | 6 +++ > rtc-max6916.c | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++++ > 3 files changed, 148 insertions(+) > create mode 100644 Kconfig > create mode 100644 Makefile > create mode 100644 rtc-max6916.c > diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig > new file mode 100644 > index 0000000..fa7a2fa > --- a/drivers/rtc/Kconfig > +++ b/drivers/rtc/Kconfig > @@ -0,0 +1,9 @@ > +config RTC_DRV_MAX6916 > +tristate "Maxim MAX6916" > + help > + If you say yes here you get support for the > + Maxim MAX6916 chips. > + This driver only supports the RTC feature, and not other chip > + features such as alarms. > + This driver can also be built as a module. If so, the module > + will be called rtc=E2=80=90max6916. > diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile > new file mode 100644 > index 0000000..db34a02 > --- a/drivers/rtc/Makefile > +++ b/drivers/rtc/Makefile > @@ -0,0 +1,6 @@ > +CONFIG_MODULE_SIG=3Dn > +obj-m+=3Drtc-max6916.o > +all: > + make -C /lib/modules/$(shell uname -r)/build M=3D$(PWD) modules > +clean: > + make -C /lib/modules/$(shell uname -r)/build M=3D$(PWD) clean Something is wrong here. Kconfig and Makefile should really not be created, and the Makefile seems like an out-of-tree-Makefile? Clone a proper working tree and look how it should be written. > + * > + */ > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +/* Registers in max6916 rtc */ > +#define MAX6916_SECONDS_REG 0x01 > +#define MAX6916_MINUTES_REG 0x02 > +#define MAX6916_HOURS_REG 0x03 > +#define MAX6916_DATE_REG 0x04 > +#define MAX6916_MONTH_REG 0x05 > +static int max6916_read_time(struct device *dev, struct rtc_time *dt) > +{ > + struct spi_device *spi =3D to_spi_device(dev); > + int err; > + unsigned char buf[8]; > + > + buf[0] =3D MAX6916_CLOCK_BURST | 0x80; > + err =3D spi_write_then_read(spi, buf, 1, buf, 8); > + if (err) > + return err; > + dt->tm_sec =3D bcd2bin(buf[0]); > + dt->tm_min =3D bcd2bin(buf[1]); > + dt->tm_hour =3D bcd2bin(buf[2] & MAX6916_CLOCK_BURST); > + dt->tm_mday =3D bcd2bin(buf[3]); > + dt->tm_mon =3D bcd2bin(buf[4]) - 1; > + dt->tm_wday =3D bcd2bin(buf[5]) - 1; > + dt->tm_year =3D bcd2bin(buf[6]) + 100; > + return rtc_valid_tm(dt); > +} > +static int max6916_set_time(struct device *dev, struct rtc_time *dt) > +{ > + struct spi_device *spi =3D to_spi_device(dev); > + unsigned char buf[9]; > + > + buf[0] =3D MAX6916_CLOCK_BURST & 0x7F; > + buf[1] =3D bcd2bin(dt->tm_sec); > + buf[2] =3D bcd2bin(dt->tm_min); > + buf[3] =3D (bcd2bin(dt->tm_hour)&MAX6916_CLOCK_BURST); > + buf[4] =3D bcd2bin(dt->tm_mday); > + buf[5] =3D bcd2bin(dt->tm_mon + 1); > + buf[6] =3D bcd2bin(dt->tm_wday + 1); > + /* year from 1900-range of 100 in rtc from 00 to 99 */ > + dt->tm_year =3D dt->tm_year % 100; > + buf[7] =3D bcd2bin(dt->tm_year); > + buf[8] =3D bcd2bin(0x00); > + /* write the rtc settings */ > + return spi_write_then_read(spi, buf, 9, NULL, 0); > +} > +static const struct rtc_class_ops max6916_rtc_ops =3D { > + .read_time =3D max6916_read_time, > + .set_time =3D max6916_set_time, > +}; > +static int max6916_probe(struct spi_device *spi) > +{ > + struct rtc_device *rtc; > + unsigned char data; > + int res; > + > + /* spi setup with max6916 in mode 3 and bits per word as 8 */ > + spi->mode =3D SPI_MODE_3; > + spi->bits_per_word =3D 8; > + spi_setup(spi); > + /* RTC Settings */ > + res =3D max6916_read_reg(&spi->dev, MAX6916_SECONDS_REG, &data); > + if (res) > + return res; > + /* Disable the write protect of rtc */ > + max6916_read_reg(&spi->dev, MAX6916_CONTROL_REG, &data); > + data =3D data & ~(1<<7); > + max6916_write_reg(&spi->dev, MAX6916_CONTROL_REG, data); > + /* Enable the oscillator,disable the oscillator stop flag,and glitch fi= lter to reduce current consumption */ > + max6916_read_reg(&spi->dev, MAX6916_STATUS_REG, &data); > + data =3D data & 0x1B; > + max6916_write_reg(&spi->dev, MAX6916_STATUS_REG, data); > + /* display the settings */ > + max6916_read_reg(&spi->dev, MAX6916_CONTROL_REG, &data); > + dev_info(&spi->dev, "MAX6916 RTC CTRL Reg =3D 0x%02x\n", data); > + max6916_read_reg(&spi->dev, MAX6916_STATUS_REG, &data); > + dev_info(&spi->dev, "MAX6916 RTC Status Reg =3D 0x%02x\n", data); > + rtc =3D devm_rtc_device_register(&spi->dev, "max6916", &max6916_rtc_ops= , THIS_MODULE); > + if (IS_ERR(rtc)) > + return PTR_ERR(rtc); > + spi_set_drvdata(spi, rtc); > + return 0; > +} > +static struct spi_driver max6916_driver =3D { > + .driver =3D { > + .name =3D "max6916", > + }, > + .probe =3D max6916_probe, > +}; > +module_spi_driver(max6916_driver); > +MODULE_DESCRIPTION("MAX6916 SPI RTC DRIVER"); > +MODULE_AUTHOR("Venkat Prashanth B U "); > +MODULE_LICENSE("GPL v2"); An overall comment, the patch is hard to parse. Please seperate logical code sections with an empty line and use indentation after if-statements. Cheers, Marcus Folkesson > --=20 > 1.9.2 >=20 --AqsLC8rIMeq19msA Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJXKeJNAAoJEJIKs6my3IBoRVYH/iBDZx6Wxr/J/gAP9IE1l7de zR1NQs0X8rSuDZcK5A7FOaA96sxSVfTzp5BPxB+fqOlMOlxKuKWH+gphHaxC7vn8 XZxzUjlY3dJ5E+5TlbPoR4gNcEbkUvV5nxcG30Gg5tusO5kq1McQ/E845gFDR2sC CJvAJ3joxe+dyt1InXobzqYC3yXpGIZWuBxfj9r7ucDnySm+zVmxdfQWpj1CVPyz Fu886SrIzg4XsEjnYYXw4RzGNsg8iSEWE1rUoCgzbHvE7lpUph3+whVcjO9jl4Bz Fzhxf+0aCPP7WfU40u9qdCdGd16eBYFs2Z1LnRa1qb5mnp/GbLSinlmfSK1pG1k= =V3Nk -----END PGP SIGNATURE----- --AqsLC8rIMeq19msA--