cregit-Linux how code gets into the kernel

Release 4.14 arch/mips/lasat/ds1603.c

Directory: arch/mips/lasat
// SPDX-License-Identifier: GPL-2.0
/*
 * Dallas Semiconductors 1603 RTC driver
 *
 * Brian Murphy <brian@murphy.dk>
 *
 */
#include <linux/kernel.h>
#include <asm/lasat/lasat.h>
#include <linux/delay.h>
#include <asm/lasat/ds1603.h>
#include <asm/time.h>

#include "ds1603.h"


#define READ_TIME_CMD 0x81

#define SET_TIME_CMD 0x80

#define TRIMMER_SET_CMD 0xC0

#define TRIMMER_VALUE_MASK 0x38

#define TRIMMER_SHIFT 3


struct ds_defs *ds1603;

/* HW specific register functions */

static void rtc_reg_write(unsigned long val) { *ds1603->reg = val; }

Contributors

PersonTokensPropCommitsCommitProp
Brian Murphy17100.00%1100.00%
Total17100.00%1100.00%


static unsigned long rtc_reg_read(void) { unsigned long tmp = *ds1603->reg; return tmp; }

Contributors

PersonTokensPropCommitsCommitProp
Brian Murphy21100.00%1100.00%
Total21100.00%1100.00%


static unsigned long rtc_datareg_read(void) { unsigned long tmp = *ds1603->data_reg; return tmp; }

Contributors

PersonTokensPropCommitsCommitProp
Brian Murphy21100.00%1100.00%
Total21100.00%1100.00%


static void rtc_nrst_high(void) { rtc_reg_write(rtc_reg_read() | ds1603->rst); }

Contributors

PersonTokensPropCommitsCommitProp
Brian Murphy18100.00%1100.00%
Total18100.00%1100.00%


static void rtc_nrst_low(void) { rtc_reg_write(rtc_reg_read() & ~ds1603->rst); }

Contributors

PersonTokensPropCommitsCommitProp
Brian Murphy19100.00%1100.00%
Total19100.00%1100.00%


static void rtc_cycle_clock(unsigned long data) { data |= ds1603->clk; rtc_reg_write(data); lasat_ndelay(250); if (ds1603->data_reversed) data &= ~ds1603->data; else data |= ds1603->data; data &= ~ds1603->clk; rtc_reg_write(data); lasat_ndelay(250 + ds1603->huge_delay); }

Contributors

PersonTokensPropCommitsCommitProp
Brian Murphy67100.00%1100.00%
Total67100.00%1100.00%


static void rtc_write_databit(unsigned int bit) { unsigned long data = rtc_reg_read(); if (ds1603->data_reversed) bit = !bit; if (bit) data |= ds1603->data; else data &= ~ds1603->data; rtc_reg_write(data); lasat_ndelay(50 + ds1603->huge_delay); rtc_cycle_clock(data); }

Contributors

PersonTokensPropCommitsCommitProp
Brian Murphy65100.00%1100.00%
Total65100.00%1100.00%


static unsigned int rtc_read_databit(void) { unsigned int data; data = (rtc_datareg_read() & (1 << ds1603->data_read_shift)) >> ds1603->data_read_shift; rtc_cycle_clock(rtc_reg_read()); return data; }

Contributors

PersonTokensPropCommitsCommitProp
Brian Murphy41100.00%1100.00%
Total41100.00%1100.00%


static void rtc_write_byte(unsigned int byte) { int i; for (i = 0; i <= 7; i++) { rtc_write_databit(byte & 1L); byte >>= 1; } }

Contributors

PersonTokensPropCommitsCommitProp
Brian Murphy39100.00%1100.00%
Total39100.00%1100.00%


static void rtc_write_word(unsigned long word) { int i; for (i = 0; i <= 31; i++) { rtc_write_databit(word & 1L); word >>= 1; } }

Contributors

PersonTokensPropCommitsCommitProp
Brian Murphy39100.00%1100.00%
Total39100.00%1100.00%


static unsigned long rtc_read_word(void) { int i; unsigned long word = 0; unsigned long shift = 0; for (i = 0; i <= 31; i++) { word |= rtc_read_databit() << shift; shift++; } return word; }

Contributors

PersonTokensPropCommitsCommitProp
Brian Murphy52100.00%1100.00%
Total52100.00%1100.00%


static void rtc_init_op(void) { rtc_nrst_high(); rtc_reg_write(rtc_reg_read() & ~ds1603->clk); lasat_ndelay(50); }

Contributors

PersonTokensPropCommitsCommitProp
Brian Murphy27100.00%1100.00%
Total27100.00%1100.00%


static void rtc_end_op(void) { rtc_nrst_low(); lasat_ndelay(1000); }

Contributors

PersonTokensPropCommitsCommitProp
Brian Murphy16100.00%1100.00%
Total16100.00%1100.00%


void read_persistent_clock(struct timespec *ts) { unsigned long word; unsigned long flags; spin_lock_irqsave(&rtc_lock, flags); rtc_init_op(); rtc_write_byte(READ_TIME_CMD); word = rtc_read_word(); rtc_end_op(); spin_unlock_irqrestore(&rtc_lock, flags); ts->tv_sec = word; ts->tv_nsec = 0; }

Contributors

PersonTokensPropCommitsCommitProp
Brian Murphy4572.58%133.33%
Martin Schwidefsky1625.81%133.33%
Ralf Bächle11.61%133.33%
Total62100.00%3100.00%


int rtc_mips_set_mmss(unsigned long time) { unsigned long flags; spin_lock_irqsave(&rtc_lock, flags); rtc_init_op(); rtc_write_byte(SET_TIME_CMD); rtc_write_word(time); rtc_end_op(); spin_unlock_irqrestore(&rtc_lock, flags); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Brian Murphy4797.92%150.00%
Ralf Bächle12.08%150.00%
Total48100.00%2100.00%


void ds1603_set_trimmer(unsigned int trimval) { rtc_init_op(); rtc_write_byte(((trimval << TRIMMER_SHIFT) & TRIMMER_VALUE_MASK) | (TRIMMER_SET_CMD)); rtc_end_op(); }

Contributors

PersonTokensPropCommitsCommitProp
Brian Murphy32100.00%1100.00%
Total32100.00%1100.00%


void ds1603_disable(void) { ds1603_set_trimmer(TRIMMER_DISABLE_RTC); }

Contributors

PersonTokensPropCommitsCommitProp
Brian Murphy12100.00%1100.00%
Total12100.00%1100.00%


void ds1603_enable(void) { ds1603_set_trimmer(TRIMMER_DEFAULT); }

Contributors

PersonTokensPropCommitsCommitProp
Brian Murphy12100.00%1100.00%
Total12100.00%1100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
Brian Murphy63597.09%125.00%
Martin Schwidefsky162.45%125.00%
Ralf Bächle20.31%125.00%
Greg Kroah-Hartman10.15%125.00%
Total654100.00%4100.00%
Directory: arch/mips/lasat
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.