Source
x
static void moxart_rtc_write_register(struct device *dev, u8 cmd, u8 data)
/*
* MOXA ART RTC driver.
*
* Copyright (C) 2013 Jonas Jensen
*
* Jonas Jensen <jonas.jensen@gmail.com>
*
* Based on code from
* Moxa Technology Co., Ltd. <www.moxa.com>
*
* 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.
*/
struct moxart_rtc {
struct rtc_device *rtc;
spinlock_t rtc_lock;
int gpio_data, gpio_sclk, gpio_reset;
};
static int day_of_year[12] = { 0, 31, 59, 90, 120, 151, 181,
212, 243, 273, 304, 334 };
static void moxart_rtc_write_byte(struct device *dev, u8 data)
{
struct moxart_rtc *moxart_rtc = dev_get_drvdata(dev);
int i;
for (i = 0; i < 8; i++, data >>= 1) {
gpio_set_value(moxart_rtc->gpio_sclk, 0);
gpio_set_value(moxart_rtc->gpio_data, ((data & 1) == 1));
udelay(GPIO_RTC_DELAY_TIME);
gpio_set_value(moxart_rtc->gpio_sclk, 1);
udelay(GPIO_RTC_DELAY_TIME);
}
}
static u8 moxart_rtc_read_byte(struct device *dev)
{
struct moxart_rtc *moxart_rtc = dev_get_drvdata(dev);
int i;
u8 data = 0;
for (i = 0; i < 8; i++) {
gpio_set_value(moxart_rtc->gpio_sclk, 0);
udelay(GPIO_RTC_DELAY_TIME);
gpio_set_value(moxart_rtc->gpio_sclk, 1);
udelay(GPIO_RTC_DELAY_TIME);
if (gpio_get_value(moxart_rtc->gpio_data))