[PATCH] rtc: Add RTC class driver for the Maxim MAX6900
From: Dale Farnsworth <[EMAIL PROTECTED]> Signed-off-by: Dale Farnsworth.org <[EMAIL PROTECTED] --- drivers/rtc/Kconfig | 10 + drivers/rtc/Makefile |1 drivers/rtc/rtc-max6900.c | 312 3 files changed, 323 insertions(+) Index: linux-2.6-powerpc-df/drivers/rtc/Kconfig === --- linux-2.6-powerpc-df.orig/drivers/rtc/Kconfig +++ linux-2.6-powerpc-df/drivers/rtc/Kconfig @@ -334,6 +334,16 @@ config RTC_DRV_TEST This driver can also be built as a module. If so, the module will be called rtc-test. +config RTC_DRV_MAX6900 + tristate "Maxim 6900" + depends on RTC_CLASS && I2C + help + If you say yes here you will get support for the + Maxim MAX6900 I2C RTC chip. + + This driver can also be built as a module. If so, the module + will be called rtc-max6900. + config RTC_DRV_MAX6902 tristate "Maxim 6902" depends on RTC_CLASS && SPI Index: linux-2.6-powerpc-df/drivers/rtc/Makefile === --- linux-2.6-powerpc-df.orig/drivers/rtc/Makefile +++ linux-2.6-powerpc-df/drivers/rtc/Makefile @@ -34,6 +34,7 @@ obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93 obj-$(CONFIG_RTC_DRV_SA1100) += rtc-sa1100.o obj-$(CONFIG_RTC_DRV_VR41XX) += rtc-vr41xx.o obj-$(CONFIG_RTC_DRV_PL031)+= rtc-pl031.o +obj-$(CONFIG_RTC_DRV_MAX6900) += rtc-max6900.o obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o obj-$(CONFIG_RTC_DRV_V3020)+= rtc-v3020.o obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o Index: linux-2.6-powerpc-df/drivers/rtc/rtc-max6900.c === --- /dev/null +++ linux-2.6-powerpc-df/drivers/rtc/rtc-max6900.c @@ -0,0 +1,312 @@ +/* + * rtc class driver for the Maxim MAX6900 chip + * + * Author: Dale Farnsworth <[EMAIL PROTECTED]> + * + * based on previously existing rtc class drivers + * + * 2007 (c) MontaVista, Software, Inc. This file is licensed under + * the terms of the GNU General Public License version 2. This program + * is licensed "as is" without any warranty of any kind, whether express + * or implied. + */ + +#include +#include +#include +#include +#include + +#define DRV_NAME "max6900" +#define DRV_VERSION "0.1" + +/* + * register indices + */ +#define MAX6900_REG_SC 0 /* seconds 00-59 */ +#define MAX6900_REG_MN 1 /* minutes 00-59 */ +#define MAX6900_REG_HR 2 /* hours00-23 */ +#define MAX6900_REG_DT 3 /* day of month 00-31 */ +#define MAX6900_REG_MO 4 /* month01-12 */ +#define MAX6900_REG_DW 5 /* day of week 1-7 */ +#define MAX6900_REG_YR 6 /* year 00-99 */ +#define MAX6900_REG_CT 7 /* control */ +#define MAX6900_REG_LEN8 + +#define MAX6900_REG_CT_WP (1 << 7)/* Write Protect */ + +/* + * register read/write commands + */ +#define MAX6900_REG_CONTROL_WRITE 0x8e +#define MAX6900_REG_BURST_READ 0xbf +#define MAX6900_REG_BURST_WRITE0xbe +#define MAX6900_REG_RESERVED_READ 0x96 + +#define MAX6900_IDLE_TIME_AFTER_WRITE 3 /* specification says 2.5 mS */ + +#define MAX6900_I2C_ADDR 0xa0 + +static unsigned short normal_i2c[] = { + MAX6900_I2C_ADDR >> 1, + I2C_CLIENT_END +}; + +I2C_CLIENT_INSMOD; /* defines addr_data */ + +static int max6900_probe(struct i2c_adapter *adapter, int addr, int kind); + +static int max6900_i2c_read_regs(struct i2c_client *client, u8 *buf) +{ + u8 reg_addr[1] = { MAX6900_REG_BURST_READ }; + struct i2c_msg msgs[2] = { + { + client->addr, + 0, /* write */ + sizeof(reg_addr), + reg_addr + }, + { + client->addr, + I2C_M_RD, + MAX6900_REG_LEN, + buf + } + }; + int rc; + + rc = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); + if (rc != ARRAY_SIZE(msgs)) { + dev_err(>dev, "%s: register read failed\n", + __FUNCTION__); + return -EIO; + } + return 0; +} + +static int max6900_i2c_write_regs(struct i2c_client *client, u8 const *buf) +{ + u8 i2c_buf[MAX6900_REG_LEN + 1] = { MAX6900_REG_BURST_WRITE }; + struct i2c_msg msgs[1] = { + { + client->addr, + 0, /* write */ + MAX6900_REG_LEN + 1, + i2c_buf + } + }; + int rc; + + memcpy(_buf[1], buf, MAX6900_REG_LEN); + +
[PATCH] rtc: Add RTC class driver for the Maxim MAX6900
From: Dale Farnsworth [EMAIL PROTECTED] Signed-off-by: Dale Farnsworth.org [EMAIL PROTECTED] --- drivers/rtc/Kconfig | 10 + drivers/rtc/Makefile |1 drivers/rtc/rtc-max6900.c | 312 3 files changed, 323 insertions(+) Index: linux-2.6-powerpc-df/drivers/rtc/Kconfig === --- linux-2.6-powerpc-df.orig/drivers/rtc/Kconfig +++ linux-2.6-powerpc-df/drivers/rtc/Kconfig @@ -334,6 +334,16 @@ config RTC_DRV_TEST This driver can also be built as a module. If so, the module will be called rtc-test. +config RTC_DRV_MAX6900 + tristate Maxim 6900 + depends on RTC_CLASS I2C + help + If you say yes here you will get support for the + Maxim MAX6900 I2C RTC chip. + + This driver can also be built as a module. If so, the module + will be called rtc-max6900. + config RTC_DRV_MAX6902 tristate Maxim 6902 depends on RTC_CLASS SPI Index: linux-2.6-powerpc-df/drivers/rtc/Makefile === --- linux-2.6-powerpc-df.orig/drivers/rtc/Makefile +++ linux-2.6-powerpc-df/drivers/rtc/Makefile @@ -34,6 +34,7 @@ obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93 obj-$(CONFIG_RTC_DRV_SA1100) += rtc-sa1100.o obj-$(CONFIG_RTC_DRV_VR41XX) += rtc-vr41xx.o obj-$(CONFIG_RTC_DRV_PL031)+= rtc-pl031.o +obj-$(CONFIG_RTC_DRV_MAX6900) += rtc-max6900.o obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o obj-$(CONFIG_RTC_DRV_V3020)+= rtc-v3020.o obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o Index: linux-2.6-powerpc-df/drivers/rtc/rtc-max6900.c === --- /dev/null +++ linux-2.6-powerpc-df/drivers/rtc/rtc-max6900.c @@ -0,0 +1,312 @@ +/* + * rtc class driver for the Maxim MAX6900 chip + * + * Author: Dale Farnsworth [EMAIL PROTECTED] + * + * based on previously existing rtc class drivers + * + * 2007 (c) MontaVista, Software, Inc. This file is licensed under + * the terms of the GNU General Public License version 2. This program + * is licensed as is without any warranty of any kind, whether express + * or implied. + */ + +#include linux/module.h +#include linux/i2c.h +#include linux/bcd.h +#include linux/rtc.h +#include linux/delay.h + +#define DRV_NAME max6900 +#define DRV_VERSION 0.1 + +/* + * register indices + */ +#define MAX6900_REG_SC 0 /* seconds 00-59 */ +#define MAX6900_REG_MN 1 /* minutes 00-59 */ +#define MAX6900_REG_HR 2 /* hours00-23 */ +#define MAX6900_REG_DT 3 /* day of month 00-31 */ +#define MAX6900_REG_MO 4 /* month01-12 */ +#define MAX6900_REG_DW 5 /* day of week 1-7 */ +#define MAX6900_REG_YR 6 /* year 00-99 */ +#define MAX6900_REG_CT 7 /* control */ +#define MAX6900_REG_LEN8 + +#define MAX6900_REG_CT_WP (1 7)/* Write Protect */ + +/* + * register read/write commands + */ +#define MAX6900_REG_CONTROL_WRITE 0x8e +#define MAX6900_REG_BURST_READ 0xbf +#define MAX6900_REG_BURST_WRITE0xbe +#define MAX6900_REG_RESERVED_READ 0x96 + +#define MAX6900_IDLE_TIME_AFTER_WRITE 3 /* specification says 2.5 mS */ + +#define MAX6900_I2C_ADDR 0xa0 + +static unsigned short normal_i2c[] = { + MAX6900_I2C_ADDR 1, + I2C_CLIENT_END +}; + +I2C_CLIENT_INSMOD; /* defines addr_data */ + +static int max6900_probe(struct i2c_adapter *adapter, int addr, int kind); + +static int max6900_i2c_read_regs(struct i2c_client *client, u8 *buf) +{ + u8 reg_addr[1] = { MAX6900_REG_BURST_READ }; + struct i2c_msg msgs[2] = { + { + client-addr, + 0, /* write */ + sizeof(reg_addr), + reg_addr + }, + { + client-addr, + I2C_M_RD, + MAX6900_REG_LEN, + buf + } + }; + int rc; + + rc = i2c_transfer(client-adapter, msgs, ARRAY_SIZE(msgs)); + if (rc != ARRAY_SIZE(msgs)) { + dev_err(client-dev, %s: register read failed\n, + __FUNCTION__); + return -EIO; + } + return 0; +} + +static int max6900_i2c_write_regs(struct i2c_client *client, u8 const *buf) +{ + u8 i2c_buf[MAX6900_REG_LEN + 1] = { MAX6900_REG_BURST_WRITE }; + struct i2c_msg msgs[1] = { + { + client-addr, + 0, /* write */ + MAX6900_REG_LEN + 1, + i2c_buf + } + }; + int rc; + +