Lines Matching +full:lsb +full:- +full:first
1 // SPDX-License-Identifier: GPL-2.0-only
63 struct c2port_ops *ops = dev->ops; in c2port_reset()
69 ops->c2ck_set(dev, 0); in c2port_reset()
71 ops->c2ck_set(dev, 1); in c2port_reset()
79 struct c2port_ops *ops = dev->ops; in c2port_strobe_ck()
81 /* During hi-low-hi transition we disable local IRQs to avoid in c2port_strobe_ck()
87 ops->c2ck_set(dev, 0); in c2port_strobe_ck()
89 ops->c2ck_set(dev, 1); in c2port_strobe_ck()
101 struct c2port_ops *ops = dev->ops; in c2port_write_ar()
107 /* INS field (11b, LSB first) */ in c2port_write_ar()
108 ops->c2d_dir(dev, 0); in c2port_write_ar()
109 ops->c2d_set(dev, 1); in c2port_write_ar()
111 ops->c2d_set(dev, 1); in c2port_write_ar()
116 ops->c2d_set(dev, addr & 0x01); in c2port_write_ar()
123 ops->c2d_dir(dev, 1); in c2port_write_ar()
129 struct c2port_ops *ops = dev->ops; in c2port_read_ar()
135 /* INS field (10b, LSB first) */ in c2port_read_ar()
136 ops->c2d_dir(dev, 0); in c2port_read_ar()
137 ops->c2d_set(dev, 0); in c2port_read_ar()
139 ops->c2d_set(dev, 1); in c2port_read_ar()
143 ops->c2d_dir(dev, 1); in c2port_read_ar()
146 *addr >>= 1; /* shift in 8-bit ADDRESS field LSB first */ in c2port_read_ar()
149 if (ops->c2d_get(dev)) in c2port_read_ar()
161 struct c2port_ops *ops = dev->ops; in c2port_write_dr()
167 /* INS field (01b, LSB first) */ in c2port_write_dr()
168 ops->c2d_dir(dev, 0); in c2port_write_dr()
169 ops->c2d_set(dev, 1); in c2port_write_dr()
171 ops->c2d_set(dev, 0); in c2port_write_dr()
174 /* LENGTH field (00b, LSB first -> 1 byte) */ in c2port_write_dr()
175 ops->c2d_set(dev, 0); in c2port_write_dr()
177 ops->c2d_set(dev, 0); in c2port_write_dr()
182 ops->c2d_set(dev, data & 0x01); in c2port_write_dr()
189 ops->c2d_dir(dev, 1); in c2port_write_dr()
193 if (ops->c2d_get(dev)) in c2port_write_dr()
197 } while (--timeout > 0); in c2port_write_dr()
199 return -EIO; in c2port_write_dr()
209 struct c2port_ops *ops = dev->ops; in c2port_read_dr()
215 /* INS field (00b, LSB first) */ in c2port_read_dr()
216 ops->c2d_dir(dev, 0); in c2port_read_dr()
217 ops->c2d_set(dev, 0); in c2port_read_dr()
219 ops->c2d_set(dev, 0); in c2port_read_dr()
222 /* LENGTH field (00b, LSB first -> 1 byte) */ in c2port_read_dr()
223 ops->c2d_set(dev, 0); in c2port_read_dr()
225 ops->c2d_set(dev, 0); in c2port_read_dr()
229 ops->c2d_dir(dev, 1); in c2port_read_dr()
233 if (ops->c2d_get(dev)) in c2port_read_dr()
237 } while (--timeout > 0); in c2port_read_dr()
239 return -EIO; in c2port_read_dr()
244 *data >>= 1; /* shift in 8-bit DATA field LSB first */ in c2port_read_dr()
247 if (ops->c2d_get(dev)) in c2port_read_dr()
265 return -EIO; in c2port_poll_in_busy()
271 } while (--timeout > 0); in c2port_poll_in_busy()
273 return -EIO; in c2port_poll_in_busy()
286 return -EIO; in c2port_poll_out_ready()
292 } while (--timeout > 0); in c2port_poll_out_ready()
294 return -EIO; in c2port_poll_out_ready()
308 return sprintf(buf, "%s\n", c2dev->name); in c2port_show_name()
316 struct c2port_ops *ops = c2dev->ops; in c2port_show_flash_blocks_num()
318 return sprintf(buf, "%d\n", ops->blocks_num); in c2port_show_flash_blocks_num()
326 struct c2port_ops *ops = c2dev->ops; in c2port_show_flash_block_size()
328 return sprintf(buf, "%d\n", ops->block_size); in c2port_show_flash_block_size()
336 struct c2port_ops *ops = c2dev->ops; in c2port_show_flash_size()
338 return sprintf(buf, "%d\n", ops->blocks_num * ops->block_size); in c2port_show_flash_size()
347 return sprintf(buf, "%d\n", c2dev->access); in access_show()
354 struct c2port_ops *ops = c2dev->ops; in access_store()
359 return -EINVAL; in access_store()
361 mutex_lock(&c2dev->mutex); in access_store()
363 c2dev->access = !!status; in access_store()
367 if (c2dev->access) in access_store()
368 ops->c2ck_set(c2dev, 1); in access_store()
369 ops->access(c2dev, c2dev->access); in access_store()
370 if (c2dev->access) in access_store()
371 ops->c2d_dir(c2dev, 1); in access_store()
373 mutex_unlock(&c2dev->mutex); in access_store()
386 if (!c2dev->access) in c2port_store_reset()
387 return -EBUSY; in c2port_store_reset()
389 mutex_lock(&c2dev->mutex); in c2port_store_reset()
392 c2dev->flash_access = 0; in c2port_store_reset()
394 mutex_unlock(&c2dev->mutex); in c2port_store_reset()
423 if (!c2dev->access) in c2port_show_dev_id()
424 return -EBUSY; in c2port_show_dev_id()
426 mutex_lock(&c2dev->mutex); in c2port_show_dev_id()
428 mutex_unlock(&c2dev->mutex); in c2port_show_dev_id()
431 dev_err(dev, "cannot read from %s\n", c2dev->name); in c2port_show_dev_id()
460 if (!c2dev->access) in c2port_show_rev_id()
461 return -EBUSY; in c2port_show_rev_id()
463 mutex_lock(&c2dev->mutex); in c2port_show_rev_id()
465 mutex_unlock(&c2dev->mutex); in c2port_show_rev_id()
468 dev_err(c2dev->dev, "cannot read from %s\n", c2dev->name); in c2port_show_rev_id()
479 return sprintf(buf, "%d\n", c2dev->flash_access); in c2port_show_flash_access()
488 if (!dev->access) in __c2port_store_flash_access()
489 return -EBUSY; in __c2port_store_flash_access()
491 dev->flash_access = !!status; in __c2port_store_flash_access()
494 if (dev->flash_access == 0) in __c2port_store_flash_access()
501 /* Write the first keycode to enable C2 Flash programming */ in __c2port_store_flash_access()
528 return -EINVAL; in c2port_store_flash_access()
530 mutex_lock(&c2dev->mutex); in c2port_store_flash_access()
532 mutex_unlock(&c2dev->mutex); in c2port_store_flash_access()
535 dev_err(c2dev->dev, "cannot enable %s flash programming\n", in c2port_store_flash_access()
536 c2dev->name); in c2port_store_flash_access()
575 return -EBUSY; in __c2port_write_flash_erase()
577 /* Send a three-byte arming sequence to enable the device erase. in __c2port_write_flash_erase()
610 if (!c2dev->access || !c2dev->flash_access) in c2port_store_flash_erase()
611 return -EBUSY; in c2port_store_flash_erase()
613 mutex_lock(&c2dev->mutex); in c2port_store_flash_erase()
615 mutex_unlock(&c2dev->mutex); in c2port_store_flash_erase()
618 dev_err(c2dev->dev, "cannot erase %s flash\n", c2dev->name); in c2port_store_flash_erase()
629 struct c2port_ops *ops = dev->ops; in __c2port_read_flash_data()
634 if (offset >= ops->block_size * ops->blocks_num) in __c2port_read_flash_data()
637 if (ops->block_size * ops->blocks_num - offset < nread) in __c2port_read_flash_data()
638 nread = ops->block_size * ops->blocks_num - offset; in __c2port_read_flash_data()
668 return -EBUSY; in __c2port_read_flash_data()
700 return -EBUSY; in __c2port_read_flash_data()
724 if (!c2dev->access || !c2dev->flash_access) in c2port_read_flash_data()
725 return -EBUSY; in c2port_read_flash_data()
727 mutex_lock(&c2dev->mutex); in c2port_read_flash_data()
729 mutex_unlock(&c2dev->mutex); in c2port_read_flash_data()
732 dev_err(c2dev->dev, "cannot read %s flash\n", c2dev->name); in c2port_read_flash_data()
740 struct c2port_ops *ops = dev->ops; in __c2port_write_flash_data()
746 if (ops->block_size * ops->blocks_num - offset < nwrite) in __c2port_write_flash_data()
747 nwrite = ops->block_size * ops->blocks_num - offset; in __c2port_write_flash_data()
750 if (offset >= ops->block_size * ops->blocks_num) in __c2port_write_flash_data()
751 return -EINVAL; in __c2port_write_flash_data()
777 return -EBUSY; in __c2port_write_flash_data()
809 return -EBUSY; in __c2port_write_flash_data()
839 if (!c2dev->access || !c2dev->flash_access) in c2port_write_flash_data()
840 return -EBUSY; in c2port_write_flash_data()
842 mutex_lock(&c2dev->mutex); in c2port_write_flash_data()
844 mutex_unlock(&c2dev->mutex); in c2port_write_flash_data()
847 dev_err(c2dev->dev, "cannot write %s flash\n", c2dev->name); in c2port_write_flash_data()
851 /* size is computed at run-time */
897 if (unlikely(!ops) || unlikely(!ops->access) || \ in c2port_device_register()
898 unlikely(!ops->c2d_dir) || unlikely(!ops->c2ck_set) || \ in c2port_device_register()
899 unlikely(!ops->c2d_get) || unlikely(!ops->c2d_set)) in c2port_device_register()
900 return ERR_PTR(-EINVAL); in c2port_device_register()
904 return ERR_PTR(-ENOMEM); in c2port_device_register()
914 c2dev->id = ret; in c2port_device_register()
916 bin_attr_flash_data.size = ops->blocks_num * ops->block_size; in c2port_device_register()
918 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev, in c2port_device_register()
919 "c2port%d", c2dev->id); in c2port_device_register()
920 if (IS_ERR(c2dev->dev)) { in c2port_device_register()
921 ret = PTR_ERR(c2dev->dev); in c2port_device_register()
924 dev_set_drvdata(c2dev->dev, c2dev); in c2port_device_register()
926 strscpy(c2dev->name, name, sizeof(c2dev->name)); in c2port_device_register()
927 c2dev->ops = ops; in c2port_device_register()
928 mutex_init(&c2dev->mutex); in c2port_device_register()
931 c2dev->access = c2dev->flash_access = 0; in c2port_device_register()
932 ops->access(c2dev, 0); in c2port_device_register()
934 dev_info(c2dev->dev, "C2 port %s added\n", name); in c2port_device_register()
935 dev_info(c2dev->dev, "%s flash has %d blocks x %d bytes " in c2port_device_register()
937 name, ops->blocks_num, ops->block_size, in c2port_device_register()
938 ops->blocks_num * ops->block_size); in c2port_device_register()
944 idr_remove(&c2port_idr, c2dev->id); in c2port_device_register()
959 dev_info(c2dev->dev, "C2 port %s removed\n", c2dev->name); in c2port_device_unregister()
962 idr_remove(&c2port_idr, c2dev->id); in c2port_device_unregister()
965 device_destroy(c2port_class, c2dev->id); in c2port_device_unregister()
978 " - (C) 2007 Rodolfo Giometti\n"); in c2port_init()
985 c2port_class->dev_groups = c2port_groups; in c2port_init()