Lines Matching refs:dev
168 static int ds_send_control_cmd(struct ds_device *dev, u16 value, u16 index)
172 err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, dev->ep[EP_CONTROL]),
175 dev_err(&dev->udev->dev,
184 static int ds_send_control_mode(struct ds_device *dev, u16 value, u16 index)
188 err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, dev->ep[EP_CONTROL]),
191 dev_err(&dev->udev->dev,
200 static int ds_send_control(struct ds_device *dev, u16 value, u16 index)
204 err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, dev->ep[EP_CONTROL]),
207 dev_err(&dev->udev->dev,
218 struct device *dev = &ds_dev->udev->dev;
221 dev_info(dev, "ep_status=0x%x, count=%d, status=%*phC",
225 dev_dbg(dev, "enable flag: 0x%02x", buf[0]);
226 dev_dbg(dev, "1-wire speed: 0x%02x", buf[1]);
227 dev_dbg(dev, "strong pullup duration: 0x%02x", buf[2]);
228 dev_dbg(dev, "programming pulse duration: 0x%02x", buf[3]);
229 dev_dbg(dev, "pulldown slew rate control: 0x%02x", buf[4]);
230 dev_dbg(dev, "write-1 low time: 0x%02x", buf[5]);
231 dev_dbg(dev, "data sample offset/write-0 recovery time: 0x%02x", buf[6]);
232 dev_dbg(dev, "reserved (test register): 0x%02x", buf[7]);
233 dev_dbg(dev, "device status flags: 0x%02x", buf[8]);
234 dev_dbg(dev, "communication command byte 1: 0x%02x", buf[9]);
235 dev_dbg(dev, "communication command byte 2: 0x%02x", buf[10]);
236 dev_dbg(dev, "communication command buffer status: 0x%02x", buf[11]);
237 dev_dbg(dev, "1-wire data output buffer status: 0x%02x", buf[12]);
238 dev_dbg(dev, "1-wire data input buffer status: 0x%02x", buf[13]);
239 dev_dbg(dev, "reserved: 0x%02x", buf[14]);
240 dev_dbg(dev, "reserved: 0x%02x", buf[15]);
245 dev_dbg(dev, "New device detect.\n");
248 dev_dbg(dev, "Result Register Value: 0x%02x", buf[i]);
250 dev_dbg(dev, "NRS: Reset no presence or ...\n");
252 dev_dbg(dev, "SH: short on reset or set path\n");
254 dev_dbg(dev, "APP: alarming presence on reset\n");
256 dev_dbg(dev, "VPP: 12V expected not seen\n");
258 dev_dbg(dev, "CMP: compare error\n");
260 dev_dbg(dev, "CRC: CRC error detected\n");
262 dev_dbg(dev, "RDP: redirected page\n");
264 dev_dbg(dev, "EOS: end of search error\n");
268 static int ds_recv_status(struct ds_device *dev, struct ds_status *st)
276 err = usb_interrupt_msg(dev->udev,
277 usb_rcvintpipe(dev->udev,
278 dev->ep[EP_STATUS]),
279 dev->st_buf, sizeof(dev->st_buf),
282 dev_err(&dev->udev->dev,
284 dev->ep[EP_STATUS], err);
289 memcpy(st, dev->st_buf, sizeof(*st));
294 static void ds_reset_device(struct ds_device *dev)
296 ds_send_control_cmd(dev, CTL_RESET_DEVICE, 0);
300 if (ds_send_control_mode(dev, MOD_PULSE_EN, PULSE_SPUE))
301 dev_err(&dev->udev->dev,
304 if (dev->spu_sleep) {
306 u8 del = dev->spu_sleep>>4;
308 if (ds_send_control(dev, COMM_SET_DURATION | COMM_IM, del))
309 dev_err(&dev->udev->dev,
314 static int ds_recv_data(struct ds_device *dev, unsigned char *buf, int size)
328 err = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, dev->ep[EP_DATA_IN]),
333 dev_info(&dev->udev->dev, "Clearing ep0x%x.\n", dev->ep[EP_DATA_IN]);
334 usb_clear_halt(dev->udev, usb_rcvbulkpipe(dev->udev, dev->ep[EP_DATA_IN]));
337 recv_len = ds_recv_status(dev, NULL);
339 ds_dump_status(dev, dev->st_buf, recv_len);
357 static int ds_send_data(struct ds_device *dev, unsigned char *buf, int len)
362 err = usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, dev->ep[EP_DATA_OUT]), buf, len, &count, 1000);
364 dev_err(&dev->udev->dev, "Failed to write 1-wire data to ep0x%x: "
365 "err=%d.\n", dev->ep[EP_DATA_OUT], err);
374 int ds_stop_pulse(struct ds_device *dev, int limit)
380 err = ds_send_control(dev, CTL_HALT_EXE_IDLE, 0);
383 err = ds_send_control(dev, CTL_RESUME_EXE, 0);
386 err = ds_recv_status(dev, &st);
391 err = ds_send_control_mode(dev, MOD_PULSE_EN, 0);
400 int ds_detect(struct ds_device *dev, struct ds_status *st)
404 err = ds_send_control_cmd(dev, CTL_RESET_DEVICE, 0);
408 err = ds_send_control(dev, COMM_SET_DURATION | COMM_IM, 0);
412 err = ds_send_control(dev, COMM_SET_DURATION | COMM_IM | COMM_TYPE, 0x40);
416 err = ds_send_control_mode(dev, MOD_PULSE_EN, PULSE_PROG);
420 err = ds_dump_status(dev, st);
427 static int ds_wait_status(struct ds_device *dev, struct ds_status *st)
433 err = ds_recv_status(dev, st);
437 printk("0x%x: count=%d, status: ", dev->ep[EP_STATUS], err);
439 printk("%02x ", dev->st_buf[i]);
446 dev_info(&dev->udev->dev, "Resetting device after ST_EPOF.\n");
447 ds_reset_device(dev);
457 ds_dump_status(dev, dev->st_buf, err);
469 static int ds_reset(struct ds_device *dev)
482 err = ds_send_control(dev, COMM_1_WIRE_RESET | COMM_IM, SPEED_NORMAL);
490 static int ds_set_speed(struct ds_device *dev, int speed)
502 err = ds_send_control_mode(dev, MOD_1WIRE_SPEED, speed);
510 static int ds_set_pullup(struct ds_device *dev, int delay)
518 dev->spu_bit = delay ? COMM_SPU : 0;
524 if (delay == 0 || ms == dev->spu_sleep)
527 err = ds_send_control(dev, COMM_SET_DURATION | COMM_IM, del);
531 dev->spu_sleep = ms;
536 static int ds_touch_bit(struct ds_device *dev, u8 bit, u8 *tbit)
541 err = ds_send_control(dev, COMM_BIT_IO | COMM_IM | (bit ? COMM_D : 0),
546 ds_wait_status(dev, &st);
548 err = ds_recv_data(dev, tbit, sizeof(*tbit));
556 static int ds_write_bit(struct ds_device *dev, u8 bit)
565 err = ds_send_control(dev, COMM_BIT_IO | COMM_IM | COMM_ICP |
570 ds_wait_status(dev, &st);
576 static int ds_write_byte(struct ds_device *dev, u8 byte)
581 err = ds_send_control(dev, COMM_BYTE_IO | COMM_IM | dev->spu_bit, byte);
585 if (dev->spu_bit)
586 msleep(dev->spu_sleep);
588 err = ds_wait_status(dev, &st);
592 err = ds_recv_data(dev, &dev->byte_buf, 1);
596 return !(byte == dev->byte_buf);
599 static int ds_read_byte(struct ds_device *dev, u8 *byte)
604 err = ds_send_control(dev, COMM_BYTE_IO | COMM_IM, 0xff);
608 ds_wait_status(dev, &st);
610 err = ds_recv_data(dev, byte, sizeof(*byte));
617 static int ds_read_block(struct ds_device *dev, u8 *buf, int len)
627 err = ds_send_data(dev, buf, len);
631 err = ds_send_control(dev, COMM_BLOCK_IO | COMM_IM, len);
635 ds_wait_status(dev, &st);
638 err = ds_recv_data(dev, buf, len);
643 static int ds_write_block(struct ds_device *dev, u8 *buf, int len)
648 err = ds_send_data(dev, buf, len);
652 err = ds_send_control(dev, COMM_BLOCK_IO | COMM_IM | dev->spu_bit, len);
656 if (dev->spu_bit)
657 msleep(dev->spu_sleep);
659 ds_wait_status(dev, &st);
661 err = ds_recv_data(dev, buf, len);
679 struct ds_device *dev = data;
714 if (ds_send_data(dev, (u8 *)&master->search_id, 8) < 0)
724 if (ds_send_control(dev, value, index) < 0)
730 err = ds_recv_status(dev, &st);
743 err = ds_recv_data(dev, (u8 *)buf, bufsize);
775 dev_info(&dev->udev->dev, "%s: max_slave_count %d reached, "
795 static int ds_match_access(struct ds_device *dev, u64 init)
800 err = ds_send_data(dev, (unsigned char *)&init, sizeof(init));
804 ds_wait_status(dev, &st);
806 err = ds_send_control(dev, COMM_MATCH_ACCESS | COMM_IM | COMM_RST, 0x0055);
810 ds_wait_status(dev, &st);
815 static int ds_set_path(struct ds_device *dev, u64 init)
824 err = ds_send_data(dev, buf, sizeof(buf));
828 ds_wait_status(dev, &st);
830 err = ds_send_control(dev, COMM_SET_PATH | COMM_IM | COMM_RST, 0);
834 ds_wait_status(dev, &st);
843 struct ds_device *dev = data;
845 if (ds_touch_bit(dev, bit, &dev->byte_buf))
848 return dev->byte_buf;
854 struct ds_device *dev = data;
856 ds_write_bit(dev, bit);
861 struct ds_device *dev = data;
864 err = ds_touch_bit(dev, 1, &dev->byte_buf);
868 return dev->byte_buf & 1;
874 struct ds_device *dev = data;
876 ds_write_byte(dev, byte);
881 struct ds_device *dev = data;
884 err = ds_read_byte(dev, &dev->byte_buf);
888 return dev->byte_buf;
893 struct ds_device *dev = data;
903 ds_write_block(dev, tbuf, len);
910 struct ds_device *dev = data;
921 err = ds_read_block(dev, tbuf, len);
932 struct ds_device *dev = data;
935 err = ds_reset(dev);
944 struct ds_device *dev = data;
946 if (ds_set_pullup(dev, delay))
952 static int ds_w1_init(struct ds_device *dev)
954 memset(&dev->master, 0, sizeof(struct w1_bus_master));
966 ds_reset_device(dev);
968 dev->master.data = dev;
969 dev->master.touch_bit = &ds9490r_touch_bit;
976 dev->master.read_bit = &ds9490r_read_bit;
977 dev->master.write_bit = &ds9490r_write_bit;
979 dev->master.read_byte = &ds9490r_read_byte;
980 dev->master.write_byte = &ds9490r_write_byte;
981 dev->master.read_block = &ds9490r_read_block;
982 dev->master.write_block = &ds9490r_write_block;
983 dev->master.reset_bus = &ds9490r_reset;
984 dev->master.set_pullup = &ds9490r_set_pullup;
985 dev->master.search = &ds9490r_search;
987 return w1_add_master_device(&dev->master);
990 static void ds_w1_fini(struct ds_device *dev)
992 w1_remove_master_device(&dev->master);
1001 struct ds_device *dev;
1004 dev = kzalloc(sizeof(struct ds_device), GFP_KERNEL);
1005 if (!dev)
1008 dev->udev = usb_get_dev(udev);
1009 if (!dev->udev) {
1013 memset(dev->ep, 0, sizeof(dev->ep));
1015 usb_set_intfdata(intf, dev);
1017 err = usb_reset_configuration(dev->udev);
1019 dev_err(&dev->udev->dev,
1026 err = usb_set_interface(dev->udev,
1029 dev_err(&dev->udev->dev, "Failed to set alternative setting %d "
1037 dev_err(&dev->udev->dev, "Num endpoints=%d. It is not DS9490R.\n",
1050 dev->ep[i+1] = endpoint->bEndpointAddress;
1059 err = ds_w1_init(dev);
1064 list_add_tail(&dev->ds_entry, &ds_devices);
1071 usb_put_dev(dev->udev);
1073 kfree(dev);
1079 struct ds_device *dev;
1081 dev = usb_get_intfdata(intf);
1082 if (!dev)
1086 list_del(&dev->ds_entry);
1089 ds_w1_fini(dev);
1093 usb_put_dev(dev->udev);
1094 kfree(dev);