Ejemplo n.º 1
0
int
main(int argc, char *argv[])
#endif
{
	struct lock_msg message_buf;
	daemonaddr_t from;
	int addrlen;
	int rc;
	int x = 1;		/* kludge to stop warnings from compiler */

	init(argc, argv);
	CRIT_BEGIN();
	while (x) {
		CRIT_END();
		addrlen = sizeof (from);
		DPF((stderr, "begin recvfrom\n"));
		rc = recvfrom(lock_soc, &message_buf, sizeof (message_buf),
		    0, (struct sockaddr *)&from, &addrlen);
		DPF((stderr, "end recvfrom rc = %d\n", rc));
		CRIT_BEGIN();
		if (rc == sizeof (message_buf))
			dispatch(&message_buf, &from);
		else
			check_for_write_lock();

		/* if we own the lock, check to see if the process died */
		if (the_lock.type != LOCK_NOTLOCKED &&
		    the_lock.remote_daemon == NULL)
			check_for_dead();
	}
	CRIT_END();
	return (0);
}
Ejemplo n.º 2
0
static ssize_t lcdi2c_customchar(struct device* dev,
				 struct device_attribute* attr,
				 const char* buf, size_t count)
{
    u8 i;

    CRIT_BEG(data, ERESTARTSYS);

    if ((count > 0 && (count % 9)) || count == 0)
    {
         dev_err(&client->dev, "incomplete character bitmap definition\n");
	 CRIT_END(data);
         return -ETOOSMALL;
    }

    for (i = 0; i < count; i+=9)
    {
        if (buf[i] > 7)
        {
            dev_err(&client->dev, "character number %d can only have values"
				  "starting from 0 to 7\n", buf[i]);
	    CRIT_END(data);
	    return -ETOOSMALL;
        }

        lcdcustomchar(data, buf[i], buf + i + 1);
    }

    CRIT_END(data);
    return count;
}
Ejemplo n.º 3
0
static ssize_t lcdi2c_backlight(struct device* dev,
				struct device_attribute* attr,
				const char* buf, size_t count)
{
    u8 res;
    int er;

    CRIT_BEG(data, ERESTARTSYS);

    er = kstrtou8(buf, 10, &res);
    if (er == 0)
    {
        lcdsetbacklight(data,  res);
        er = count;
    }
    else if (er == -ERANGE)
        dev_err(dev, "Brightness parameter out of range (0-255).");
    else if (er == -EINVAL)
        dev_err(dev, "Brightness parameter has numerical value. \"%s\" was given", buf);
    else
        dev_err(dev, "Brightness parameter wasn't properly converted! err: %d", er);

    CRIT_END(data);
    return er;
}
Ejemplo n.º 4
0
static int lcdi2c_release(struct inode *inode, struct file *file)
{
    CRIT_BEG(data, EBUSY);

    data->deviceopencnt--;

    module_put(THIS_MODULE);
    CRIT_END(data);
    return SUCCESS;
}
Ejemplo n.º 5
0
static ssize_t lcdi2c_clear(struct device* dev, struct device_attribute* attr,
			    const char* buf, size_t count)
{
    CRIT_BEG(data, ERESTARTSYS);

    if (count > 0 && buf[0] == '1')
        lcdclear(data);

    CRIT_END(data);
    return count;
}
Ejemplo n.º 6
0
static int lcdi2c_open(struct inode *inode, struct file *file)
{
    CRIT_BEG(data, EBUSY);

    data->deviceopencnt++;
    data->devicefileptr = 0;
    try_module_get(THIS_MODULE);
    CRIT_END(data);

    return SUCCESS;
}
Ejemplo n.º 7
0
static ssize_t lcdi2c_scrollhz(struct device* dev, struct device_attribute* attr,
			       const char* buf, size_t count)
{
    CRIT_BEG(data, ERESTARTSYS);

    if (count > 0)
        lcdscrollhoriz(data, buf[0] - '0');

    CRIT_END(data);
    return count;
}
Ejemplo n.º 8
0
static ssize_t lcdi2c_blink_show(struct device *dev,
				 struct device_attribute *attr, char *buf)
{
    int count = 0;

    CRIT_BEG(data, ERESTARTSYS);

    if (buf)
        count = snprintf(buf, PAGE_SIZE, "%c", data->blink ? '1' : '0');

    CRIT_END(data);
    return count;
}
Ejemplo n.º 9
0
static ssize_t lcdi2c_meta_show(struct device *dev,
				struct device_attribute *attr, char *buf)
{

#define META_BUFFER_LEN 54

    ssize_t count = 0;
    char tmp[12], lines[META_BUFFER_LEN];

    CRIT_BEG(data, ERESTARTSYS);

