Lines Matching refs:pt1

73 struct pt1 {  struct
90 struct pt1 *pt1; argument
112 #define pt1_printk(level, pt1, format, arg...) \ argument
113 dev_printk(level, &(pt1)->pdev->dev, format, ##arg)
115 static void pt1_write_reg(struct pt1 *pt1, int reg, u32 data) in pt1_write_reg() argument
117 writel(data, pt1->regs + reg * 4); in pt1_write_reg()
120 static u32 pt1_read_reg(struct pt1 *pt1, int reg) in pt1_read_reg() argument
122 return readl(pt1->regs + reg * 4); in pt1_read_reg()
128 static void pt1_increment_table_count(struct pt1 *pt1) in pt1_increment_table_count() argument
130 pt1_write_reg(pt1, 0, 0x00000020); in pt1_increment_table_count()
133 static void pt1_init_table_count(struct pt1 *pt1) in pt1_init_table_count() argument
135 pt1_write_reg(pt1, 0, 0x00000010); in pt1_init_table_count()
138 static void pt1_register_tables(struct pt1 *pt1, u32 first_pfn) in pt1_register_tables() argument
140 pt1_write_reg(pt1, 5, first_pfn); in pt1_register_tables()
141 pt1_write_reg(pt1, 0, 0x0c000040); in pt1_register_tables()
144 static void pt1_unregister_tables(struct pt1 *pt1) in pt1_unregister_tables() argument
146 pt1_write_reg(pt1, 0, 0x08080000); in pt1_unregister_tables()
149 static int pt1_sync(struct pt1 *pt1) in pt1_sync() argument
153 if (pt1_read_reg(pt1, 0) & 0x20000000) in pt1_sync()
155 pt1_write_reg(pt1, 0, 0x00000008); in pt1_sync()
157 pt1_printk(KERN_ERR, pt1, "could not sync\n"); in pt1_sync()
161 static u64 pt1_identify(struct pt1 *pt1) in pt1_identify() argument
167 id |= (u64)(pt1_read_reg(pt1, 0) >> 30 & 1) << i; in pt1_identify()
168 pt1_write_reg(pt1, 0, 0x00000008); in pt1_identify()
173 static int pt1_unlock(struct pt1 *pt1) in pt1_unlock() argument
176 pt1_write_reg(pt1, 0, 0x00000008); in pt1_unlock()
178 if (pt1_read_reg(pt1, 0) & 0x80000000) in pt1_unlock()
182 pt1_printk(KERN_ERR, pt1, "could not unlock\n"); in pt1_unlock()
186 static int pt1_reset_pci(struct pt1 *pt1) in pt1_reset_pci() argument
189 pt1_write_reg(pt1, 0, 0x01010000); in pt1_reset_pci()
190 pt1_write_reg(pt1, 0, 0x01000000); in pt1_reset_pci()
192 if (pt1_read_reg(pt1, 0) & 0x00000001) in pt1_reset_pci()
196 pt1_printk(KERN_ERR, pt1, "could not reset PCI\n"); in pt1_reset_pci()
200 static int pt1_reset_ram(struct pt1 *pt1) in pt1_reset_ram() argument
203 pt1_write_reg(pt1, 0, 0x02020000); in pt1_reset_ram()
204 pt1_write_reg(pt1, 0, 0x02000000); in pt1_reset_ram()
206 if (pt1_read_reg(pt1, 0) & 0x00000002) in pt1_reset_ram()
210 pt1_printk(KERN_ERR, pt1, "could not reset RAM\n"); in pt1_reset_ram()
214 static int pt1_do_enable_ram(struct pt1 *pt1) in pt1_do_enable_ram() argument
218 status = pt1_read_reg(pt1, 0) & 0x00000004; in pt1_do_enable_ram()
219 pt1_write_reg(pt1, 0, 0x00000002); in pt1_do_enable_ram()
222 if ((pt1_read_reg(pt1, 0) & 0x00000004) != status) in pt1_do_enable_ram()
227 pt1_printk(KERN_ERR, pt1, "could not enable RAM\n"); in pt1_do_enable_ram()
231 static int pt1_enable_ram(struct pt1 *pt1) in pt1_enable_ram() argument
236 phase = pt1->pdev->device == 0x211a ? 128 : 166; in pt1_enable_ram()
238 ret = pt1_do_enable_ram(pt1); in pt1_enable_ram()
245 static void pt1_disable_ram(struct pt1 *pt1) in pt1_disable_ram() argument
247 pt1_write_reg(pt1, 0, 0x0b0b0000); in pt1_disable_ram()
250 static void pt1_set_stream(struct pt1 *pt1, int index, int enabled) in pt1_set_stream() argument
252 pt1_write_reg(pt1, 2, 1 << (index + 8) | enabled << index); in pt1_set_stream()
255 static void pt1_init_streams(struct pt1 *pt1) in pt1_init_streams() argument
259 pt1_set_stream(pt1, i, 0); in pt1_init_streams()
262 static int pt1_filter(struct pt1 *pt1, struct pt1_buffer_page *page) in pt1_filter() argument
281 adap = pt1->adaps[index]; in pt1_filter()
290 pt1->table_index, pt1->buf_index); in pt1_filter()
319 struct pt1 *pt1; in pt1_thread() local
322 pt1 = data; in pt1_thread()
328 page = pt1->tables[pt1->table_index].bufs[pt1->buf_index].page; in pt1_thread()
329 if (!pt1_filter(pt1, page)) { in pt1_thread()
334 if (++pt1->buf_index >= PT1_NR_BUFS) { in pt1_thread()
335 pt1_increment_table_count(pt1); in pt1_thread()
336 pt1->buf_index = 0; in pt1_thread()
337 if (++pt1->table_index >= pt1_nr_tables) in pt1_thread()
338 pt1->table_index = 0; in pt1_thread()
345 static void pt1_free_page(struct pt1 *pt1, void *page, dma_addr_t addr) in pt1_free_page() argument
347 dma_free_coherent(&pt1->pdev->dev, PT1_PAGE_SIZE, page, addr); in pt1_free_page()
350 static void *pt1_alloc_page(struct pt1 *pt1, dma_addr_t *addrp, u32 *pfnp) in pt1_alloc_page() argument
355 page = dma_alloc_coherent(&pt1->pdev->dev, PT1_PAGE_SIZE, &addr, in pt1_alloc_page()
368 static void pt1_cleanup_buffer(struct pt1 *pt1, struct pt1_buffer *buf) in pt1_cleanup_buffer() argument
370 pt1_free_page(pt1, buf->page, buf->addr); in pt1_cleanup_buffer()
374 pt1_init_buffer(struct pt1 *pt1, struct pt1_buffer *buf, u32 *pfnp) in pt1_init_buffer() argument
379 page = pt1_alloc_page(pt1, &addr, pfnp); in pt1_init_buffer()
390 static void pt1_cleanup_table(struct pt1 *pt1, struct pt1_table *table) in pt1_cleanup_table() argument
395 pt1_cleanup_buffer(pt1, &table->bufs[i]); in pt1_cleanup_table()
397 pt1_free_page(pt1, table->page, table->addr); in pt1_cleanup_table()
401 pt1_init_table(struct pt1 *pt1, struct pt1_table *table, u32 *pfnp) in pt1_init_table() argument
408 page = pt1_alloc_page(pt1, &addr, pfnp); in pt1_init_table()
413 ret = pt1_init_buffer(pt1, &table->bufs[i], &buf_pfn); in pt1_init_table()
420 pt1_increment_table_count(pt1); in pt1_init_table()
427 pt1_cleanup_buffer(pt1, &table->bufs[i]); in pt1_init_table()
429 pt1_free_page(pt1, page, addr); in pt1_init_table()
433 static void pt1_cleanup_tables(struct pt1 *pt1) in pt1_cleanup_tables() argument
438 tables = pt1->tables; in pt1_cleanup_tables()
439 pt1_unregister_tables(pt1); in pt1_cleanup_tables()
442 pt1_cleanup_table(pt1, &tables[i]); in pt1_cleanup_tables()
447 static int pt1_init_tables(struct pt1 *pt1) in pt1_init_tables() argument
457 pt1_init_table_count(pt1); in pt1_init_tables()
461 ret = pt1_init_table(pt1, &tables[0], &first_pfn); in pt1_init_tables()
468 ret = pt1_init_table(pt1, &tables[i], &pfn); in pt1_init_tables()
477 pt1_register_tables(pt1, first_pfn); in pt1_init_tables()
478 pt1->tables = tables; in pt1_init_tables()
483 pt1_cleanup_table(pt1, &tables[i]); in pt1_init_tables()
489 static int pt1_start_polling(struct pt1 *pt1) in pt1_start_polling() argument
493 mutex_lock(&pt1->lock); in pt1_start_polling()
494 if (!pt1->kthread) { in pt1_start_polling()
495 pt1->kthread = kthread_run(pt1_thread, pt1, "earth-pt1"); in pt1_start_polling()
496 if (IS_ERR(pt1->kthread)) { in pt1_start_polling()
497 ret = PTR_ERR(pt1->kthread); in pt1_start_polling()
498 pt1->kthread = NULL; in pt1_start_polling()
501 mutex_unlock(&pt1->lock); in pt1_start_polling()
512 ret = pt1_start_polling(adap->pt1); in pt1_start_feed()
515 pt1_set_stream(adap->pt1, adap->index, 1); in pt1_start_feed()
520 static void pt1_stop_polling(struct pt1 *pt1) in pt1_stop_polling() argument
524 mutex_lock(&pt1->lock); in pt1_stop_polling()
526 count += pt1->adaps[i]->users; in pt1_stop_polling()
528 if (count == 0 && pt1->kthread) { in pt1_stop_polling()
529 kthread_stop(pt1->kthread); in pt1_stop_polling()
530 pt1->kthread = NULL; in pt1_stop_polling()
532 mutex_unlock(&pt1->lock); in pt1_stop_polling()
540 pt1_set_stream(adap->pt1, adap->index, 0); in pt1_stop_feed()
541 pt1_stop_polling(adap->pt1); in pt1_stop_feed()
547 pt1_update_power(struct pt1 *pt1) in pt1_update_power() argument
559 bits = pt1->power | !pt1->reset << 3; in pt1_update_power()
560 mutex_lock(&pt1->lock); in pt1_update_power()
562 adap = pt1->adaps[i]; in pt1_update_power()
577 pt1_write_reg(pt1, 1, bits); in pt1_update_power()
578 mutex_unlock(&pt1->lock); in pt1_update_power()
587 pt1_update_power(adap->pt1); in pt1_set_voltage()
601 pt1_update_power(adap->pt1); in pt1_sleep()
615 pt1_update_power(adap->pt1); in pt1_wakeup()
637 pt1_alloc_adapter(struct pt1 *pt1) in pt1_alloc_adapter() argument
652 adap->pt1 = pt1; in pt1_alloc_adapter()
671 &pt1->pdev->dev, adapter_nr); in pt1_alloc_adapter()
709 static void pt1_cleanup_adapters(struct pt1 *pt1) in pt1_cleanup_adapters() argument
713 pt1_free_adapter(pt1->adaps[i]); in pt1_cleanup_adapters()
716 static int pt1_init_adapters(struct pt1 *pt1) in pt1_init_adapters() argument
723 adap = pt1_alloc_adapter(pt1); in pt1_init_adapters()
730 pt1->adaps[i] = adap; in pt1_init_adapters()
736 pt1_free_adapter(pt1->adaps[i]); in pt1_init_adapters()
765 static void pt1_cleanup_frontends(struct pt1 *pt1) in pt1_cleanup_frontends() argument
769 pt1_cleanup_frontend(pt1->adaps[i]); in pt1_cleanup_frontends()
821 static int pt1_init_frontends(struct pt1 *pt1) in pt1_init_frontends() argument
832 i2c_adap = &pt1->i2c_adap; in pt1_init_frontends()
833 configs = pt1->pdev->device == 0x211a ? pt1_configs : pt2_configs; in pt1_init_frontends()
864 ret = pt1_init_frontend(pt1->adaps[j], fe[j]); in pt1_init_frontends()
881 static void pt1_i2c_emit(struct pt1 *pt1, int addr, int busy, int read_enable, in pt1_i2c_emit() argument
884 pt1_write_reg(pt1, 4, addr << 18 | busy << 13 | read_enable << 12 | in pt1_i2c_emit()
888 static void pt1_i2c_write_bit(struct pt1 *pt1, int addr, int *addrp, int data) in pt1_i2c_write_bit() argument
890 pt1_i2c_emit(pt1, addr, 1, 0, 0, data, addr + 1); in pt1_i2c_write_bit()
891 pt1_i2c_emit(pt1, addr + 1, 1, 0, 1, data, addr + 2); in pt1_i2c_write_bit()
892 pt1_i2c_emit(pt1, addr + 2, 1, 0, 0, data, addr + 3); in pt1_i2c_write_bit()
896 static void pt1_i2c_read_bit(struct pt1 *pt1, int addr, int *addrp) in pt1_i2c_read_bit() argument
898 pt1_i2c_emit(pt1, addr, 1, 0, 0, 1, addr + 1); in pt1_i2c_read_bit()
899 pt1_i2c_emit(pt1, addr + 1, 1, 0, 1, 1, addr + 2); in pt1_i2c_read_bit()
900 pt1_i2c_emit(pt1, addr + 2, 1, 1, 1, 1, addr + 3); in pt1_i2c_read_bit()
901 pt1_i2c_emit(pt1, addr + 3, 1, 0, 0, 1, addr + 4); in pt1_i2c_read_bit()
905 static void pt1_i2c_write_byte(struct pt1 *pt1, int addr, int *addrp, int data) in pt1_i2c_write_byte() argument
909 pt1_i2c_write_bit(pt1, addr, &addr, data >> (7 - i) & 1); in pt1_i2c_write_byte()
910 pt1_i2c_write_bit(pt1, addr, &addr, 1); in pt1_i2c_write_byte()
914 static void pt1_i2c_read_byte(struct pt1 *pt1, int addr, int *addrp, int last) in pt1_i2c_read_byte() argument
918 pt1_i2c_read_bit(pt1, addr, &addr); in pt1_i2c_read_byte()
919 pt1_i2c_write_bit(pt1, addr, &addr, last); in pt1_i2c_read_byte()
923 static void pt1_i2c_prepare(struct pt1 *pt1, int addr, int *addrp) in pt1_i2c_prepare() argument
925 pt1_i2c_emit(pt1, addr, 1, 0, 1, 1, addr + 1); in pt1_i2c_prepare()
926 pt1_i2c_emit(pt1, addr + 1, 1, 0, 1, 0, addr + 2); in pt1_i2c_prepare()
927 pt1_i2c_emit(pt1, addr + 2, 1, 0, 0, 0, addr + 3); in pt1_i2c_prepare()
932 pt1_i2c_write_msg(struct pt1 *pt1, int addr, int *addrp, struct i2c_msg *msg) in pt1_i2c_write_msg() argument
935 pt1_i2c_prepare(pt1, addr, &addr); in pt1_i2c_write_msg()
936 pt1_i2c_write_byte(pt1, addr, &addr, msg->addr << 1); in pt1_i2c_write_msg()
938 pt1_i2c_write_byte(pt1, addr, &addr, msg->buf[i]); in pt1_i2c_write_msg()
943 pt1_i2c_read_msg(struct pt1 *pt1, int addr, int *addrp, struct i2c_msg *msg) in pt1_i2c_read_msg() argument
946 pt1_i2c_prepare(pt1, addr, &addr); in pt1_i2c_read_msg()
947 pt1_i2c_write_byte(pt1, addr, &addr, msg->addr << 1 | 1); in pt1_i2c_read_msg()
949 pt1_i2c_read_byte(pt1, addr, &addr, i == msg->len - 1); in pt1_i2c_read_msg()
953 static int pt1_i2c_end(struct pt1 *pt1, int addr) in pt1_i2c_end() argument
955 pt1_i2c_emit(pt1, addr, 1, 0, 0, 0, addr + 1); in pt1_i2c_end()
956 pt1_i2c_emit(pt1, addr + 1, 1, 0, 1, 0, addr + 2); in pt1_i2c_end()
957 pt1_i2c_emit(pt1, addr + 2, 1, 0, 1, 1, 0); in pt1_i2c_end()
959 pt1_write_reg(pt1, 0, 0x00000004); in pt1_i2c_end()
964 } while (pt1_read_reg(pt1, 0) & 0x00000080); in pt1_i2c_end()
968 static void pt1_i2c_begin(struct pt1 *pt1, int *addrp) in pt1_i2c_begin() argument
973 pt1_i2c_emit(pt1, addr, 0, 0, 1, 1, addr /* itself */); in pt1_i2c_begin()
976 if (!pt1->i2c_running) { in pt1_i2c_begin()
977 pt1_i2c_emit(pt1, addr, 1, 0, 1, 1, addr + 1); in pt1_i2c_begin()
978 pt1_i2c_emit(pt1, addr + 1, 1, 0, 1, 0, addr + 2); in pt1_i2c_begin()
980 pt1->i2c_running = 1; in pt1_i2c_begin()
987 struct pt1 *pt1; in pt1_i2c_xfer() local
994 pt1 = i2c_get_adapdata(adap); in pt1_i2c_xfer()
1013 pt1_i2c_begin(pt1, &addr); in pt1_i2c_xfer()
1014 pt1_i2c_write_msg(pt1, addr, &addr, msg); in pt1_i2c_xfer()
1015 pt1_i2c_read_msg(pt1, addr, &addr, next_msg); in pt1_i2c_xfer()
1016 ret = pt1_i2c_end(pt1, addr); in pt1_i2c_xfer()
1020 word = pt1_read_reg(pt1, 2); in pt1_i2c_xfer()
1026 pt1_i2c_begin(pt1, &addr); in pt1_i2c_xfer()
1027 pt1_i2c_write_msg(pt1, addr, &addr, msg); in pt1_i2c_xfer()
1028 ret = pt1_i2c_end(pt1, addr); in pt1_i2c_xfer()
1047 static void pt1_i2c_wait(struct pt1 *pt1) in pt1_i2c_wait() argument
1051 pt1_i2c_emit(pt1, 0, 0, 0, 1, 1, 0); in pt1_i2c_wait()
1054 static void pt1_i2c_init(struct pt1 *pt1) in pt1_i2c_init() argument
1058 pt1_i2c_emit(pt1, i, 0, 0, 1, 1, 0); in pt1_i2c_init()
1063 struct pt1 *pt1; in pt1_remove() local
1066 pt1 = pci_get_drvdata(pdev); in pt1_remove()
1067 regs = pt1->regs; in pt1_remove()
1069 if (pt1->kthread) in pt1_remove()
1070 kthread_stop(pt1->kthread); in pt1_remove()
1071 pt1_cleanup_tables(pt1); in pt1_remove()
1072 pt1_cleanup_frontends(pt1); in pt1_remove()
1073 pt1_disable_ram(pt1); in pt1_remove()
1074 pt1->power = 0; in pt1_remove()
1075 pt1->reset = 1; in pt1_remove()
1076 pt1_update_power(pt1); in pt1_remove()
1077 pt1_cleanup_adapters(pt1); in pt1_remove()
1078 i2c_del_adapter(&pt1->i2c_adap); in pt1_remove()
1080 kfree(pt1); in pt1_remove()
1091 struct pt1 *pt1; in pt1_probe() local
1114 pt1 = kzalloc(sizeof(struct pt1), GFP_KERNEL); in pt1_probe()
1115 if (!pt1) { in pt1_probe()
1120 mutex_init(&pt1->lock); in pt1_probe()
1121 pt1->pdev = pdev; in pt1_probe()
1122 pt1->regs = regs; in pt1_probe()
1123 pci_set_drvdata(pdev, pt1); in pt1_probe()
1125 ret = pt1_init_adapters(pt1); in pt1_probe()
1129 mutex_init(&pt1->lock); in pt1_probe()
1131 pt1->power = 0; in pt1_probe()
1132 pt1->reset = 1; in pt1_probe()
1133 pt1_update_power(pt1); in pt1_probe()
1135 i2c_adap = &pt1->i2c_adap; in pt1_probe()
1140 i2c_set_adapdata(i2c_adap, pt1); in pt1_probe()
1145 pt1_i2c_init(pt1); in pt1_probe()
1146 pt1_i2c_wait(pt1); in pt1_probe()
1148 ret = pt1_sync(pt1); in pt1_probe()
1152 pt1_identify(pt1); in pt1_probe()
1154 ret = pt1_unlock(pt1); in pt1_probe()
1158 ret = pt1_reset_pci(pt1); in pt1_probe()
1162 ret = pt1_reset_ram(pt1); in pt1_probe()
1166 ret = pt1_enable_ram(pt1); in pt1_probe()
1170 pt1_init_streams(pt1); in pt1_probe()
1172 pt1->power = 1; in pt1_probe()
1173 pt1_update_power(pt1); in pt1_probe()
1176 pt1->reset = 0; in pt1_probe()
1177 pt1_update_power(pt1); in pt1_probe()
1180 ret = pt1_init_frontends(pt1); in pt1_probe()
1184 ret = pt1_init_tables(pt1); in pt1_probe()
1191 pt1_cleanup_frontends(pt1); in pt1_probe()
1193 pt1_disable_ram(pt1); in pt1_probe()
1194 pt1->power = 0; in pt1_probe()
1195 pt1->reset = 1; in pt1_probe()
1196 pt1_update_power(pt1); in pt1_probe()
1200 pt1_cleanup_adapters(pt1); in pt1_probe()
1203 kfree(pt1); in pt1_probe()