Commit 572e6179adb5447ff42ec2aa5cf3a26decf97583

Authored by Detlev Zundel
Committed by Wolfgang Denk
1 parent 88685b5f62

drivers/twserial: Add protocol driver for "three wire serial" interface.

This pretty unintelligent interface is used on some RTC chips.

Signed-off-by: Detlev Zundel <dzu@denx.de>

Showing 4 changed files with 197 additions and 1 deletions Side-by-side Diff

1 1 #
2   -# (C) Copyright 2000-2008
  2 +# (C) Copyright 2000-2009
3 3 # Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 4 #
5 5 # See file CREDITS for list of people who contributed to this
... ... @@ -262,6 +262,7 @@
262 262 endif
263 263 LIBS += drivers/rtc/librtc.a
264 264 LIBS += drivers/serial/libserial.a
  265 +LIBS += drivers/twserial/libtws.a
265 266 LIBS += drivers/usb/libusb.a
266 267 LIBS += drivers/video/libvideo.a
267 268 LIBS += common/libcommon.a
drivers/twserial/Makefile
  1 +#
  2 +# (C) Copyright 2009
  3 +# Detlev Zundel, DENX Software Engineering, dzu@denx.de.
  4 +#
  5 +# See file CREDITS for list of people who contributed to this
  6 +# project.
  7 +#
  8 +# This program is free software; you can redistribute it and/or
  9 +# modify it under the terms of the GNU General Public License as
  10 +# published by the Free Software Foundation; either version 2 of
  11 +# the License, or (at your option) any later version.
  12 +#
  13 +# This program is distributed in the hope that it will be useful,
  14 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16 +# GNU General Public License for more details.
  17 +#
  18 +# You should have received a copy of the GNU General Public License
  19 +# along with this program; if not, write to the Free Software
  20 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21 +# MA 02111-1307 USA
  22 +#
  23 +
  24 +include $(TOPDIR)/config.mk
  25 +
  26 +LIB := $(obj)libtws.a
  27 +
  28 +COBJS-$(CONFIG_SOFT_TWS) += soft_tws.o
  29 +
  30 +COBJS := $(COBJS-y)
  31 +SRCS := $(COBJS:.o=.c)
  32 +OBJS := $(addprefix $(obj),$(COBJS))
  33 +
  34 +all: $(LIB)
  35 +
  36 +$(LIB): $(obj).depend $(OBJS)
  37 + $(AR) $(ARFLAGS) $@ $(OBJS)
  38 +
  39 +#########################################################################
  40 +
  41 +# defines $(obj).depend target
  42 +include $(SRCTREE)/rules.mk
  43 +
  44 +sinclude $(obj).depend
  45 +
  46 +#########################################################################
drivers/twserial/soft_tws.c
  1 +/*
  2 + * (C) Copyright 2009
  3 + * Detlev Zundel, DENX Software Engineering, dzu@denx.de.
  4 + *
  5 + * See file CREDITS for list of people who contributed to this
  6 + * project.
  7 + *
  8 + * This program is free software; you can redistribute it and/or
  9 + * modify it under the terms of the GNU General Public License as
  10 + * published by the Free Software Foundation; either version 2 of
  11 + * the License, or (at your option) any later version.
  12 + *
  13 + * This program is distributed in the hope that it will be useful,
  14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16 + * GNU General Public License for more details.
  17 + *
  18 + * You should have received a copy of the GNU General Public License
  19 + * along with this program; if not, write to the Free Software
  20 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21 + * MA 02111-1307 USA
  22 + *
  23 + */
  24 +
  25 +#define TWS_IMPLEMENTATION
  26 +#include <common.h>
  27 +
  28 +/*=====================================================================*/
  29 +/* Public Functions */
  30 +/*=====================================================================*/
  31 +
  32 +/*-----------------------------------------------------------------------
  33 + * Read bits
  34 + */
  35 +int tws_read(uchar *buffer, int len)
  36 +{
  37 + int rem = len;
  38 + uchar accu, shift;
  39 +
  40 + debug("tws_read: buffer %p len %d\n", buffer, len);
  41 +
  42 + /* Configure the data pin for input */
  43 + tws_data_config_output(0);
  44 +
  45 + /* Disable WR, i.e. setup a read */
  46 + tws_wr(0);
  47 + udelay(1);
  48 +
  49 + /* Rise CE */
  50 + tws_ce(1);
  51 + udelay(1);
  52 +
  53 + for (; rem > 0; ) {
  54 + for (shift = 0, accu = 0;
  55 + (rem > 0) && (shift < 8);
  56 + rem--, shift++) {
  57 + tws_clk(1);
  58 + udelay(10);
  59 + accu |= (tws_data_read() << shift); /* LSB first */
  60 + tws_clk(0);
  61 + udelay(10);
  62 + }
  63 + *buffer++ = accu;
  64 + }
  65 +
  66 + /* Lower CE */
  67 + tws_ce(0);
  68 +
  69 + return len - rem;
  70 +}
  71 +
  72 +
  73 +/*-----------------------------------------------------------------------
  74 + * Write bits
  75 + */
  76 +int tws_write(uchar *buffer, int len)
  77 +{
  78 + int rem = len;
  79 + uchar accu, shift;
  80 +
  81 + debug("tws_write: buffer %p len %d\n", buffer, len);
  82 +
  83 + /* Configure the data pin for output */
  84 + tws_data_config_output(1);
  85 +
  86 + /* Enable WR, i.e. setup a write */
  87 + tws_wr(1);
  88 + udelay(1);
  89 +
  90 + /* Rise CE */
  91 + tws_ce(1);
  92 + udelay(1);
  93 +
  94 + for (; rem > 0; ) {
  95 + for (shift = 0, accu = *buffer++;
  96 + (rem > 0) && (shift < 8);
  97 + rem--, shift++) {
  98 + tws_data(accu & 0x01); /* LSB first */
  99 + tws_clk(1);
  100 + udelay(10);
  101 + tws_clk(0);
  102 + udelay(10);
  103 + accu >>= 1;
  104 + }
  105 + }
  106 +
  107 + /* Lower CE */
  108 + tws_ce(0);
  109 +
  110 + return len - rem;
  111 +}
  1 +/*
  2 + * (C) Copyright 2009
  3 + * Detlev Zundel, DENX Software Engineering, dzu@denx.de.
  4 + *
  5 + * See file CREDITS for list of people who contributed to this
  6 + * project.
  7 + *
  8 + * This program is free software; you can redistribute it and/or
  9 + * modify it under the terms of the GNU General Public License as
  10 + * published by the Free Software Foundation; either version 2 of
  11 + * the License, or (at your option) any later version.
  12 + *
  13 + * This program is distributed in the hope that it will be useful,
  14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16 + * GNU General Public License for more details.
  17 + *
  18 + * You should have received a copy of the GNU General Public License
  19 + * along with this program; if not, write to the Free Software
  20 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21 + * MA 02111-1307 USA
  22 + *
  23 + */
  24 +
  25 +#ifndef _TWS_H_
  26 +#define _TWS_H_
  27 +
  28 +/*
  29 + * Read/Write interface:
  30 + * buffer: Where to read/write the data
  31 + * len: How many bits to read/write
  32 + *
  33 + * Returns: 0 on success, not 0 on failure
  34 + */
  35 +int tws_read(uchar *buffer, int len);
  36 +int tws_write(uchar *buffer, int len);
  37 +
  38 +#endif /* _TWS_H_ */