    if (buf)
    {
        int i;
        memset(lines, 0, META_BUFFER_LEN);
        for (i=0; i < data->organization.rows; i++)
        {
            snprintf(tmp, 12, "R[%d]=0x%02X ",i, data->organization.addresses[i]);
            strncat(lines, tmp, META_BUFFER_LEN);
        }

        count = snprintf(buf, PAGE_SIZE,
                         "Topology:%s=%d\n"
                         "Rows:%d\n"
                         "Columns:%d\n"
                         "Rows addresses:%s\n"
                         "Pins:RS=%d RW=%d E=%d BCKLIGHT=%d D[4]=%d D[5]=%d D[6]=%d D[7]=%d\n"
			 "IOCTLS:\n",
                         data->organization.toponame,
                         data->organization.topology,
                         data->organization.rows,
                         data->organization.columns,
                         lines,
                         PIN_RS, PIN_RW, PIN_EN,
                         PIN_BACKLIGHTON,
                         PIN_DB4, PIN_DB5, PIN_DB6, PIN_DB7
                        );

 	for(i=0; i < (sizeof(ioctls) / sizeof(IOCTLDescription_t)); i++)
 	{
 	  count += snprintf(lines, META_BUFFER_LEN, "\t%s=0x%02X\n",
                            ioctls[i].name, ioctls[i].ioctlcode);
 	  strncat(buf, lines, PAGE_SIZE);
 	}


    }

    CRIT_END(data);
    return count;
}
Ejemplo n.º 10
0
static ssize_t lcdi2c_char_show(struct device *dev,
				struct device_attribute *attr, char *buf)
{
    u8 memaddr;

    CRIT_BEG(data, ERESTARTSYS);

    memaddr = (data->column + (data->row * data->organization.columns))
              % LCD_BUFFER_SIZE;
    buf[0] = data->buffer[memaddr];

    CRIT_END(data);
    return 1;
}
Ejemplo n.º 11
0
static ssize_t lcdi2c_fopwrite(struct file *file, const char __user *buffer,
			    size_t length, loff_t *offset)
{
    u8 i, str[81];

    CRIT_BEG(data, EBUSY);

    for(i = 0; i < length && i < (data->organization.columns * data->organization.rows); i++)
      get_user(str[i], buffer + i);
    str[i] = 0;
    (*offset) = lcdprint(data, str);

    CRIT_END(data);
    return i;
}
Ejemplo n.º 12
0
static ssize_t lcdi2c_cursorpos(struct device* dev,
				struct device_attribute* attr,
				const char* buf, size_t count)
{
    CRIT_BEG(data, ERESTARTSYS);

    if (count >= 2)
    {
        count = 2;
        lcdsetcursor(data, buf[0], buf[1]);
    }

    CRIT_END(data);
    return count;
}
Ejemplo n.º 13
0
loff_t lcdi2c_lseek(struct file *file, loff_t offset, int orig)
{
  u8 memaddr, oldoffset;

  CRIT_BEG(data, EBUSY);
  memaddr = data->column + (data->row * data->organization.columns);
  oldoffset = memaddr;
  memaddr = (memaddr + (u8)offset) % (data->organization.rows * data->organization.columns);
  data->column =  (memaddr % data->organization.columns);
  data->row = (memaddr / data->organization.columns);
  lcdsetcursor(data, data->column, data->row);
  CRIT_END(data);

  return oldoffset;
}
Ejemplo n.º 14
0
static ssize_t lcdi2c_blink(struct device* dev,
			    struct device_attribute* attr,
			    const char* buf, size_t count)
{
    CRIT_BEG(data, ERESTARTSYS);

    if (count > 0)
    {
        data->blink = (buf[0] == '1');
        lcdblink(data, data->blink);
    }

    CRIT_END(data);
    return count;
}
Ejemplo n.º 15
0
static ssize_t lcdi2c_cursorpos_show(struct device *dev,
				     struct device_attribute *attr,
				     char *buf)
{
    ssize_t count = 0;

    CRIT_BEG(data, ERESTARTSYS);

    if (buf)
    {
        count = 2;
        buf[0] = data->column;
        buf[1] = data->row;
    }

    CRIT_END(data);
    return count;
}
Ejemplo n.º 16
0
static ssize_t lcdi2c_data_show(struct device *dev,
				struct device_attribute *attr, char *buf)
{
    u8 i=0;

    CRIT_BEG(data, ERESTARTSYS);

    if (buf)
    {
        for (i = 0; i < (data->organization.columns * data->organization.rows); i++)
        {
            buf[i] = data->buffer[i];
        }
    }

    CRIT_END(data);
    return (data->organization.columns * data->organization.rows);
}
Ejemplo n.º 17
0
static ssize_t lcdi2c_char(struct device* dev,
				 struct device_attribute* attr,
				 const char* buf, size_t count)
{
    u8 memaddr;

    CRIT_BEG(data, ERESTARTSYS);

    if (buf && count > 0)
    {
      memaddr = (1 + data->column + (data->row * data->organization.columns))
                % LCD_BUFFER_SIZE;
      lcdwrite(data, buf[0]);
      data->column = (memaddr % data->organization.columns);
      data->row = (memaddr / data->organization.columns);
      lcdsetcursor(data, data->column, data->row);
    }

    CRIT_END(data);
    return 1;
}
Ejemplo n.º 18
0
static ssize_t lcdi2c_customchar_show(struct device *dev,
				      struct device_attribute *attr, char *buf)
{
    int count = 0, c, i;

    CRIT_BEG(data, ERESTARTSYS);

    for (c = 0; c < 8; c++)
    {
        buf[c * 9] = c;
	count++;
        for (i = 0; i < 8; i++)
        {
            buf[c * 9 + (i + 1)] = data->customchars[c][i];
            count++;
        }
    }

    CRIT_END(data);
    return count;
}
Ejemplo n.º 19
0
static ssize_t lcdi2c_data(struct device* dev,
			   struct device_attribute* attr,
			   const char* buf, size_t count)
{
    u8 i, addr, memaddr;

    CRIT_BEG(data, ERESTARTSYS);

    if (count > 0)
    {
	memaddr = data->column + (data->row * data->organization.columns);
	for(i = 0; i < count; i++)
	{
	  addr = (memaddr + i) % (data->organization.columns * data->organization.rows);
	  data->buffer[addr] = buf[i];
	}
	lcdflushbuffer(data);
    }

    CRIT_END(data);
    return count;
}
Ejemplo n.º 20
0
static ssize_t lcdi2c_fopread(struct file *file, char __user *buffer,
			   size_t length, loff_t *offset)
{
    u8 i = 0;

    CRIT_BEG(data, EBUSY);
    if (data->devicefileptr == (data->organization.columns * data->organization.rows))
      return 0;

    while(i < length && i < (data->organization.columns * data->organization.rows))
    {
      put_user(data->buffer[i], buffer++);
      data->devicefileptr++;
      i++;
    }

    i %= (data->organization.columns * data->organization.rows);
    ITOP(data, i, data->column, data->row);
    lcdsetcursor(data, data->column, data->row);
    (*offset) = i;
    CRIT_END(data);

    return i;
}
Ejemplo n.º 21
0
static long lcdi2c_ioctl(struct file *file,
			unsigned int ioctl_num,
			unsigned long arg)
{

  char *buffer = (char*)arg, ccb[10];
  u8 memaddr, i, ch;
  long status = SUCCESS;

  CRIT_BEG(data, EAGAIN);

  switch (ioctl_num)
  {
    case LCD_IOCTL_SETCHAR:
      get_user(ch, buffer);
      memaddr = (1 + data->column + (data->row * data->organization.columns)) % LCD_BUFFER_SIZE;
      lcdwrite(data, ch);
      data->column = (memaddr % data->organization.columns);
      data->row = (memaddr / data->organization.columns);
      lcdsetcursor(data, data->column, data->row);
      break;
    case LCD_IOCTL_GETCHAR:
      memaddr = (data->column + (data->row * data->organization.columns)) % LCD_BUFFER_SIZE;
      ch = data->buffer[memaddr];
      put_user(ch, buffer);
      break;
    case LCD_IOCTL_GETPOSITION:
      printk(KERN_INFO "GETPOSITION called\n");
      put_user(data->column, buffer);
      put_user(data->row, buffer+1);
      break;
    case LCD_IOCTL_SETPOSITION:
      get_user(data->column, buffer);
      get_user(data->row, buffer+1);
      lcdsetcursor(data, data->column, data->row);
      break;
    case LCD_IOCTL_RESET:
      get_user(ch, buffer);
      if (ch == '1')
	lcdinit(data, data->organization.topology);
      break;
    case LCD_IOCTL_HOME:
      printk(KERN_INFO "HOME called\n");
      get_user(ch, buffer);
      if (ch == '1')
	lcdhome(data);
      break;
    case LCD_IOCTL_GETCURSOR:
      put_user(data->cursor ? '1' : '0', buffer);
      break;
    case LCD_IOCTL_SETCURSOR:
      get_user(ch, buffer);
      lcdcursor(data, (ch == '1'));
      break;
    case LCD_IOCTL_GETBLINK:
      put_user(data->blink ? '1' : '0', buffer);
      break;
    case LCD_IOCTL_SETBLINK:
      get_user(ch, buffer);
      lcdblink(data, (ch == '1'));
      break;
    case LCD_IOCTL_GETBACKLIGHT:
      put_user(data->backlight ? '1' : '0', buffer);
      break;
    case LCD_IOCTL_SETBACKLIGHT:
      get_user(ch, buffer);
      lcdsetbacklight(data, (ch == '1'));
      break;
    case LCD_IOCTL_SCROLLHZ:
      get_user(ch, buffer);
      lcdscrollhoriz(data, ch - '0');
      break;
    case LCD_IOCTL_GETCUSTOMCHAR:
      get_user(ch, buffer);
      for (i=0; i<8; i++)
	put_user(data->customchars[ch][i], buffer + i + 1);
      break;
    case LCD_IOCTL_SETCUSTOMCHAR:
      for (i = 0; i < 9; i++)
	get_user(ccb[i], buffer + i);
      lcdcustomchar(data, ccb[0], ccb+1);
      break;
    case LCD_IOCTL_CLEAR:
      get_user(ch, buffer);
      if (ch == '1')
	lcdclear(data);
      break;
    default:
      printk(KERN_INFO "Unknown IOCTL\n");
      break;
  }
  CRIT_END(data);

  return status;
}