Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- uchcom.c.bak Fri Nov 15 19:17:39 2013
- +++ uchcom.c Sun May 11 06:15:20 2014
- @@ -48,9 +48,10 @@
- #include <dev/usb/usbdevs.h>
- #include <dev/usb/ucomvar.h>
- +#define UCHCOM_DEBUG
- #ifdef UCHCOM_DEBUG
- #define DPRINTFN(n, x) do { if (uchcomdebug > (n)) printf x; } while (0)
- -int uchcomdebug = 0;
- +int uchcomdebug = 3;
- #else
- #define DPRINTFN(n, x)
- #endif
- @@ -72,7 +73,7 @@ int uchcomdebug = 0;
- #define UCHCOM_REG_STAT2 0x07
- #define UCHCOM_REG_BPS_PRE 0x12
- #define UCHCOM_REG_BPS_DIV 0x13
- -#define UCHCOM_REG_BPS_MOD 0x14
- +#define UCHCOM_REG_BPS_MOD 0x2C
- #define UCHCOM_REG_BPS_PAD 0x0F
- #define UCHCOM_REG_BREAK1 0x05
- #define UCHCOM_REG_BREAK2 0x18
- @@ -81,9 +82,8 @@ int uchcomdebug = 0;
- #define UCHCOM_VER_20 0x20
- -#define UCHCOM_BASE_UNKNOWN 0
- -#define UCHCOM_BPS_MOD_BASE 20000000
- -#define UCHCOM_BPS_MOD_BASE_OFS 1100
- +#define UCHCOM_BAUDBASE_FACTOR 1532620800
- +#define UCHCOM_BAUDBASE_DIVMAX 3
- #define UCHCOM_DTR_MASK 0x20
- #define UCHCOM_RTS_MASK 0x40
- @@ -142,24 +142,6 @@ struct uchcom_divider
- uint8_t dv_mod;
- };
- -struct uchcom_divider_record
- -{
- - uint32_t dvr_high;
- - uint32_t dvr_low;
- - uint32_t dvr_base_clock;
- - struct uchcom_divider dvr_divider;
- -};
- -
- -static const struct uchcom_divider_record dividers[] =
- -{
- - { 307200, 307200, UCHCOM_BASE_UNKNOWN, { 7, 0xD9, 0 } },
- - { 921600, 921600, UCHCOM_BASE_UNKNOWN, { 7, 0xF3, 0 } },
- - { 2999999, 23530, 6000000, { 3, 0, 0 } },
- - { 23529, 2942, 750000, { 2, 0, 0 } },
- - { 2941, 368, 93750, { 1, 0, 0 } },
- - { 367, 1, 11719, { 0, 0, 0 } },
- -};
- -
- void uchcom_get_status(void *, int, u_char *, u_char *);
- void uchcom_set(void *, int, int, int);
- int uchcom_param(void *, int, struct termios *);
- @@ -259,6 +241,7 @@ uchcom_attach(struct device *parent, struct device *se
- struct ucom_attach_args uca;
- struct usbd_device *dev = uaa->device;
- struct uchcom_endpoints endpoints;
- + usbd_status err;
- sc->sc_udev = dev;
- sc->sc_dtr = sc->sc_rts = -1;
- @@ -300,7 +283,15 @@ uchcom_attach(struct device *parent, struct device *se
- uca.methods = &uchcom_methods;
- uca.arg = sc;
- uca.info = NULL;
- -
- +
- + err = uchcom_setup_comm(sc);
- + if (err) {
- + printf("%s: setup failed, %s\n", sc->sc_dev.dv_xname,
- + usbd_errstr(err));
- + usbd_deactivate(sc->sc_udev);
- + return;
- + }
- +
- sc->sc_subdev = config_found_sm(self, &uca, ucomprint, ucomsubmatch);
- return;
- @@ -645,39 +636,26 @@ uchcom_set_break(struct uchcom_softc *sc, int onoff)
- int
- uchcom_calc_divider_settings(struct uchcom_divider *dp, uint32_t rate)
- {
- - int i;
- - const struct uchcom_divider_record *rp;
- - uint32_t div, rem, mod;
- + uint32_t factor, prescaler;
- - /* find record */
- - for (i=0; i<nitems(dividers); i++) {
- - if (dividers[i].dvr_high >= rate &&
- - dividers[i].dvr_low <= rate) {
- - rp = ÷rs[i];
- - goto found;
- - }
- - }
- - return -1;
- + if (!rate)
- + return -1;
- -found:
- - dp->dv_prescaler = rp->dvr_divider.dv_prescaler;
- - if (rp->dvr_base_clock == UCHCOM_BASE_UNKNOWN)
- - dp->dv_div = rp->dvr_divider.dv_div;
- - else {
- - div = rp->dvr_base_clock / rate;
- - rem = rp->dvr_base_clock % rate;
- - if (div==0 || div>=0xFF)
- - return -1;
- - if ((rem<<1) >= rate)
- - div += 1;
- - dp->dv_div = (uint8_t)-div;
- + factor = UCHCOM_BAUDBASE_FACTOR / rate;
- + prescaler = UCHCOM_BAUDBASE_DIVMAX;
- +
- + while ((factor > 0xfff0) && prescaler) {
- + factor >>= 3;
- + prescaler--;
- }
- + if (factor > 0xfff0)
- + return -1;
- - mod = UCHCOM_BPS_MOD_BASE/rate + UCHCOM_BPS_MOD_BASE_OFS;
- - mod = mod + mod/2;
- + factor = 0x10000 - factor;
- + dp->dv_prescaler = prescaler;
- + dp->dv_div = (factor & 0xff00) >> 8;
- + dp->dv_mod = factor & 0xff;
- - dp->dv_mod = mod / 0x100;
- -
- return 0;
- }
- @@ -859,6 +837,10 @@ uchcom_setup_comm(struct uchcom_softc *sc)
- if (ret)
- return ret;
- + ret = uchcom_read_status(sc, NULL);
- + if (ret)
- + return ret;
- +
- return 0;
- }
- @@ -949,7 +931,7 @@ uchcom_param(void *arg, int portno, struct termios *t)
- {
- struct uchcom_softc *sc = arg;
- int ret;
- -
- +return 0; // XXX
- if (usbd_is_dying(sc->sc_udev))
- return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement