[PATCH v3 3/3] fuse: export pipe_max_size for max_pages

2018-08-14 Thread Constantine Shulyupin
Signed-off-by: Constantine Shulyupin 
---
 fs/pipe.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/pipe.c b/fs/pipe.c
index bb0840e234f3..4990d92b0849 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -34,6 +34,7 @@
  * be set by root in /proc/sys/fs/pipe-max-size
  */
 unsigned int pipe_max_size = 1048576;
+EXPORT_SYMBOL(pipe_max_size);
 
 /* Maximum allocatable pages per user. Hard limit is unset by default, soft
  * matches default values.
-- 
2.17.1



[PATCH v3 1/3] fuse: add max_pages option

2018-08-14 Thread Constantine Shulyupin
Replace FUSE_MAX_PAGES_PER_REQ with the configurable
mount parameter max_pages to improve performance.

Old RFC with detailed description of the problem and
many fixes by Mitsuo Hayasaka (mitsuo.hayasaka...@hitachi.com):
 - https://lkml.org/lkml/2012/7/5/136

Changes in v3:
- used clamp_val
- split documentation change
- split EXPORT_SYMBOL(pipe_max_size)

Changes in v2:
- add limitation by pipe_max_size, which was requested in
  https://lkml.org/lkml/2012/7/12/32

Changes in v1: https://lkml.org/lkml/2017/8/6/194
 - replace FUSE_MAX_PAGES_PER_REQ with
   FUSE_DEFAULT_MAX_PAGES_PER_REQ and
   fc->max_pages
 - add mount option max_pages

Signed-off-by: Constantine Shulyupin 
---
 fs/fuse/dev.c|  4 ++--
 fs/fuse/file.c   | 54 
 fs/fuse/fuse_i.h |  5 -
 fs/fuse/inode.c  | 14 +
 4 files changed, 47 insertions(+), 30 deletions(-)

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 11ea2c4a38ab..b324ffc2d82a 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1663,7 +1663,7 @@ static int fuse_retrieve(struct fuse_conn *fc, struct 
inode *inode,
unsigned int num;
unsigned int offset;
size_t total_len = 0;
-   int num_pages;
+   unsigned num_pages;
 
offset = outarg->offset & ~PAGE_MASK;
file_size = i_size_read(inode);
@@ -1675,7 +1675,7 @@ static int fuse_retrieve(struct fuse_conn *fc, struct 
inode *inode,
num = file_size - outarg->offset;
 
num_pages = (num + offset + PAGE_SIZE - 1) >> PAGE_SHIFT;
-   num_pages = min(num_pages, FUSE_MAX_PAGES_PER_REQ);
+   num_pages = min(num_pages, fc->max_pages);
 
req = fuse_get_req(fc, num_pages);
if (IS_ERR(req))
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index fe8d84eb714a..e0924e46ef24 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -847,11 +847,11 @@ static int fuse_readpages_fill(void *_data, struct page 
*page)
fuse_wait_on_page_writeback(inode, page->index);
 
if (req->num_pages &&
-   (req->num_pages == FUSE_MAX_PAGES_PER_REQ ||
+   (req->num_pages == fc->max_pages ||
 (req->num_pages + 1) * PAGE_SIZE > fc->max_read ||
 req->pages[req->num_pages - 1]->index + 1 != page->index)) {
int nr_alloc = min_t(unsigned, data->nr_pages,
-FUSE_MAX_PAGES_PER_REQ);
+fc->max_pages);
fuse_send_readpages(req, data->file);
if (fc->async_read)
req = fuse_get_req_for_background(fc, nr_alloc);
@@ -886,7 +886,7 @@ static int fuse_readpages(struct file *file, struct 
address_space *mapping,
struct fuse_conn *fc = get_fuse_conn(inode);
struct fuse_fill_data data;
int err;
-   int nr_alloc = min_t(unsigned, nr_pages, FUSE_MAX_PAGES_PER_REQ);
+   int nr_alloc = min_t(unsigned, nr_pages, fc->max_pages);
 
err = -EIO;
if (is_bad_inode(inode))
@@ -1101,12 +1101,12 @@ static ssize_t fuse_fill_write_pages(struct fuse_req 
*req,
return count > 0 ? count : err;
 }
 
-static inline unsigned fuse_wr_pages(loff_t pos, size_t len)
+static inline unsigned fuse_wr_pages(loff_t pos, size_t len, unsigned 
max_pages)
 {
return min_t(unsigned,
 ((pos + len - 1) >> PAGE_SHIFT) -
 (pos >> PAGE_SHIFT) + 1,
-FUSE_MAX_PAGES_PER_REQ);
+max_pages);
 }
 
 static ssize_t fuse_perform_write(struct kiocb *iocb,
@@ -1128,7 +1128,8 @@ static ssize_t fuse_perform_write(struct kiocb *iocb,
do {
struct fuse_req *req;
ssize_t count;
-   unsigned nr_pages = fuse_wr_pages(pos, iov_iter_count(ii));
+   unsigned nr_pages = fuse_wr_pages(pos, iov_iter_count(ii),
+ fc->max_pages);
 
req = fuse_get_req(fc, nr_pages);
if (IS_ERR(req)) {
@@ -1318,11 +1319,6 @@ static int fuse_get_user_pages(struct fuse_req *req, 
struct iov_iter *ii,
return ret < 0 ? ret : 0;
 }
 
-static inline int fuse_iter_npages(const struct iov_iter *ii_p)
-{
-   return iov_iter_npages(ii_p, FUSE_MAX_PAGES_PER_REQ);
-}
-
 ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
   loff_t *ppos, int flags)
 {
@@ -1342,9 +1338,10 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, struct 
iov_iter *iter,
int err = 0;
 
if (io->async)
-   req = fuse_get_req_for_background(fc, fuse_iter_npages(iter));
+   req = fuse_get_req_for_background(fc, iov_iter_npages(iter,
+   fc->max_pages));
else
-   req = fuse_get_req(fc, fuse_iter_npages(

[PATCH v3 3/3] fuse: export pipe_max_size for max_pages

2018-08-14 Thread Constantine Shulyupin
Signed-off-by: Constantine Shulyupin 
---
 fs/pipe.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/pipe.c b/fs/pipe.c
index bb0840e234f3..4990d92b0849 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -34,6 +34,7 @@
  * be set by root in /proc/sys/fs/pipe-max-size
  */
 unsigned int pipe_max_size = 1048576;
+EXPORT_SYMBOL(pipe_max_size);
 
 /* Maximum allocatable pages per user. Hard limit is unset by default, soft
  * matches default values.
-- 
2.17.1



[PATCH v3 1/3] fuse: add max_pages option

2018-08-14 Thread Constantine Shulyupin
Replace FUSE_MAX_PAGES_PER_REQ with the configurable
mount parameter max_pages to improve performance.

Old RFC with detailed description of the problem and
many fixes by Mitsuo Hayasaka (mitsuo.hayasaka...@hitachi.com):
 - https://lkml.org/lkml/2012/7/5/136

Changes in v3:
- used clamp_val
- split documentation change
- split EXPORT_SYMBOL(pipe_max_size)

Changes in v2:
- add limitation by pipe_max_size, which was requested in
  https://lkml.org/lkml/2012/7/12/32

Changes in v1: https://lkml.org/lkml/2017/8/6/194
 - replace FUSE_MAX_PAGES_PER_REQ with
   FUSE_DEFAULT_MAX_PAGES_PER_REQ and
   fc->max_pages
 - add mount option max_pages

Signed-off-by: Constantine Shulyupin 
---
 fs/fuse/dev.c|  4 ++--
 fs/fuse/file.c   | 54 
 fs/fuse/fuse_i.h |  5 -
 fs/fuse/inode.c  | 14 +
 4 files changed, 47 insertions(+), 30 deletions(-)

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 11ea2c4a38ab..b324ffc2d82a 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1663,7 +1663,7 @@ static int fuse_retrieve(struct fuse_conn *fc, struct 
inode *inode,
unsigned int num;
unsigned int offset;
size_t total_len = 0;
-   int num_pages;
+   unsigned num_pages;
 
offset = outarg->offset & ~PAGE_MASK;
file_size = i_size_read(inode);
@@ -1675,7 +1675,7 @@ static int fuse_retrieve(struct fuse_conn *fc, struct 
inode *inode,
num = file_size - outarg->offset;
 
num_pages = (num + offset + PAGE_SIZE - 1) >> PAGE_SHIFT;
-   num_pages = min(num_pages, FUSE_MAX_PAGES_PER_REQ);
+   num_pages = min(num_pages, fc->max_pages);
 
req = fuse_get_req(fc, num_pages);
if (IS_ERR(req))
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index fe8d84eb714a..e0924e46ef24 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -847,11 +847,11 @@ static int fuse_readpages_fill(void *_data, struct page 
*page)
fuse_wait_on_page_writeback(inode, page->index);
 
if (req->num_pages &&
-   (req->num_pages == FUSE_MAX_PAGES_PER_REQ ||
+   (req->num_pages == fc->max_pages ||
 (req->num_pages + 1) * PAGE_SIZE > fc->max_read ||
 req->pages[req->num_pages - 1]->index + 1 != page->index)) {
int nr_alloc = min_t(unsigned, data->nr_pages,
-FUSE_MAX_PAGES_PER_REQ);
+fc->max_pages);
fuse_send_readpages(req, data->file);
if (fc->async_read)
req = fuse_get_req_for_background(fc, nr_alloc);
@@ -886,7 +886,7 @@ static int fuse_readpages(struct file *file, struct 
address_space *mapping,
struct fuse_conn *fc = get_fuse_conn(inode);
struct fuse_fill_data data;
int err;
-   int nr_alloc = min_t(unsigned, nr_pages, FUSE_MAX_PAGES_PER_REQ);
+   int nr_alloc = min_t(unsigned, nr_pages, fc->max_pages);
 
err = -EIO;
if (is_bad_inode(inode))
@@ -1101,12 +1101,12 @@ static ssize_t fuse_fill_write_pages(struct fuse_req 
*req,
return count > 0 ? count : err;
 }
 
-static inline unsigned fuse_wr_pages(loff_t pos, size_t len)
+static inline unsigned fuse_wr_pages(loff_t pos, size_t len, unsigned 
max_pages)
 {
return min_t(unsigned,
 ((pos + len - 1) >> PAGE_SHIFT) -
 (pos >> PAGE_SHIFT) + 1,
-FUSE_MAX_PAGES_PER_REQ);
+max_pages);
 }
 
 static ssize_t fuse_perform_write(struct kiocb *iocb,
@@ -1128,7 +1128,8 @@ static ssize_t fuse_perform_write(struct kiocb *iocb,
do {
struct fuse_req *req;
ssize_t count;
-   unsigned nr_pages = fuse_wr_pages(pos, iov_iter_count(ii));
+   unsigned nr_pages = fuse_wr_pages(pos, iov_iter_count(ii),
+ fc->max_pages);
 
req = fuse_get_req(fc, nr_pages);
if (IS_ERR(req)) {
@@ -1318,11 +1319,6 @@ static int fuse_get_user_pages(struct fuse_req *req, 
struct iov_iter *ii,
return ret < 0 ? ret : 0;
 }
 
-static inline int fuse_iter_npages(const struct iov_iter *ii_p)
-{
-   return iov_iter_npages(ii_p, FUSE_MAX_PAGES_PER_REQ);
-}
-
 ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
   loff_t *ppos, int flags)
 {
@@ -1342,9 +1338,10 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, struct 
iov_iter *iter,
int err = 0;
 
if (io->async)
-   req = fuse_get_req_for_background(fc, fuse_iter_npages(iter));
+   req = fuse_get_req_for_background(fc, iov_iter_npages(iter,
+   fc->max_pages));
else
-   req = fuse_get_req(fc, fuse_iter_npages(

[PATCH] drivers/char/random.c: fix uninitialized value warning

2018-07-18 Thread Constantine Shulyupin
Local variable t should be initialized by arch_get_random_int.
Actually on failure of arch_get_random_int, value is not used.
So, just keep the build clean with less warnings.

warning:
drivers/char/random.c: In function ‘write_pool.constprop’:
drivers/char/random.c:1912:11: warning: ‘t’ may be used uninitialized in this 
function [-Wmaybe-uninitialized]

Signed-off-by: Constantine Shulyupin 
---
 drivers/char/random.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 283fe390e878..8e51846d0673 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1896,7 +1896,7 @@ static int
 write_pool(struct entropy_store *r, const char __user *buffer, size_t count)
 {
size_t bytes;
-   __u32 t, buf[16];
+   __u32 t = 0, buf[16];
const char __user *p = buffer;
 
while (count > 0) {
-- 
2.17.1



[PATCH] drivers/char/random.c: fix uninitialized value warning

2018-07-18 Thread Constantine Shulyupin
Local variable t should be initialized by arch_get_random_int.
Actually on failure of arch_get_random_int, value is not used.
So, just keep the build clean with less warnings.

warning:
drivers/char/random.c: In function ‘write_pool.constprop’:
drivers/char/random.c:1912:11: warning: ‘t’ may be used uninitialized in this 
function [-Wmaybe-uninitialized]

Signed-off-by: Constantine Shulyupin 
---
 drivers/char/random.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 283fe390e878..8e51846d0673 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1896,7 +1896,7 @@ static int
 write_pool(struct entropy_store *r, const char __user *buffer, size_t count)
 {
size_t bytes;
-   __u32 t, buf[16];
+   __u32 t = 0, buf[16];
const char __user *p = buffer;
 
while (count > 0) {
-- 
2.17.1



[PATCH] MAINTAINERS: Add samples/mic/

2018-07-11 Thread Constantine Shulyupin
Signed-off-by: Constantine Shulyupin 
---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index b40d702337f2..42c439b5cd6a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7303,6 +7303,7 @@ F:drivers/misc/mic/
 F: drivers/dma/mic_x100_dma.c
 F: drivers/dma/mic_x100_dma.h
 F: Documentation/mic/
+F: samples/mic/
 
 INTEL PMC CORE DRIVER
 M: Rajneesh Bhardwaj 
-- 
2.17.1



[PATCH] MAINTAINERS: Add samples/mic/

2018-07-11 Thread Constantine Shulyupin
Signed-off-by: Constantine Shulyupin 
---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index b40d702337f2..42c439b5cd6a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7303,6 +7303,7 @@ F:drivers/misc/mic/
 F: drivers/dma/mic_x100_dma.c
 F: drivers/dma/mic_x100_dma.h
 F: Documentation/mic/
+F: samples/mic/
 
 INTEL PMC CORE DRIVER
 M: Rajneesh Bhardwaj 
-- 
2.17.1



[PATCH] samples: fix compilation of mpssd

2018-07-11 Thread Constantine Shulyupin
Errors:

In file included from /usr/include/x86_64-linux-gnu/sys/types.h:194:0,
 from /usr/include/stdlib.h:394,
 from mpssd.c:23:
mpssd.c:93:10: error: initializer element is not constant
   .num = htole16(MIC_VRING_ENTRIES),

mpssd.c:610:10: warning: implicit declaration of function ‘readv’;

Signed-off-by: Constantine Shulyupin 
---
 samples/mic/mpssd/mpssd.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/samples/mic/mpssd/mpssd.c b/samples/mic/mpssd/mpssd.c
index f42ce551bb48..9cddb9cfdc79 100644
--- a/samples/mic/mpssd/mpssd.c
+++ b/samples/mic/mpssd/mpssd.c
@@ -33,6 +33,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -77,6 +78,10 @@ static struct mic_info mic_list;
 #define VIRTIO_NET_HDR_F_DATA_VALID2   /* Csum is valid */
 #endif
 
+#define __uint16_identity(x) (x)
+#define __uint64_identity(x) (x)
+#define __uint32_identity(x) (x)
+
 static struct {
struct mic_device_desc dd;
struct mic_vqconfig vqconfig[2];
-- 
2.17.1



[PATCH] samples: fix compilation of mpssd

2018-07-11 Thread Constantine Shulyupin
Errors:

In file included from /usr/include/x86_64-linux-gnu/sys/types.h:194:0,
 from /usr/include/stdlib.h:394,
 from mpssd.c:23:
mpssd.c:93:10: error: initializer element is not constant
   .num = htole16(MIC_VRING_ENTRIES),

mpssd.c:610:10: warning: implicit declaration of function ‘readv’;

Signed-off-by: Constantine Shulyupin 
---
 samples/mic/mpssd/mpssd.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/samples/mic/mpssd/mpssd.c b/samples/mic/mpssd/mpssd.c
index f42ce551bb48..9cddb9cfdc79 100644
--- a/samples/mic/mpssd/mpssd.c
+++ b/samples/mic/mpssd/mpssd.c
@@ -33,6 +33,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -77,6 +78,10 @@ static struct mic_info mic_list;
 #define VIRTIO_NET_HDR_F_DATA_VALID2   /* Csum is valid */
 #endif
 
+#define __uint16_identity(x) (x)
+#define __uint64_identity(x) (x)
+#define __uint32_identity(x) (x)
+
 static struct {
struct mic_device_desc dd;
struct mic_vqconfig vqconfig[2];
-- 
2.17.1



[PATCH] scripts/tags.sh: add __ro_after_init

2018-07-11 Thread Constantine Shulyupin
Signed-off-by: Constantine Shulyupin 
---
 scripts/tags.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/tags.sh b/scripts/tags.sh
index 66f08bb1cce9..412a70cce558 100755
--- a/scripts/tags.sh
+++ b/scripts/tags.sh
@@ -245,7 +245,7 @@ exuberant()
 {
setup_regex exuberant asm c
all_target_sources | xargs $1 -a\
-   -I __initdata,__exitdata,__initconst,   \
+   -I __initdata,__exitdata,__initconst,__ro_after_init\
-I __initdata_memblock  \
-I __refdata,__attribute,__maybe_unused,__always_unused \
-I __acquires,__releases,__deprecated   \
-- 
2.17.1



[PATCH] scripts/tags.sh: add __ro_after_init

2018-07-11 Thread Constantine Shulyupin
Signed-off-by: Constantine Shulyupin 
---
 scripts/tags.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/tags.sh b/scripts/tags.sh
index 66f08bb1cce9..412a70cce558 100755
--- a/scripts/tags.sh
+++ b/scripts/tags.sh
@@ -245,7 +245,7 @@ exuberant()
 {
setup_regex exuberant asm c
all_target_sources | xargs $1 -a\
-   -I __initdata,__exitdata,__initconst,   \
+   -I __initdata,__exitdata,__initconst,__ro_after_init\
-I __initdata_memblock  \
-I __refdata,__attribute,__maybe_unused,__always_unused \
-I __acquires,__releases,__deprecated   \
-- 
2.17.1



[PATCH v1] samples: fix compilatin of mpssd

2018-07-07 Thread Constantine Shulyupin
Errors:

In file included from /usr/include/x86_64-linux-gnu/sys/types.h:194:0,
 from /usr/include/stdlib.h:394,
 from mpssd.c:23:
mpssd.c:93:10: error: initializer element is not constant
   .num = htole16(MIC_VRING_ENTRIES),

mpssd.c:610:10: warning: implicit declaration of function ‘readv’;

Signed-off-by: Constantine Shulyupin 
---
 samples/mic/mpssd/mpssd.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/samples/mic/mpssd/mpssd.c b/samples/mic/mpssd/mpssd.c
index f42ce551bb48..9cddb9cfdc79 100644
--- a/samples/mic/mpssd/mpssd.c
+++ b/samples/mic/mpssd/mpssd.c
@@ -33,6 +33,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -77,6 +78,10 @@ static struct mic_info mic_list;
 #define VIRTIO_NET_HDR_F_DATA_VALID2   /* Csum is valid */
 #endif
 
+#define __uint16_identity(x) (x)
+#define __uint64_identity(x) (x)
+#define __uint32_identity(x) (x)
+
 static struct {
struct mic_device_desc dd;
struct mic_vqconfig vqconfig[2];
-- 
2.17.1



[PATCH v1] samples: fix compilatin of mpssd

2018-07-07 Thread Constantine Shulyupin
Errors:

In file included from /usr/include/x86_64-linux-gnu/sys/types.h:194:0,
 from /usr/include/stdlib.h:394,
 from mpssd.c:23:
mpssd.c:93:10: error: initializer element is not constant
   .num = htole16(MIC_VRING_ENTRIES),

mpssd.c:610:10: warning: implicit declaration of function ‘readv’;

Signed-off-by: Constantine Shulyupin 
---
 samples/mic/mpssd/mpssd.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/samples/mic/mpssd/mpssd.c b/samples/mic/mpssd/mpssd.c
index f42ce551bb48..9cddb9cfdc79 100644
--- a/samples/mic/mpssd/mpssd.c
+++ b/samples/mic/mpssd/mpssd.c
@@ -33,6 +33,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -77,6 +78,10 @@ static struct mic_info mic_list;
 #define VIRTIO_NET_HDR_F_DATA_VALID2   /* Csum is valid */
 #endif
 
+#define __uint16_identity(x) (x)
+#define __uint64_identity(x) (x)
+#define __uint32_identity(x) (x)
+
 static struct {
struct mic_device_desc dd;
struct mic_vqconfig vqconfig[2];
-- 
2.17.1



[PATCH v2] fuse: +max_pages

2018-07-04 Thread Constantine Shulyupin
Replace FUSE_MAX_PAGES_PER_REQ with the configurable
mount parameter max_pages to improve performance.

Old RFC with detailed description of the problem and
many fixes by Mitsuo Hayasaka (mitsuo.hayasaka...@hitachi.com):
 - https://lkml.org/lkml/2012/7/5/136

Changes in v2:
- add limitation by pipe_max_size, which was requested in
  https://lkml.org/lkml/2012/7/12/32

Changes in v1: https://lkml.org/lkml/2017/8/6/194
 - replace FUSE_MAX_PAGES_PER_REQ with
   FUSE_DEFAULT_MAX_PAGES_PER_REQ and
   fc->max_pages
 - add mount option max_pages

Signed-off-by: Constantine Shulyupin 
---
 Documentation/filesystems/fuse.txt |  5 ++-
 fs/fuse/dev.c  |  4 +--
 fs/fuse/file.c | 54 +++---
 fs/fuse/fuse_i.h   |  5 ++-
 fs/fuse/inode.c| 15 +
 fs/pipe.c  |  1 +
 6 files changed, 53 insertions(+), 31 deletions(-)

diff --git a/Documentation/filesystems/fuse.txt 
b/Documentation/filesystems/fuse.txt
index 13af4a49e7db..d4e832fe9ce6 100644
--- a/Documentation/filesystems/fuse.txt
+++ b/Documentation/filesystems/fuse.txt
@@ -108,7 +108,10 @@ Mount options
 
   With this option the maximum size of read operations can be set.
   The default is infinite.  Note that the size of read requests is
-  limited anyway to 32 pages (which is 128kbyte on i386).
+  limited anyway to max_pages (which by default is 32 or 128KB on x86).
+
+'max_pages=N'
+   Maximal number of pages per request. The default is 32 or 128KB on x86.
 
 'blksize=N'
 
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index e03ca14f40e9..f51100505c5b 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1648,7 +1648,7 @@ static int fuse_retrieve(struct fuse_conn *fc, struct 
inode *inode,
unsigned int num;
unsigned int offset;
size_t total_len = 0;
-   int num_pages;
+   unsigned num_pages;
 
offset = outarg->offset & ~PAGE_MASK;
file_size = i_size_read(inode);
@@ -1660,7 +1660,7 @@ static int fuse_retrieve(struct fuse_conn *fc, struct 
inode *inode,
num = file_size - outarg->offset;
 
num_pages = (num + offset + PAGE_SIZE - 1) >> PAGE_SHIFT;
-   num_pages = min(num_pages, FUSE_MAX_PAGES_PER_REQ);
+   num_pages = min(num_pages, fc->max_pages);
 
req = fuse_get_req(fc, num_pages);
if (IS_ERR(req))
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index a201fb0ac64f..e145a3ef0439 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -847,11 +847,11 @@ static int fuse_readpages_fill(void *_data, struct page 
*page)
fuse_wait_on_page_writeback(inode, page->index);
 
if (req->num_pages &&
-   (req->num_pages == FUSE_MAX_PAGES_PER_REQ ||
+   (req->num_pages == fc->max_pages ||
 (req->num_pages + 1) * PAGE_SIZE > fc->max_read ||
 req->pages[req->num_pages - 1]->index + 1 != page->index)) {
int nr_alloc = min_t(unsigned, data->nr_pages,
-FUSE_MAX_PAGES_PER_REQ);
+fc->max_pages);
fuse_send_readpages(req, data->file);
if (fc->async_read)
req = fuse_get_req_for_background(fc, nr_alloc);
@@ -885,7 +885,7 @@ static int fuse_readpages(struct file *file, struct 
address_space *mapping,
struct fuse_conn *fc = get_fuse_conn(inode);
struct fuse_fill_data data;
int err;
-   int nr_alloc = min_t(unsigned, nr_pages, FUSE_MAX_PAGES_PER_REQ);
+   int nr_alloc = min_t(unsigned, nr_pages, fc->max_pages);
 
err = -EIO;
if (is_bad_inode(inode))
@@ -1100,12 +1100,12 @@ static ssize_t fuse_fill_write_pages(struct fuse_req 
*req,
return count > 0 ? count : err;
 }
 
-static inline unsigned fuse_wr_pages(loff_t pos, size_t len)
+static inline unsigned fuse_wr_pages(loff_t pos, size_t len, unsigned 
max_pages)
 {
return min_t(unsigned,
 ((pos + len - 1) >> PAGE_SHIFT) -
 (pos >> PAGE_SHIFT) + 1,
-FUSE_MAX_PAGES_PER_REQ);
+max_pages);
 }
 
 static ssize_t fuse_perform_write(struct kiocb *iocb,
@@ -1127,7 +1127,8 @@ static ssize_t fuse_perform_write(struct kiocb *iocb,
do {
struct fuse_req *req;
ssize_t count;
-   unsigned nr_pages = fuse_wr_pages(pos, iov_iter_count(ii));
+   unsigned nr_pages = fuse_wr_pages(pos, iov_iter_count(ii),
+ fc->max_pages);
 
req = fuse_get_req(fc, nr_pages);
if (IS_ERR(req)) {
@@ -1317,11 +1318,6 @@ static int fuse_get_user_pages(struct fuse_req *req, 
struct iov_iter *ii,
return ret < 0 ? ret : 0;
 }
 
-static inline int fuse_iter_npages(const struct iov_iter *ii_p

[PATCH v2] fuse: +max_pages

2018-07-04 Thread Constantine Shulyupin
Replace FUSE_MAX_PAGES_PER_REQ with the configurable
mount parameter max_pages to improve performance.

Old RFC with detailed description of the problem and
many fixes by Mitsuo Hayasaka (mitsuo.hayasaka...@hitachi.com):
 - https://lkml.org/lkml/2012/7/5/136

Changes in v2:
- add limitation by pipe_max_size, which was requested in
  https://lkml.org/lkml/2012/7/12/32

Changes in v1: https://lkml.org/lkml/2017/8/6/194
 - replace FUSE_MAX_PAGES_PER_REQ with
   FUSE_DEFAULT_MAX_PAGES_PER_REQ and
   fc->max_pages
 - add mount option max_pages

Signed-off-by: Constantine Shulyupin 
---
 Documentation/filesystems/fuse.txt |  5 ++-
 fs/fuse/dev.c  |  4 +--
 fs/fuse/file.c | 54 +++---
 fs/fuse/fuse_i.h   |  5 ++-
 fs/fuse/inode.c| 15 +
 fs/pipe.c  |  1 +
 6 files changed, 53 insertions(+), 31 deletions(-)

diff --git a/Documentation/filesystems/fuse.txt 
b/Documentation/filesystems/fuse.txt
index 13af4a49e7db..d4e832fe9ce6 100644
--- a/Documentation/filesystems/fuse.txt
+++ b/Documentation/filesystems/fuse.txt
@@ -108,7 +108,10 @@ Mount options
 
   With this option the maximum size of read operations can be set.
   The default is infinite.  Note that the size of read requests is
-  limited anyway to 32 pages (which is 128kbyte on i386).
+  limited anyway to max_pages (which by default is 32 or 128KB on x86).
+
+'max_pages=N'
+   Maximal number of pages per request. The default is 32 or 128KB on x86.
 
 'blksize=N'
 
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index e03ca14f40e9..f51100505c5b 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1648,7 +1648,7 @@ static int fuse_retrieve(struct fuse_conn *fc, struct 
inode *inode,
unsigned int num;
unsigned int offset;
size_t total_len = 0;
-   int num_pages;
+   unsigned num_pages;
 
offset = outarg->offset & ~PAGE_MASK;
file_size = i_size_read(inode);
@@ -1660,7 +1660,7 @@ static int fuse_retrieve(struct fuse_conn *fc, struct 
inode *inode,
num = file_size - outarg->offset;
 
num_pages = (num + offset + PAGE_SIZE - 1) >> PAGE_SHIFT;
-   num_pages = min(num_pages, FUSE_MAX_PAGES_PER_REQ);
+   num_pages = min(num_pages, fc->max_pages);
 
req = fuse_get_req(fc, num_pages);
if (IS_ERR(req))
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index a201fb0ac64f..e145a3ef0439 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -847,11 +847,11 @@ static int fuse_readpages_fill(void *_data, struct page 
*page)
fuse_wait_on_page_writeback(inode, page->index);
 
if (req->num_pages &&
-   (req->num_pages == FUSE_MAX_PAGES_PER_REQ ||
+   (req->num_pages == fc->max_pages ||
 (req->num_pages + 1) * PAGE_SIZE > fc->max_read ||
 req->pages[req->num_pages - 1]->index + 1 != page->index)) {
int nr_alloc = min_t(unsigned, data->nr_pages,
-FUSE_MAX_PAGES_PER_REQ);
+fc->max_pages);
fuse_send_readpages(req, data->file);
if (fc->async_read)
req = fuse_get_req_for_background(fc, nr_alloc);
@@ -885,7 +885,7 @@ static int fuse_readpages(struct file *file, struct 
address_space *mapping,
struct fuse_conn *fc = get_fuse_conn(inode);
struct fuse_fill_data data;
int err;
-   int nr_alloc = min_t(unsigned, nr_pages, FUSE_MAX_PAGES_PER_REQ);
+   int nr_alloc = min_t(unsigned, nr_pages, fc->max_pages);
 
err = -EIO;
if (is_bad_inode(inode))
@@ -1100,12 +1100,12 @@ static ssize_t fuse_fill_write_pages(struct fuse_req 
*req,
return count > 0 ? count : err;
 }
 
-static inline unsigned fuse_wr_pages(loff_t pos, size_t len)
+static inline unsigned fuse_wr_pages(loff_t pos, size_t len, unsigned 
max_pages)
 {
return min_t(unsigned,
 ((pos + len - 1) >> PAGE_SHIFT) -
 (pos >> PAGE_SHIFT) + 1,
-FUSE_MAX_PAGES_PER_REQ);
+max_pages);
 }
 
 static ssize_t fuse_perform_write(struct kiocb *iocb,
@@ -1127,7 +1127,8 @@ static ssize_t fuse_perform_write(struct kiocb *iocb,
do {
struct fuse_req *req;
ssize_t count;
-   unsigned nr_pages = fuse_wr_pages(pos, iov_iter_count(ii));
+   unsigned nr_pages = fuse_wr_pages(pos, iov_iter_count(ii),
+ fc->max_pages);
 
req = fuse_get_req(fc, nr_pages);
if (IS_ERR(req)) {
@@ -1317,11 +1318,6 @@ static int fuse_get_user_pages(struct fuse_req *req, 
struct iov_iter *ii,
return ret < 0 ? ret : 0;
 }
 
-static inline int fuse_iter_npages(const struct iov_iter *ii_p

[PATCH v1] fuse: add configurable max_pages parameter

2017-08-06 Thread Constantine Shulyupin
Replace define FUSE_MAX_PAGES_PER_REQ with the configurable
mount parameter max_pages to improve performance.
To utilize the max_pages parameter you must also increase the
value of bufsize in the user mode library.

Signed-off-by: Constantine Shulyupin <co...@makelinux.com>
---
 Documentation/filesystems/fuse.txt |  5 +++-
 fs/fuse/dev.c  |  2 +-
 fs/fuse/file.c | 54 +-
 fs/fuse/fuse_i.h   |  5 +++-
 fs/fuse/inode.c| 12 +
 5 files changed, 51 insertions(+), 27 deletions(-)

diff --git a/Documentation/filesystems/fuse.txt 
b/Documentation/filesystems/fuse.txt
index 13af4a4..d4e832f 100644
--- a/Documentation/filesystems/fuse.txt
+++ b/Documentation/filesystems/fuse.txt
@@ -108,7 +108,10 @@ Mount options
 
   With this option the maximum size of read operations can be set.
   The default is infinite.  Note that the size of read requests is
-  limited anyway to 32 pages (which is 128kbyte on i386).
+  limited anyway to max_pages (which by default is 32 or 128KB on x86).
+
+'max_pages=N'
+   Maximal number of pages per request. The default is 32 or 128KB on x86.
 
 'blksize=N'
 
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index ebb5e37..f750f30 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1707,7 +1707,7 @@ static int fuse_retrieve(struct fuse_conn *fc, struct 
inode *inode,
num = file_size - outarg->offset;
 
num_pages = (num + offset + PAGE_SIZE - 1) >> PAGE_SHIFT;
-   num_pages = min(num_pages, FUSE_MAX_PAGES_PER_REQ);
+   num_pages = min(num_pages, fc->max_pages);
 
req = fuse_get_req(fc, num_pages);
if (IS_ERR(req))
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 6c0aed7..de00cf3 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -861,11 +861,11 @@ static int fuse_readpages_fill(void *_data, struct page 
*page)
fuse_wait_on_page_writeback(inode, page->index);
 
if (req->num_pages &&
-   (req->num_pages == FUSE_MAX_PAGES_PER_REQ ||
+   (req->num_pages == fc->max_pages ||
 (req->num_pages + 1) * PAGE_CACHE_SIZE > fc->max_read ||
 req->pages[req->num_pages - 1]->index + 1 != page->index)) {
int nr_alloc = min_t(unsigned, data->nr_pages,
-FUSE_MAX_PAGES_PER_REQ);
+fc->max_pages);
fuse_send_readpages(req, data->file);
if (fc->async_read)
req = fuse_get_req_for_background(fc, nr_alloc);
@@ -901,7 +901,7 @@ static int fuse_readpages(struct file *file, struct 
address_space *mapping,
struct fuse_conn *fc = get_fuse_conn(inode);
struct fuse_fill_data data;
int err;
-   int nr_alloc = min_t(unsigned, nr_pages, FUSE_MAX_PAGES_PER_REQ);
+   int nr_alloc = min_t(unsigned, nr_pages, fc->max_pages);
 
err = -EIO;
if (is_bad_inode(inode))
@@ -,12 +,12 @@ static ssize_t fuse_fill_write_pages(struct fuse_req 
*req,
return count > 0 ? count : err;
 }
 
-static inline unsigned fuse_wr_pages(loff_t pos, size_t len)
+static inline unsigned fuse_wr_pages(loff_t pos, size_t len, unsigned 
max_pages)
 {
return min_t(unsigned,
 ((pos + len - 1) >> PAGE_CACHE_SHIFT) -
 (pos >> PAGE_CACHE_SHIFT) + 1,
-FUSE_MAX_PAGES_PER_REQ);
+max_pages);
 }
 
 static ssize_t fuse_perform_write(struct file *file,
@@ -1138,7 +1138,8 @@ static ssize_t fuse_perform_write(struct file *file,
do {
struct fuse_req *req;
ssize_t count;
-   unsigned nr_pages = fuse_wr_pages(pos, iov_iter_count(ii));
+   unsigned nr_pages = fuse_wr_pages(pos, iov_iter_count(ii),
+ fc->max_pages);
 
req = fuse_get_req(fc, nr_pages);
if (IS_ERR(req)) {
@@ -1326,9 +1327,10 @@ static int fuse_get_user_pages(struct fuse_req *req, 
struct iov_iter *ii,
return 0;
 }
 
-static inline int fuse_iter_npages(const struct iov_iter *ii_p)
+static inline int fuse_iter_npages(struct fuse_conn *fc,
+  const struct iov_iter *ii_p)
 {
-   return iov_iter_npages(ii_p, FUSE_MAX_PAGES_PER_REQ);
+   return iov_iter_npages(ii_p, fc->max_pages);
 }
 
 ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
@@ -1350,9 +1352,10 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, struct 
iov_iter *iter,
struct fuse_req *req;
 
if (io->async)
-   req = fuse_get_req_for_background(fc, fuse_iter_npages(iter));
+   req = fuse_get_req_for_background(fc,
+ fuse_iter_npages(fc, iter));
else

[PATCH v1] fuse: add configurable max_pages parameter

2017-08-06 Thread Constantine Shulyupin
Replace define FUSE_MAX_PAGES_PER_REQ with the configurable
mount parameter max_pages to improve performance.
To utilize the max_pages parameter you must also increase the
value of bufsize in the user mode library.

Signed-off-by: Constantine Shulyupin 
---
 Documentation/filesystems/fuse.txt |  5 +++-
 fs/fuse/dev.c  |  2 +-
 fs/fuse/file.c | 54 +-
 fs/fuse/fuse_i.h   |  5 +++-
 fs/fuse/inode.c| 12 +
 5 files changed, 51 insertions(+), 27 deletions(-)

diff --git a/Documentation/filesystems/fuse.txt 
b/Documentation/filesystems/fuse.txt
index 13af4a4..d4e832f 100644
--- a/Documentation/filesystems/fuse.txt
+++ b/Documentation/filesystems/fuse.txt
@@ -108,7 +108,10 @@ Mount options
 
   With this option the maximum size of read operations can be set.
   The default is infinite.  Note that the size of read requests is
-  limited anyway to 32 pages (which is 128kbyte on i386).
+  limited anyway to max_pages (which by default is 32 or 128KB on x86).
+
+'max_pages=N'
+   Maximal number of pages per request. The default is 32 or 128KB on x86.
 
 'blksize=N'
 
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index ebb5e37..f750f30 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1707,7 +1707,7 @@ static int fuse_retrieve(struct fuse_conn *fc, struct 
inode *inode,
num = file_size - outarg->offset;
 
num_pages = (num + offset + PAGE_SIZE - 1) >> PAGE_SHIFT;
-   num_pages = min(num_pages, FUSE_MAX_PAGES_PER_REQ);
+   num_pages = min(num_pages, fc->max_pages);
 
req = fuse_get_req(fc, num_pages);
if (IS_ERR(req))
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 6c0aed7..de00cf3 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -861,11 +861,11 @@ static int fuse_readpages_fill(void *_data, struct page 
*page)
fuse_wait_on_page_writeback(inode, page->index);
 
if (req->num_pages &&
-   (req->num_pages == FUSE_MAX_PAGES_PER_REQ ||
+   (req->num_pages == fc->max_pages ||
 (req->num_pages + 1) * PAGE_CACHE_SIZE > fc->max_read ||
 req->pages[req->num_pages - 1]->index + 1 != page->index)) {
int nr_alloc = min_t(unsigned, data->nr_pages,
-FUSE_MAX_PAGES_PER_REQ);
+fc->max_pages);
fuse_send_readpages(req, data->file);
if (fc->async_read)
req = fuse_get_req_for_background(fc, nr_alloc);
@@ -901,7 +901,7 @@ static int fuse_readpages(struct file *file, struct 
address_space *mapping,
struct fuse_conn *fc = get_fuse_conn(inode);
struct fuse_fill_data data;
int err;
-   int nr_alloc = min_t(unsigned, nr_pages, FUSE_MAX_PAGES_PER_REQ);
+   int nr_alloc = min_t(unsigned, nr_pages, fc->max_pages);
 
err = -EIO;
if (is_bad_inode(inode))
@@ -,12 +,12 @@ static ssize_t fuse_fill_write_pages(struct fuse_req 
*req,
return count > 0 ? count : err;
 }
 
-static inline unsigned fuse_wr_pages(loff_t pos, size_t len)
+static inline unsigned fuse_wr_pages(loff_t pos, size_t len, unsigned 
max_pages)
 {
return min_t(unsigned,
 ((pos + len - 1) >> PAGE_CACHE_SHIFT) -
 (pos >> PAGE_CACHE_SHIFT) + 1,
-FUSE_MAX_PAGES_PER_REQ);
+max_pages);
 }
 
 static ssize_t fuse_perform_write(struct file *file,
@@ -1138,7 +1138,8 @@ static ssize_t fuse_perform_write(struct file *file,
do {
struct fuse_req *req;
ssize_t count;
-   unsigned nr_pages = fuse_wr_pages(pos, iov_iter_count(ii));
+   unsigned nr_pages = fuse_wr_pages(pos, iov_iter_count(ii),
+ fc->max_pages);
 
req = fuse_get_req(fc, nr_pages);
if (IS_ERR(req)) {
@@ -1326,9 +1327,10 @@ static int fuse_get_user_pages(struct fuse_req *req, 
struct iov_iter *ii,
return 0;
 }
 
-static inline int fuse_iter_npages(const struct iov_iter *ii_p)
+static inline int fuse_iter_npages(struct fuse_conn *fc,
+  const struct iov_iter *ii_p)
 {
-   return iov_iter_npages(ii_p, FUSE_MAX_PAGES_PER_REQ);
+   return iov_iter_npages(ii_p, fc->max_pages);
 }
 
 ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
@@ -1350,9 +1352,10 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, struct 
iov_iter *iter,
struct fuse_req *req;
 
if (io->async)
-   req = fuse_get_req_for_background(fc, fuse_iter_npages(iter));
+   req = fuse_get_req_for_background(fc,
+ fuse_iter_npages(fc, iter));
else
-   req = fuse_

[PATCH v9] Documentation: add Device tree bindings for hwmon/nct7802

2015-11-23 Thread Constantine Shulyupin
From: Constantine Shulyupin 

Introduced subnodes sensor, fan and peci with properties.

Signed-off-by: Constantine Shulyupin 
---
Changed in v9:
- Fixed nuvoton,nct7802-sensor
- Introduced nuvoton,nct7802-vmon, nuvoton,nct7802-fan-in, 
nuvoton,nct7802-fan-ctl

Changed in v8:
- added senor type "local"
- Compatible nodes converted to senor types "vcore", "vcc"

Changed in v7:
- sensors type (thermistor, thermistor, voltage) and pwm type
selected with type property instead of compatible property.

Changed in v6:
- Removed previous definition.
- Introduced subnodes sensor, fan and peci with properties.

Changed in v5:
- Fixed typos

Changed in v4:
- Removed registers initialization by names
- Added properties nuvoton,sensor*-type

Changed in v3:
- Fixed vendor prefix
- Added short registers description,
  full registers description is available at
https://www.nuvoton.com/hq/products/cloud-computing/hardware-monitors/desktop-server-series/nct7802y/

Changed in v2:
- Removed nct7802,reg-init
- Added registers initialization by names

Introduced in v1:
 - nct7802,reg-init
---
 .../devicetree/bindings/hwmon/nct7802.txt  | 125 +
 1 file changed, 125 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/nct7802.txt

diff --git a/Documentation/devicetree/bindings/hwmon/nct7802.txt 
b/Documentation/devicetree/bindings/hwmon/nct7802.txt
new file mode 100644
index 000..cf983b3
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/nct7802.txt
@@ -0,0 +1,125 @@
+Nuvoton NCT7802Y Hardware Monitoring IC
+
+Required node properties:
+
+ - "compatible": must be "nuvoton,nct7802"
+ - "reg": I2C bus address of the device
+ - #address-cells=<1>;
+ - #size-cells=<0>;
+
+Optional subnodes:
+
+Sensor subnodes properties:
+ - "compatible", allowed values:
+- "nuvoton,nct7802-sensor"
+ - "sensor-type", allowed values:
+   "thermal-diode"
+   "thermistor"
+   "voltage"
+   "local" (only one instance, no "reg" required)
+For sensors of types "thermal-diode", "thermistor" and "voltage" required
+ - "reg": sensor index in range 0 .. 2
+
+Except sensor at address 2 can't be "thermal-diode".
+
+Voltage monitor subnodes properties:
+ - "compatible", allowed values:
+- "nuvoton,nct7802-vmon"
+ - "vmon-type", allowed values:
+   "vcore"
+   "vcc"
+ - "reg" is not used because there is only one instance of
+ vcore and vcc voltage monitors.
+
+Fan subnodes:
+
+Fan tachometer subnode (input):
+
+Required properties:
+ - "reg" :sensor index of in range 0 .. 2.
+ - "compatible", should be "nuvoton,nct7802-fan-in"
+
+Fan PWM (or DC) subnode (output or control):
+
+Required properties:
+ - "reg" :sensor index of in range 0 .. 2.
+ - "compatible", should be "nuvoton,nct7802-fan-ctl"
+Optional boolean properties:
+ - "direct-current" :direct current powered fan instead default PWM
+ - "invert" :inverted polarity
+ - "open-drain" :open-drain output instead push pull
+
+Subnode "peci" properties:
+ - "reg" :sensor index in range 0 .. 1
+ - "compatible", should be "nuvoton,nct7802-peci"
+
+Not defined sensors, fans and PECI modules will be disabled.
+
+Example nct7802 node:
+
+nct7802-example@28 {
+   compatible = "nuvoton,nct7802";
+   reg = <0x28>;
+   #address-cells=<1>;
+   #size-cells=<0>;
+   local-sensor {
+   compatible = "nuvoton,nct7802-sensor";
+   sensor-type = "local";
+   };
+   sensor@0 {
+   compatible = "nuvoton,nct7802-sensor";
+   reg = <0>;
+   sensor-type = "thermal-diode";
+   };
+   sensor@1 {
+   compatible = "nuvoton,nct7802-sensor";
+   reg = <1>;
+   sensor-type = "thermistor";
+   };
+   sensor@2 {
+   compatible = "nuvoton,nct7802-sensor";
+   reg = <2>;
+   sensor-type = "voltage";
+   };
+   vcc {
+   compatible = "nuvoton,nct7802-vmon";
+   sensor-type = "vcc";
+   };
+   vcore {
+   compatible = "nuvoton,nct7802-vmon";
+   sensor-type = "vcore";
+   };
+   fan-in@0 {
+   compatible = "nuvoton,nct7802-fan-in";
+   reg = <0>;
+   };
+   fan-in@1 {
+   compatible = "nuvoton,nct7802-fan-in";
+   reg = <1>;
+   };
+   fan-ctl@0

[PATCH v9] Documentation: add Device tree bindings for hwmon/nct7802

2015-11-23 Thread Constantine Shulyupin
From: Constantine Shulyupin <co...@makelinux.com>

Introduced subnodes sensor, fan and peci with properties.

Signed-off-by: Constantine Shulyupin <co...@makelinux.com>
---
Changed in v9:
- Fixed nuvoton,nct7802-sensor
- Introduced nuvoton,nct7802-vmon, nuvoton,nct7802-fan-in, 
nuvoton,nct7802-fan-ctl

Changed in v8:
- added senor type "local"
- Compatible nodes converted to senor types "vcore", "vcc"

Changed in v7:
- sensors type (thermistor, thermistor, voltage) and pwm type
selected with type property instead of compatible property.

Changed in v6:
- Removed previous definition.
- Introduced subnodes sensor, fan and peci with properties.

Changed in v5:
- Fixed typos

Changed in v4:
- Removed registers initialization by names
- Added properties nuvoton,sensor*-type

Changed in v3:
- Fixed vendor prefix
- Added short registers description,
  full registers description is available at
https://www.nuvoton.com/hq/products/cloud-computing/hardware-monitors/desktop-server-series/nct7802y/

Changed in v2:
- Removed nct7802,reg-init
- Added registers initialization by names

Introduced in v1:
 - nct7802,reg-init
---
 .../devicetree/bindings/hwmon/nct7802.txt  | 125 +
 1 file changed, 125 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/nct7802.txt

diff --git a/Documentation/devicetree/bindings/hwmon/nct7802.txt 
b/Documentation/devicetree/bindings/hwmon/nct7802.txt
new file mode 100644
index 000..cf983b3
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/nct7802.txt
@@ -0,0 +1,125 @@
+Nuvoton NCT7802Y Hardware Monitoring IC
+
+Required node properties:
+
+ - "compatible": must be "nuvoton,nct7802"
+ - "reg": I2C bus address of the device
+ - #address-cells=<1>;
+ - #size-cells=<0>;
+
+Optional subnodes:
+
+Sensor subnodes properties:
+ - "compatible", allowed values:
+- "nuvoton,nct7802-sensor"
+ - "sensor-type", allowed values:
+   "thermal-diode"
+   "thermistor"
+   "voltage"
+   "local" (only one instance, no "reg" required)
+For sensors of types "thermal-diode", "thermistor" and "voltage" required
+ - "reg": sensor index in range 0 .. 2
+
+Except sensor at address 2 can't be "thermal-diode".
+
+Voltage monitor subnodes properties:
+ - "compatible", allowed values:
+- "nuvoton,nct7802-vmon"
+ - "vmon-type", allowed values:
+   "vcore"
+   "vcc"
+ - "reg" is not used because there is only one instance of
+ vcore and vcc voltage monitors.
+
+Fan subnodes:
+
+Fan tachometer subnode (input):
+
+Required properties:
+ - "reg" :sensor index of in range 0 .. 2.
+ - "compatible", should be "nuvoton,nct7802-fan-in"
+
+Fan PWM (or DC) subnode (output or control):
+
+Required properties:
+ - "reg" :sensor index of in range 0 .. 2.
+ - "compatible", should be "nuvoton,nct7802-fan-ctl"
+Optional boolean properties:
+ - "direct-current" :direct current powered fan instead default PWM
+ - "invert" :inverted polarity
+ - "open-drain" :open-drain output instead push pull
+
+Subnode "peci" properties:
+ - "reg" :sensor index in range 0 .. 1
+ - "compatible", should be "nuvoton,nct7802-peci"
+
+Not defined sensors, fans and PECI modules will be disabled.
+
+Example nct7802 node:
+
+nct7802-example@28 {
+   compatible = "nuvoton,nct7802";
+   reg = <0x28>;
+   #address-cells=<1>;
+   #size-cells=<0>;
+   local-sensor {
+   compatible = "nuvoton,nct7802-sensor";
+   sensor-type = "local";
+   };
+   sensor@0 {
+   compatible = "nuvoton,nct7802-sensor";
+   reg = <0>;
+   sensor-type = "thermal-diode";
+   };
+   sensor@1 {
+   compatible = "nuvoton,nct7802-sensor";
+   reg = <1>;
+   sensor-type = "thermistor";
+   };
+   sensor@2 {
+   compatible = "nuvoton,nct7802-sensor";
+   reg = <2>;
+   sensor-type = "voltage";
+   };
+   vcc {
+   compatible = "nuvoton,nct7802-vmon";
+   sensor-type = "vcc";
+   };
+   vcore {
+   compatible = "nuvoton,nct7802-vmon";
+   sensor-type = "vcore";
+   };
+   fan-in@0 {
+   compatible = "nuvoton,nct7802-fan-in";
+   reg = <0>;
+   };
+   fan-in@1 {
+   compatible = "nuvoton,nct7802-fan-in";
+   reg =

Re: [PATCH v8] Documentation: add Device tree bindings for hwmon/nct7802

2015-11-14 Thread Constantine Shulyupin
On Thu, Nov 12, 2015 at 7:26 PM, Rob Herring  wrote:
> On Mon, Oct 26, 2015 at 10:24:17PM +0200, Constantine Shulyupin wrote:
>> From: Constantine Shulyupin 
>> +Optional subnodes:
>> +
>> +Sensor subnodes properties:
>> + - "compatible", allowed values:
>> +  - "nuvoton,nct7802"
>
> This should have -sensor appended?

Right.

>> + - "sensor-type", allowed values:
>> + "thermal-diode"
>> + "thermistor"
>> + "voltage"
>> + "local"
>> + "vcore"
>> + "vcc"
>
> These are different connections to the same h/w block in the chip? If
> so, then this is fine. If the h/w blocks are different, then it would be
> better to go back to different compatible strings.

"thermal-diode", "thermistor", "voltage",  "local" - is one H/W block
(7.2.32 Mode Selection Register, 22h)
One of above "local" - is single input, enables by one bit EnLTD

 "vcore", "vcc" - another H/W block (7.2.35 Voltage Monitor Enable
Register, 25h), each of them is different input.

I'll divide them in the next patch.

>
>> +For sensors of types "thermal-diode", "thermistor" and "voltage" required
>> + - "reg": index in range 0 .. 2
>> +
>> +Except sensor at address 2 can't be "thermal-diode".
>> +
>> +Fan subnode:
>> +
>> +Required properties:
>> + - "reg" :index of in range 0 .. 2.
>
> What does the numbering correspond to in the h/w?
The numberring corresponds to the three different temperature/voltage
inputs (RTD1_MD, RTD2_MD, RTD3_MD) and three different fans (EnFan1,
EnFan2, EnFan3, EnDCFAN*, etc)

>> + vcc {
>> + compatible = "nuvoton,nct7802-sensor";
>> + sensor-type = "vcc";
>
> No unit address?
>
>> + };
>> + vcore {
>> + compatible = "nuvoton,nct7802-sensor";
>> + sensor-type = "vcore";
>> + };

There is only one vcc anv vcore input.


-- 
Thanks
Constantine
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v8] Documentation: add Device tree bindings for hwmon/nct7802

2015-11-14 Thread Constantine Shulyupin
On Thu, Nov 12, 2015 at 7:26 PM, Rob Herring <r...@kernel.org> wrote:
> On Mon, Oct 26, 2015 at 10:24:17PM +0200, Constantine Shulyupin wrote:
>> From: Constantine Shulyupin <co...@makelinux.com>
>> +Optional subnodes:
>> +
>> +Sensor subnodes properties:
>> + - "compatible", allowed values:
>> +  - "nuvoton,nct7802"
>
> This should have -sensor appended?

Right.

>> + - "sensor-type", allowed values:
>> + "thermal-diode"
>> + "thermistor"
>> + "voltage"
>> + "local"
>> + "vcore"
>> + "vcc"
>
> These are different connections to the same h/w block in the chip? If
> so, then this is fine. If the h/w blocks are different, then it would be
> better to go back to different compatible strings.

"thermal-diode", "thermistor", "voltage",  "local" - is one H/W block
(7.2.32 Mode Selection Register, 22h)
One of above "local" - is single input, enables by one bit EnLTD

 "vcore", "vcc" - another H/W block (7.2.35 Voltage Monitor Enable
Register, 25h), each of them is different input.

I'll divide them in the next patch.

>
>> +For sensors of types "thermal-diode", "thermistor" and "voltage" required
>> + - "reg": index in range 0 .. 2
>> +
>> +Except sensor at address 2 can't be "thermal-diode".
>> +
>> +Fan subnode:
>> +
>> +Required properties:
>> + - "reg" :index of in range 0 .. 2.
>
> What does the numbering correspond to in the h/w?
The numberring corresponds to the three different temperature/voltage
inputs (RTD1_MD, RTD2_MD, RTD3_MD) and three different fans (EnFan1,
EnFan2, EnFan3, EnDCFAN*, etc)

>> + vcc {
>> + compatible = "nuvoton,nct7802-sensor";
>> + sensor-type = "vcc";
>
> No unit address?
>
>> + };
>> + vcore {
>> + compatible = "nuvoton,nct7802-sensor";
>> + sensor-type = "vcore";
>> + };

There is only one vcc anv vcore input.


-- 
Thanks
Constantine
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3] hwmon: (nct7802) Add device tree support

2015-10-26 Thread Constantine Shulyupin
From: Constantine Shulyupin 

Introduced nct7802_platform_data, nct7802_parse_dt,
nct7802_platform_data_set.

Parsing of DT nodes
 - compatible = "nuvoton,nct7802-sensor",
with "sensor-type" = "thermal-diode" | "thermistor" | "voltage" |
"local" | "vcc" | "vcore"
 - compatible = "nuvoton,nct7802-fan",
with boolen properties "direct-current", "invert", "invert"
 - compatible = "nuvoton,nct7802-peci"

Signed-off-by: Constantine Shulyupin 
---
Changed in v3:
- Removed nuvoton,sensorX-type
- Introduced nct7802_platform_data, new DT parser for sensors, fans, peci,
  vcc, vcore

Changed in v2:
- removed tempX_type
- introduced nuvoton,sensorX-type with string values

Changed in v1:
- Introduced tempX_type with numerical values
---
 drivers/hwmon/nct7802.c | 186 +++-
 1 file changed, 185 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index 3ce33d2..dee9eb3 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -53,6 +53,8 @@ static const u8 REG_VOLTAGE_LIMIT_MSB_SHIFT[2][5] = {
 #define REG_PECI_ENABLE0x23
 #define REG_FAN_ENABLE 0x24
 #define REG_VMON_ENABLE0x25
+#define REG_FAN_TYPE   0x5e
+#define REG_FAN_MODE   0x5f
 #define REG_PWM(x) (0x60 + (x))
 #define REG_SMARTFAN_EN(x)  (0x64 + (x) / 2)
 #define SMARTFAN_EN_SHIFT(x)((x) % 2 * 4)
@@ -69,6 +71,18 @@ struct nct7802_data {
struct mutex access_lock; /* for multi-byte read and write operations */
 };
 
+struct nct7802_platform_data {
+   s8 sensor_type[3];
+   s8 local_temp_enable;
+   s8 vcc_enable;
+   s8 vcore_enable;
+   s8 fan_enable[3];
+   s8 fan_dc[2];   /* direct current instead PWM */
+   s8 fan_od[3];   /* open drain */
+   s8 fan_inv[3];  /* inverted polarity */
+   s8 peci_enable[2];
+};
+
 static ssize_t show_temp_type(struct device *dev, struct device_attribute 
*attr,
  char *buf)
 {
@@ -1077,6 +1091,151 @@ static const struct regmap_config nct7802_regmap_config 
= {
.volatile_reg = nct7802_regmap_is_volatile,
 };
 
+static int nct7802_parse_dt(struct device_node *node,
+   struct nct7802_platform_data *pdata)
+{
+   struct device_node *child;
+   const char *sen_type;
+   int ret;
+   int i;
+
+   for_each_child_of_node(node, child) {
+   u32 reg = 0xFF;
+
+   of_property_read_u32(child, "reg", );
+   if (of_device_is_compatible(child, "nuvoton,nct7802-sensor")) {
+   ret = of_property_read_string(child,
+ "sensor-type", _type);
+   if (ret < 0) {
+   pr_err("%s: expected property sensor-type\n",
+  child->full_name);
+   return -EINVAL;
+   }
+   if (!strcmp(sen_type, "local")) {
+   pdata->local_temp_enable = 1;
+   continue;
+   } else if (!strcmp(sen_type, "vcc")) {
+   pdata->vcc_enable = 1;
+   continue;
+   } else if (!strcmp(sen_type, "vcore")) {
+   pdata->vcore_enable = 1;
+   continue;
+   }
+   if (reg >= ARRAY_SIZE(pdata->sensor_type)) {
+   pr_err("%s: invalid value: reg=%d\n",
+  child->full_name, reg);
+   return -EINVAL;
+   }
+   if (!strcmp(sen_type, "thermal-diode")) {
+   pdata->sensor_type[reg] = 1;
+   } else if (!strcmp(sen_type, "thermistor")) {
+   pdata->sensor_type[reg] = 2;
+   } else if (!strcmp(sen_type, "voltage")) {
+   pdata->sensor_type[reg] = 3;
+   } else {
+   pr_err("%s: invalid sensor-type=\"%s\"\n",
+  child->full_name, sen_type);
+   return -EINVAL;
+   }
+   } else if (of_device_is_compatible(child,
+  "nuvoton,nct7802-fan")) {
+   if (reg >= ARRAY_SIZE(pdata->fan_enable)) {
+   

[PATCH v8] Documentation: add Device tree bindings for hwmon/nct7802

2015-10-26 Thread Constantine Shulyupin
From: Constantine Shulyupin 

Introduced subnodes sensor, fan and peci with properties.

Signed-off-by: Constantine Shulyupin 
---
Changed in v8:
- added senor type "local"
- Compatible nodes converted to senor types "vcore", "vcc"

Changed in v7:
- sensors type (thermistor, thermistor, voltage) and pwm type
selected with type property instead of compatible property.

Changed in v6:
- Removed previous definition.
- Introduced subnodes sensor, fan and peci with properties.

Changed in v5:
- Fixed typos

Changed in v4:
- Removed registers initialization by names
- Added properties nuvoton,sensor*-type

Changed in v3:
- Fixed vendor prefix
- Added short registers description,
  full registers description is available at
https://www.nuvoton.com/hq/products/cloud-computing/hardware-monitors/desktop-server-series/nct7802y/

Changed in v2:
- Removed nct7802,reg-init
- Added registers initialization by names

Introduced in v1:
 - nct7802,reg-init
---
 .../devicetree/bindings/hwmon/nct7802.txt  | 102 +
 1 file changed, 102 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/nct7802.txt

diff --git a/Documentation/devicetree/bindings/hwmon/nct7802.txt 
b/Documentation/devicetree/bindings/hwmon/nct7802.txt
new file mode 100644
index 000..8647783
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/nct7802.txt
@@ -0,0 +1,102 @@
+Nuvoton NCT7802Y Hardware Monitoring IC
+
+Required node properties:
+
+ - "compatible": must be "nuvoton,nct7802"
+ - "reg": I2C bus address of the device
+ - #address-cells=<1>;
+ - #size-cells=<0>;
+
+Optional subnodes:
+
+Sensor subnodes properties:
+ - "compatible", allowed values:
+- "nuvoton,nct7802"
+ - "sensor-type", allowed values:
+   "thermal-diode"
+   "thermistor"
+   "voltage"
+   "local"
+   "vcore"
+   "vcc"
+For sensors of types "thermal-diode", "thermistor" and "voltage" required
+ - "reg": index in range 0 .. 2
+
+Except sensor at address 2 can't be "thermal-diode".
+
+Fan subnode:
+
+Required properties:
+ - "reg" :index of in range 0 .. 2.
+ - "compatible", should be "nuvoton,nct7802-fan"
+Optional boolean properties:
+ - "direct-current" :direct current powered fan instead default PWM
+ - "invert" :inverted polarity
+ - "open-drain" :open-drain output instead push pull
+
+Subnode "peci" properties:
+ - "reg" :index in range 0 .. 1
+ - "compatible", should be "nuvoton,nct7802-peci"
+
+Not defined sensors, fans and PECI modules will be disabled.
+
+Example nct7802 node:
+
+nct7802-example@28 {
+   compatible = "nuvoton,nct7802";
+   reg = <0x28>;
+   #address-cells=<1>;
+   #size-cells=<0>;
+   local-sensor {
+   compatible = "nuvoton,nct7802-sensor";
+   sensor-type = "local";
+   };
+   sensor@0 {
+   compatible = "nuvoton,nct7802-sensor";
+   reg = <0>;
+   sensor-type = "thermal-diode";
+   };
+   sensor@1 {
+   compatible = "nuvoton,nct7802-sensor";
+   reg = <1>;
+   sensor-type = "thermistor";
+   };
+   sensor@2 {
+   compatible = "nuvoton,nct7802-sensor";
+   reg = <2>;
+   sensor-type = "voltage";
+   };
+   vcc {
+   compatible = "nuvoton,nct7802-sensor";
+   sensor-type = "vcc";
+   };
+   vcore {
+   compatible = "nuvoton,nct7802-sensor";
+   sensor-type = "vcore";
+   };
+   pwm-fan@0 {
+   compatible = "nuvoton,nct7802-fan";
+   reg = <0>;
+   };
+   dc-fan@1 {
+   compatible = "nuvoton,nct7802-fan";
+   reg = <1>;
+   direct-current;
+   open-drain;
+   invert;
+   };
+   fan@2 {
+   compatible = "nuvoton,nct7802-fan";
+   reg = <2>;
+   open-drain;
+   invert;
+   };
+   peci@0 {
+   compatible = "nuvoton,nct7802-peci";
+   reg = <0>;
+   };
+   peci@1 {
+   compatible = "nuvoton,nct7802-peci";
+   reg = <1>;
+   };
+};
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v8] Documentation: add Device tree bindings for hwmon/nct7802

2015-10-26 Thread Constantine Shulyupin
From: Constantine Shulyupin <co...@makelinux.com>

Introduced subnodes sensor, fan and peci with properties.

Signed-off-by: Constantine Shulyupin <co...@makelinux.com>
---
Changed in v8:
- added senor type "local"
- Compatible nodes converted to senor types "vcore", "vcc"

Changed in v7:
- sensors type (thermistor, thermistor, voltage) and pwm type
selected with type property instead of compatible property.

Changed in v6:
- Removed previous definition.
- Introduced subnodes sensor, fan and peci with properties.

Changed in v5:
- Fixed typos

Changed in v4:
- Removed registers initialization by names
- Added properties nuvoton,sensor*-type

Changed in v3:
- Fixed vendor prefix
- Added short registers description,
  full registers description is available at
https://www.nuvoton.com/hq/products/cloud-computing/hardware-monitors/desktop-server-series/nct7802y/

Changed in v2:
- Removed nct7802,reg-init
- Added registers initialization by names

Introduced in v1:
 - nct7802,reg-init
---
 .../devicetree/bindings/hwmon/nct7802.txt  | 102 +
 1 file changed, 102 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/nct7802.txt

diff --git a/Documentation/devicetree/bindings/hwmon/nct7802.txt 
b/Documentation/devicetree/bindings/hwmon/nct7802.txt
new file mode 100644
index 000..8647783
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/nct7802.txt
@@ -0,0 +1,102 @@
+Nuvoton NCT7802Y Hardware Monitoring IC
+
+Required node properties:
+
+ - "compatible": must be "nuvoton,nct7802"
+ - "reg": I2C bus address of the device
+ - #address-cells=<1>;
+ - #size-cells=<0>;
+
+Optional subnodes:
+
+Sensor subnodes properties:
+ - "compatible", allowed values:
+- "nuvoton,nct7802"
+ - "sensor-type", allowed values:
+   "thermal-diode"
+   "thermistor"
+   "voltage"
+   "local"
+   "vcore"
+   "vcc"
+For sensors of types "thermal-diode", "thermistor" and "voltage" required
+ - "reg": index in range 0 .. 2
+
+Except sensor at address 2 can't be "thermal-diode".
+
+Fan subnode:
+
+Required properties:
+ - "reg" :index of in range 0 .. 2.
+ - "compatible", should be "nuvoton,nct7802-fan"
+Optional boolean properties:
+ - "direct-current" :direct current powered fan instead default PWM
+ - "invert" :inverted polarity
+ - "open-drain" :open-drain output instead push pull
+
+Subnode "peci" properties:
+ - "reg" :index in range 0 .. 1
+ - "compatible", should be "nuvoton,nct7802-peci"
+
+Not defined sensors, fans and PECI modules will be disabled.
+
+Example nct7802 node:
+
+nct7802-example@28 {
+   compatible = "nuvoton,nct7802";
+   reg = <0x28>;
+   #address-cells=<1>;
+   #size-cells=<0>;
+   local-sensor {
+   compatible = "nuvoton,nct7802-sensor";
+   sensor-type = "local";
+   };
+   sensor@0 {
+   compatible = "nuvoton,nct7802-sensor";
+   reg = <0>;
+   sensor-type = "thermal-diode";
+   };
+   sensor@1 {
+   compatible = "nuvoton,nct7802-sensor";
+   reg = <1>;
+   sensor-type = "thermistor";
+   };
+   sensor@2 {
+   compatible = "nuvoton,nct7802-sensor";
+   reg = <2>;
+   sensor-type = "voltage";
+   };
+   vcc {
+   compatible = "nuvoton,nct7802-sensor";
+   sensor-type = "vcc";
+   };
+   vcore {
+   compatible = "nuvoton,nct7802-sensor";
+   sensor-type = "vcore";
+   };
+   pwm-fan@0 {
+   compatible = "nuvoton,nct7802-fan";
+   reg = <0>;
+   };
+   dc-fan@1 {
+   compatible = "nuvoton,nct7802-fan";
+   reg = <1>;
+   direct-current;
+   open-drain;
+   invert;
+   };
+   fan@2 {
+   compatible = "nuvoton,nct7802-fan";
+   reg = <2>;
+   open-drain;
+   invert;
+   };
+   peci@0 {
+   compatible = "nuvoton,nct7802-peci";
+   reg = <0>;
+   };
+   peci@1 {
+   compatible = "nuvoton,nct7802-peci";
+   reg = <1>;
+   };
+};
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3] hwmon: (nct7802) Add device tree support

2015-10-26 Thread Constantine Shulyupin
From: Constantine Shulyupin <co...@makelinux.com>

Introduced nct7802_platform_data, nct7802_parse_dt,
nct7802_platform_data_set.

Parsing of DT nodes
 - compatible = "nuvoton,nct7802-sensor",
with "sensor-type" = "thermal-diode" | "thermistor" | "voltage" |
"local" | "vcc" | "vcore"
 - compatible = "nuvoton,nct7802-fan",
with boolen properties "direct-current", "invert", "invert"
 - compatible = "nuvoton,nct7802-peci"

Signed-off-by: Constantine Shulyupin <co...@makelinux.com>
---
Changed in v3:
- Removed nuvoton,sensorX-type
- Introduced nct7802_platform_data, new DT parser for sensors, fans, peci,
  vcc, vcore

Changed in v2:
- removed tempX_type
- introduced nuvoton,sensorX-type with string values

Changed in v1:
- Introduced tempX_type with numerical values
---
 drivers/hwmon/nct7802.c | 186 +++-
 1 file changed, 185 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index 3ce33d2..dee9eb3 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -53,6 +53,8 @@ static const u8 REG_VOLTAGE_LIMIT_MSB_SHIFT[2][5] = {
 #define REG_PECI_ENABLE0x23
 #define REG_FAN_ENABLE 0x24
 #define REG_VMON_ENABLE0x25
+#define REG_FAN_TYPE   0x5e
+#define REG_FAN_MODE   0x5f
 #define REG_PWM(x) (0x60 + (x))
 #define REG_SMARTFAN_EN(x)  (0x64 + (x) / 2)
 #define SMARTFAN_EN_SHIFT(x)((x) % 2 * 4)
@@ -69,6 +71,18 @@ struct nct7802_data {
struct mutex access_lock; /* for multi-byte read and write operations */
 };
 
+struct nct7802_platform_data {
+   s8 sensor_type[3];
+   s8 local_temp_enable;
+   s8 vcc_enable;
+   s8 vcore_enable;
+   s8 fan_enable[3];
+   s8 fan_dc[2];   /* direct current instead PWM */
+   s8 fan_od[3];   /* open drain */
+   s8 fan_inv[3];  /* inverted polarity */
+   s8 peci_enable[2];
+};
+
 static ssize_t show_temp_type(struct device *dev, struct device_attribute 
*attr,
  char *buf)
 {
@@ -1077,6 +1091,151 @@ static const struct regmap_config nct7802_regmap_config 
= {
.volatile_reg = nct7802_regmap_is_volatile,
 };
 
+static int nct7802_parse_dt(struct device_node *node,
+   struct nct7802_platform_data *pdata)
+{
+   struct device_node *child;
+   const char *sen_type;
+   int ret;
+   int i;
+
+   for_each_child_of_node(node, child) {
+   u32 reg = 0xFF;
+
+   of_property_read_u32(child, "reg", );
+   if (of_device_is_compatible(child, "nuvoton,nct7802-sensor")) {
+   ret = of_property_read_string(child,
+ "sensor-type", _type);
+   if (ret < 0) {
+   pr_err("%s: expected property sensor-type\n",
+  child->full_name);
+   return -EINVAL;
+   }
+   if (!strcmp(sen_type, "local")) {
+   pdata->local_temp_enable = 1;
+   continue;
+   } else if (!strcmp(sen_type, "vcc")) {
+   pdata->vcc_enable = 1;
+   continue;
+   } else if (!strcmp(sen_type, "vcore")) {
+   pdata->vcore_enable = 1;
+   continue;
+   }
+   if (reg >= ARRAY_SIZE(pdata->sensor_type)) {
+   pr_err("%s: invalid value: reg=%d\n",
+  child->full_name, reg);
+   return -EINVAL;
+   }
+   if (!strcmp(sen_type, "thermal-diode")) {
+   pdata->sensor_type[reg] = 1;
+   } else if (!strcmp(sen_type, "thermistor")) {
+   pdata->sensor_type[reg] = 2;
+   } else if (!strcmp(sen_type, "voltage")) {
+   pdata->sensor_type[reg] = 3;
+   } else {
+   pr_err("%s: invalid sensor-type=\"%s\"\n",
+  child->full_name, sen_type);
+   return -EINVAL;
+   }
+   } else if (of_device_is_compatible(child,
+  "nuvoton,nct7802-fan")) {
+

[PATCH v7] Documentation: add Device tree bindings for hwmon/nct7802

2015-10-23 Thread Constantine Shulyupin
Introduced subnodes sensor, fan and peci with properties.

Signed-off-by: Constantine Shulyupin 
---
Changed in v7:
- sensors type (thermistor, thermistor, voltage) and pwm type
selected with type property instead of compatible property.

Changed in v6:
- Removed previous definition.
- Introduced subnodes sensor, fan and peci with properties.

Changed in v5:
- Fixed typos

Changed in v4:
- Removed registers initialization by names
- Added properties nuvoton,sensor*-type

Changed in v3:
- Fixed vendor prefix
- Added short registers description,
  full registers description is available at
https://www.nuvoton.com/hq/products/cloud-computing/hardware-monitors/desktop-server-series/nct7802y/

Changed in v2:
- Removed nct7802,reg-init
- Added registers initialization by names

Introduced in v1:
 - nct7802,reg-init
---
 .../devicetree/bindings/hwmon/nct7802.txt  | 77 ++
 1 file changed, 77 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/nct7802.txt

diff --git a/Documentation/devicetree/bindings/hwmon/nct7802.txt 
b/Documentation/devicetree/bindings/hwmon/nct7802.txt
new file mode 100644
index 000..1619202
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/nct7802.txt
@@ -0,0 +1,77 @@
+Nuvoton NCT7802Y Hardware Monitoring IC
+
+Required node properties:
+
+ - "compatible": must be "nuvoton,nct7802"
+ - "reg": I2C bus address of the device
+ - #address-cells=<1>;
+ - #size-cells=<0>;
+
+Optional subnodes:
+
+Sensor subnodes properties:
+ - "reg": index in range 0..2
+ - "compatible", allowed values:
+- "nuvoton,nct7802"
+ - "sensor-type", allowed values:
+   "thermal-diode"
+   "thermistor"
+   "voltage"
+
+Except sensor at address 2 can't be "thermal-diode".
+
+Fan subnode:
+
+Required properties:
+ - "reg" :index of in range 0 .. 2.
+ - "compatible", should be "nuvoton,nct7802-fan"
+Optional boolean properties:
+ - "direct-current" :direct current powered fan instead default PWM
+ - "invert" :inverted polarity
+ - "open-drain" :open-drain output instead push pull
+
+Subnode "peci" properties:
+ - "reg" :index in range 0..1
+ - "compatible", should be "nuvoton,nct7802-peci"
+
+Subnode vcc properties:
+ - "compatible", should be "nuvoton,nct7802-vcc"
+
+Subnode vcore properties:
+ - "compatible", should be "nuvoton,nct7802-vcore"
+
+Not defined sensors, fans and PECI modules will be disabled.
+
+Example nct7802 node:
+
+nct7802 {
+   compatible = "nuvoton,nct7802";
+   reg = <0x2a>;
+   #address-cells=<1>;
+   #size-cells=<0>;
+   sensor@0 {
+   reg = <0>;
+   compatible = "nuvoton,nct7802";
+   sensor-type = "thermistor"
+   };
+   sensor@1 {
+   reg = <1>;
+   compatible = "nuvoton,nct7802";
+   sensor-type = "thermal-diode";
+   };
+   pwm-fan@0 {
+   reg = <0>;
+   compatible = "nuvoton,nct7802-fan";
+   };
+   dc-fan@1 {
+   reg = <1>;
+   compatible = "nuvoton,nct7802-fan";
+   dc;
+   invert;
+   open-drain;
+   };
+   peci@0 {
+   reg = <0>;
+   compatible = "nuvoton,nct7802-peci";
+   };
+};
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v7] Documentation: add Device tree bindings for hwmon/nct7802

2015-10-23 Thread Constantine Shulyupin
Introduced subnodes sensor, fan and peci with properties.

Signed-off-by: Constantine Shulyupin <co...@makelinux.com>
---
Changed in v7:
- sensors type (thermistor, thermistor, voltage) and pwm type
selected with type property instead of compatible property.

Changed in v6:
- Removed previous definition.
- Introduced subnodes sensor, fan and peci with properties.

Changed in v5:
- Fixed typos

Changed in v4:
- Removed registers initialization by names
- Added properties nuvoton,sensor*-type

Changed in v3:
- Fixed vendor prefix
- Added short registers description,
  full registers description is available at
https://www.nuvoton.com/hq/products/cloud-computing/hardware-monitors/desktop-server-series/nct7802y/

Changed in v2:
- Removed nct7802,reg-init
- Added registers initialization by names

Introduced in v1:
 - nct7802,reg-init
---
 .../devicetree/bindings/hwmon/nct7802.txt  | 77 ++
 1 file changed, 77 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/nct7802.txt

diff --git a/Documentation/devicetree/bindings/hwmon/nct7802.txt 
b/Documentation/devicetree/bindings/hwmon/nct7802.txt
new file mode 100644
index 000..1619202
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/nct7802.txt
@@ -0,0 +1,77 @@
+Nuvoton NCT7802Y Hardware Monitoring IC
+
+Required node properties:
+
+ - "compatible": must be "nuvoton,nct7802"
+ - "reg": I2C bus address of the device
+ - #address-cells=<1>;
+ - #size-cells=<0>;
+
+Optional subnodes:
+
+Sensor subnodes properties:
+ - "reg": index in range 0..2
+ - "compatible", allowed values:
+- "nuvoton,nct7802"
+ - "sensor-type", allowed values:
+   "thermal-diode"
+   "thermistor"
+   "voltage"
+
+Except sensor at address 2 can't be "thermal-diode".
+
+Fan subnode:
+
+Required properties:
+ - "reg" :index of in range 0 .. 2.
+ - "compatible", should be "nuvoton,nct7802-fan"
+Optional boolean properties:
+ - "direct-current" :direct current powered fan instead default PWM
+ - "invert" :inverted polarity
+ - "open-drain" :open-drain output instead push pull
+
+Subnode "peci" properties:
+ - "reg" :index in range 0..1
+ - "compatible", should be "nuvoton,nct7802-peci"
+
+Subnode vcc properties:
+ - "compatible", should be "nuvoton,nct7802-vcc"
+
+Subnode vcore properties:
+ - "compatible", should be "nuvoton,nct7802-vcore"
+
+Not defined sensors, fans and PECI modules will be disabled.
+
+Example nct7802 node:
+
+nct7802 {
+   compatible = "nuvoton,nct7802";
+   reg = <0x2a>;
+   #address-cells=<1>;
+   #size-cells=<0>;
+   sensor@0 {
+   reg = <0>;
+   compatible = "nuvoton,nct7802";
+   sensor-type = "thermistor"
+   };
+   sensor@1 {
+   reg = <1>;
+   compatible = "nuvoton,nct7802";
+   sensor-type = "thermal-diode";
+   };
+   pwm-fan@0 {
+   reg = <0>;
+   compatible = "nuvoton,nct7802-fan";
+   };
+   dc-fan@1 {
+   reg = <1>;
+   compatible = "nuvoton,nct7802-fan";
+   dc;
+   invert;
+   open-drain;
+   };
+   peci@0 {
+   reg = <0>;
+   compatible = "nuvoton,nct7802-peci";
+   };
+};
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v6] Documentation: add Device tree bindings for hwmon/nct7802

2015-10-02 Thread Constantine Shulyupin
Introduced subnodes sensor, fan and peci with properties.

Signed-off-by: Constantine Shulyupin 
---
Changed in v6:
- Removed previous definition.
- Introduced subnodes sensor, fan and peci with properties.

Changed in v5:
- Fixed typos

Changed in v4:
- Removed registers initialization by names
- Added properties nuvoton,sensor*-type

Changed in v3:
- Fixed vendor prefix
- Added short registers description,
  full registers description is available at
https://www.nuvoton.com/hq/products/cloud-computing/hardware-monitors/desktop-server-series/nct7802y/

Changed in v2:
- Removed nct7802,reg-init
- Added registers initialization by names

Introduced in v1:
 - nct7802,reg-init
---
 .../devicetree/bindings/hwmon/nct7802.txt  | 66 ++
 1 file changed, 66 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/nct7802.txt

diff --git a/Documentation/devicetree/bindings/hwmon/nct7802.txt 
b/Documentation/devicetree/bindings/hwmon/nct7802.txt
new file mode 100644
index 000..88ee599
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/nct7802.txt
@@ -0,0 +1,66 @@
+Nuvoton NCT7802Y Hardware Monitoring IC
+
+Required node properties:
+
+ - "compatible": must be "nuvoton,nct7802"
+ - "reg": I2C bus address of the device
+ - #address-cells=<1>;
+ - #size-cells=<0>;
+
+Optional subnodes:
+
+Subnode "sensor" properties:
+ - "reg": index in range 0..3
+ - "compatible", allowed values:
+- "nuvoton,nct7802-thermal-diode"
+- "nuvoton,nct7802-thermistor"
+- "nuvoton,nct7802-voltage"
+
+Sensor at address 2 can't be "nuvoton,nct7802-thermal-diode".
+
+Subnode "fan":
+Required properties:
+ - "reg" :index of in range 0 .. 2.
+ - "compatible", allowed values:
+   "nuvoton,nct7802-fan-pwm" :PWM powered fan
+   "nuvoton,nct7802-fan-dc" :direct current powered fan
+Optional boolean properties:
+ - "invert"  :inverted polarity
+ - "open-drain" :open-drain output instead push pull
+
+Subnode "peci" properties:
+ - "reg" :index in range 0..1
+ - "compatible", should be "nuvoton,nct7802-peci"
+
+Not defined sensors, fans and PECI modules will be disabled.
+
+Example nct7802 node:
+
+nct7802 {
+   compatible = "nuvoton,nct7802";
+   reg = <0x2a>;
+   #address-cells=<1>;
+   #size-cells=<0>;
+   sensor@0 {
+   reg = <0>;
+   compatible = "nuvoton,nct7802-thermistor";
+   };
+   sensor@2 {
+   reg = <2>;
+   compatible = "nuvoton,nct7802-thermal-diode";
+   };
+   fan@0 {
+   reg = <0>;
+   compatible = "nuvoton,nct7802-fan-pwm";
+   };
+   fan@1 {
+   reg = <1>;
+   compatible = "nuvoton,nct7802-fan-dc";
+   invert;
+   open-drain;
+   };
+   peci@0 {
+   reg = <0>;
+   compatible = "nuvoton,nct7802-peci";
+   };
+};
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v6] Documentation: add Device tree bindings for hwmon/nct7802

2015-10-02 Thread Constantine Shulyupin
Introduced subnodes sensor, fan and peci with properties.

Signed-off-by: Constantine Shulyupin <co...@makelinux.com>
---
Changed in v6:
- Removed previous definition.
- Introduced subnodes sensor, fan and peci with properties.

Changed in v5:
- Fixed typos

Changed in v4:
- Removed registers initialization by names
- Added properties nuvoton,sensor*-type

Changed in v3:
- Fixed vendor prefix
- Added short registers description,
  full registers description is available at
https://www.nuvoton.com/hq/products/cloud-computing/hardware-monitors/desktop-server-series/nct7802y/

Changed in v2:
- Removed nct7802,reg-init
- Added registers initialization by names

Introduced in v1:
 - nct7802,reg-init
---
 .../devicetree/bindings/hwmon/nct7802.txt  | 66 ++
 1 file changed, 66 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/nct7802.txt

diff --git a/Documentation/devicetree/bindings/hwmon/nct7802.txt 
b/Documentation/devicetree/bindings/hwmon/nct7802.txt
new file mode 100644
index 000..88ee599
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/nct7802.txt
@@ -0,0 +1,66 @@
+Nuvoton NCT7802Y Hardware Monitoring IC
+
+Required node properties:
+
+ - "compatible": must be "nuvoton,nct7802"
+ - "reg": I2C bus address of the device
+ - #address-cells=<1>;
+ - #size-cells=<0>;
+
+Optional subnodes:
+
+Subnode "sensor" properties:
+ - "reg": index in range 0..3
+ - "compatible", allowed values:
+- "nuvoton,nct7802-thermal-diode"
+- "nuvoton,nct7802-thermistor"
+- "nuvoton,nct7802-voltage"
+
+Sensor at address 2 can't be "nuvoton,nct7802-thermal-diode".
+
+Subnode "fan":
+Required properties:
+ - "reg" :index of in range 0 .. 2.
+ - "compatible", allowed values:
+   "nuvoton,nct7802-fan-pwm" :PWM powered fan
+   "nuvoton,nct7802-fan-dc" :direct current powered fan
+Optional boolean properties:
+ - "invert"  :inverted polarity
+ - "open-drain" :open-drain output instead push pull
+
+Subnode "peci" properties:
+ - "reg" :index in range 0..1
+ - "compatible", should be "nuvoton,nct7802-peci"
+
+Not defined sensors, fans and PECI modules will be disabled.
+
+Example nct7802 node:
+
+nct7802 {
+   compatible = "nuvoton,nct7802";
+   reg = <0x2a>;
+   #address-cells=<1>;
+   #size-cells=<0>;
+   sensor@0 {
+   reg = <0>;
+   compatible = "nuvoton,nct7802-thermistor";
+   };
+   sensor@2 {
+   reg = <2>;
+   compatible = "nuvoton,nct7802-thermal-diode";
+   };
+   fan@0 {
+   reg = <0>;
+   compatible = "nuvoton,nct7802-fan-pwm";
+   };
+   fan@1 {
+   reg = <1>;
+   compatible = "nuvoton,nct7802-fan-dc";
+   invert;
+   open-drain;
+   };
+   peci@0 {
+   reg = <0>;
+   compatible = "nuvoton,nct7802-peci";
+   };
+};
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: Please suggest proper format for DT properties.

2015-09-21 Thread Constantine Shulyupin
On Mon, Sep 21, 2015 at 4:51 AM, Rob Herring  wrote:
> On Fri, Sep 18, 2015 at 5:36 PM, Constantine Shulyupin
>  wrote:
>> Hi,
>>
>> I am designing DT support for a hwmon chip.
>> It has some sensors, each of them can be:
>>  - "disabled"
>>  - "thermal diode"
>>  - "thermistor"
>>  - "voltage"
>>
>> Four possible options for DT properties format.
>>
>> Option 1: Separated property for each sensor.
>>
>> Example nct7802 node:
>>
>> nct7802 {
>> compatible = "nuvoton,nct7802";
>> reg = <0x2a>;
>> nuvoton,sensor1-type = "thermistor";
>> nuvoton,sensor2-type = "disabled";
>> nuvoton,sensor3-type = "voltage";
>> };
>>
>> Option 2: Array of strings for all sensors.
>>
>> nct7802 {
>> compatible = "nuvoton,nct7802";
>> reg = <0x2a>;
>> nuvoton,sensors-types = "thermistor", "disabled", "voltage";
>> };
>
> It seems you are just listing out all possible modes. Why do you need
> this in the DT at all? This can be inferred by the compatible string.

There are tree sensor, each of one can be one of three type ("thermal
diode", "thermistor", "voltage") or be disabled.
Also there are at least five platform depended registers, most of them
are enable/disable.
You can find full datasheet here
https://www.nuvoton.com/hq/products/cloud-computing/hardware-monitors/desktop-server-series/nct7802y/

The question is how to describe configuration of this registers in dts.
The second option is array of types for tree registers.

>> Option 3: Sets of 4 cells.
>>
>>   Borrowed from marvell,reg-init and broadcom,c45-reg-init.
>>
>>   The first cell is the page address,
>>   the second a register address within the page,
>>   the third cell contains a mask to be ANDed with the existing register
>>   value, and the fourth cell is ORed with the result to yield the
>>   new register value. If the third cell has a value of zero,
>>   no read of the existing value is performed.
>
> I don't see how this relates to the first 2 options. The register you
> write selects the mode? In general, we don't want bindings of just
> random register writes.
>
> Rob
Option 3 allows arbitrary registers configuration.

To see the full picture you can refer to datasheet mentioned above to
function nct7802_init_chip via
http://lxr.free-electrons.com/source/drivers/hwmon/nct7802.c#L789
and proposed patch for option #2: https://lkml.org/lkml/2015/9/13/204

-- 
Thanks
Constantine
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: Please suggest proper format for DT properties.

2015-09-21 Thread Constantine Shulyupin
On Mon, Sep 21, 2015 at 4:51 AM, Rob Herring <r...@kernel.org> wrote:
> On Fri, Sep 18, 2015 at 5:36 PM, Constantine Shulyupin
> <co...@makelinux.com> wrote:
>> Hi,
>>
>> I am designing DT support for a hwmon chip.
>> It has some sensors, each of them can be:
>>  - "disabled"
>>  - "thermal diode"
>>  - "thermistor"
>>  - "voltage"
>>
>> Four possible options for DT properties format.
>>
>> Option 1: Separated property for each sensor.
>>
>> Example nct7802 node:
>>
>> nct7802 {
>> compatible = "nuvoton,nct7802";
>> reg = <0x2a>;
>> nuvoton,sensor1-type = "thermistor";
>> nuvoton,sensor2-type = "disabled";
>> nuvoton,sensor3-type = "voltage";
>> };
>>
>> Option 2: Array of strings for all sensors.
>>
>> nct7802 {
>> compatible = "nuvoton,nct7802";
>> reg = <0x2a>;
>> nuvoton,sensors-types = "thermistor", "disabled", "voltage";
>> };
>
> It seems you are just listing out all possible modes. Why do you need
> this in the DT at all? This can be inferred by the compatible string.

There are tree sensor, each of one can be one of three type ("thermal
diode", "thermistor", "voltage") or be disabled.
Also there are at least five platform depended registers, most of them
are enable/disable.
You can find full datasheet here
https://www.nuvoton.com/hq/products/cloud-computing/hardware-monitors/desktop-server-series/nct7802y/

The question is how to describe configuration of this registers in dts.
The second option is array of types for tree registers.

>> Option 3: Sets of 4 cells.
>>
>>   Borrowed from marvell,reg-init and broadcom,c45-reg-init.
>>
>>   The first cell is the page address,
>>   the second a register address within the page,
>>   the third cell contains a mask to be ANDed with the existing register
>>   value, and the fourth cell is ORed with the result to yield the
>>   new register value. If the third cell has a value of zero,
>>   no read of the existing value is performed.
>
> I don't see how this relates to the first 2 options. The register you
> write selects the mode? In general, we don't want bindings of just
> random register writes.
>
> Rob
Option 3 allows arbitrary registers configuration.

To see the full picture you can refer to datasheet mentioned above to
function nct7802_init_chip via
http://lxr.free-electrons.com/source/drivers/hwmon/nct7802.c#L789
and proposed patch for option #2: https://lkml.org/lkml/2015/9/13/204

-- 
Thanks
Constantine
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Please suggest proper format for DT properties.

2015-09-18 Thread Constantine Shulyupin
Hi,

I am designing DT support for a hwmon chip. 
It has some sensors, each of them can be:
 - "disabled"
 - "thermal diode"
 - "thermistor"
 - "voltage"

Four possible options for DT properties format.

Option 1: Separated property for each sensor.

Example nct7802 node:

nct7802 {
compatible = "nuvoton,nct7802";
reg = <0x2a>;
nuvoton,sensor1-type = "thermistor";
nuvoton,sensor2-type = "disabled";
nuvoton,sensor3-type = "voltage";
};

Option 2: Array of strings for all sensors.

nct7802 {
compatible = "nuvoton,nct7802";
reg = <0x2a>;
nuvoton,sensors-types = "thermistor", "disabled", "voltage";
};

Option 3: Sets of 4 cells.

  Borrowed from marvell,reg-init and broadcom,c45-reg-init.

  The first cell is the page address, 
  the second a register address within the page,
  the third cell contains a mask to be ANDed with the existing register
  value, and the fourth cell is ORed with the result to yield the
  new register value. If the third cell has a value of zero,
  no read of the existing value is performed.

Example nct7802 node:

nct7802 {
compatible = "nuvoton,nct7802";
reg = <0x2a>;
nct7802,reg-init =
<0 0x21 0 0x01 > // START = 1
<0 0x22 0x03 0x02>; // RTD1_MD = 2
};

Please suggest proper format for DT properties.

Thanks
Constantine

PS:
Datasheet: 
https://www.nuvoton.com/hq/products/cloud-computing/hardware-monitors/desktop-server-series/nct7802y/
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Please suggest proper format for DT properties.

2015-09-18 Thread Constantine Shulyupin
Hi,

I am designing DT support for a hwmon chip. 
It has some sensors, each of them can be:
 - "disabled"
 - "thermal diode"
 - "thermistor"
 - "voltage"

Four possible options for DT properties format.

Option 1: Separated property for each sensor.

Example nct7802 node:

nct7802 {
compatible = "nuvoton,nct7802";
reg = <0x2a>;
nuvoton,sensor1-type = "thermistor";
nuvoton,sensor2-type = "disabled";
nuvoton,sensor3-type = "voltage";
};

Option 2: Array of strings for all sensors.

nct7802 {
compatible = "nuvoton,nct7802";
reg = <0x2a>;
nuvoton,sensors-types = "thermistor", "disabled", "voltage";
};

Option 3: Sets of 4 cells.

  Borrowed from marvell,reg-init and broadcom,c45-reg-init.

  The first cell is the page address, 
  the second a register address within the page,
  the third cell contains a mask to be ANDed with the existing register
  value, and the fourth cell is ORed with the result to yield the
  new register value. If the third cell has a value of zero,
  no read of the existing value is performed.

Example nct7802 node:

nct7802 {
compatible = "nuvoton,nct7802";
reg = <0x2a>;
nct7802,reg-init =
<0 0x21 0 0x01 > // START = 1
<0 0x22 0x03 0x02>; // RTD1_MD = 2
};

Please suggest proper format for DT properties.

Thanks
Constantine

PS:
Datasheet: 
https://www.nuvoton.com/hq/products/cloud-computing/hardware-monitors/desktop-server-series/nct7802y/
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2] hwmon: (nct7802) hwmon: (nct7802) Add device tree support

2015-09-13 Thread Constantine Shulyupin
Introduced properties sensorX-type with string values
"disabled", "thermal diode", "thermistor" and "voltage".

Signed-off-by: Constantine Shulyupin 
---
Changed in v2:
- removed tempX_type
- introduced nuvoton,sensorX-type with string values

Changed in v1:
- Introduced tempX_type with numerical values
---
 drivers/hwmon/nct7802.c | 43 ---
 1 file changed, 40 insertions(+), 3 deletions(-)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index 3ce33d2..edd9063 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -1077,9 +1077,11 @@ static const struct regmap_config nct7802_regmap_config 
= {
.volatile_reg = nct7802_regmap_is_volatile,
 };
 
-static int nct7802_init_chip(struct nct7802_data *data)
+static int nct7802_init_chip(struct device_node *node,
+struct nct7802_data *data)
 {
int err;
+   int i;
 
/* Enable ADC */
err = regmap_update_bits(data->regmap, REG_START, 0x01, 0x01);
@@ -1092,7 +1094,34 @@ static int nct7802_init_chip(struct nct7802_data *data)
return err;
 
/* Enable Vcore and VCC voltage monitoring */
-   return regmap_update_bits(data->regmap, REG_VMON_ENABLE, 0x03, 0x03);
+   err =  regmap_update_bits(data->regmap, REG_VMON_ENABLE, 0x03, 0x03);
+   if (err)
+   return err;
+
+   for (i = 0; i < 3; i++) {
+   char propname[30];
+   const char *val;
+   int senor_type;
+
+   snprintf(propname, sizeof(propname), "nuvoton,sensor%d-type",
+i + 1);
+   err = of_property_read_string(node, propname, );
+   if (err < 0)
+   break;
+   if (!strcmp(val, "disabled"))
+   senor_type = 0;
+   else if (!strcmp(val, "thermal diode"))
+   senor_type = 1;
+   else if (!strcmp(val, "thermistor"))
+   senor_type = 2;
+   else if (!strcmp(val, "voltage"))
+   senor_type = 3;
+   else
+   return -EINVAL;
+   err = regmap_update_bits(data->regmap, REG_MODE,
+3 << 2 * i, senor_type << 2 * i);
+   }
+   return 0;
 }
 
 static int nct7802_probe(struct i2c_client *client,
@@ -1113,7 +1142,7 @@ static int nct7802_probe(struct i2c_client *client,
 
mutex_init(>access_lock);
 
-   ret = nct7802_init_chip(data);
+   ret = nct7802_init_chip(client->dev.of_node, data);
if (ret < 0)
return ret;
 
@@ -1133,10 +1162,18 @@ static const struct i2c_device_id nct7802_idtable[] = {
 };
 MODULE_DEVICE_TABLE(i2c, nct7802_idtable);
 
+#ifdef CONFIG_OF
+static const struct of_device_id nct7802_dt_match[] = {
+   { .compatible = "nuvoton,nct7802" },
+   { },
+};
+#endif
+
 static struct i2c_driver nct7802_driver = {
.class = I2C_CLASS_HWMON,
.driver = {
.name = DRVNAME,
+   .of_match_table = of_match_ptr(nct7802_dt_match),
},
.detect = nct7802_detect,
.probe = nct7802_probe,
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5] Documentation: add Device tree bindings for hwmon/nct7802

2015-09-13 Thread Constantine Shulyupin
Add sensors' types configuration.

---
Changed on v5:
- Fixed typos

Changed on v4:
- Removed registers initialization by names
- Added properties nuvoton,sensor*-type

Changed in v3:
- Fixed vendor prefix
- Added short registers description,
  full registers description is available at
https://www.nuvoton.com/hq/products/cloud-computing/hardware-monitors/desktop-server-series/nct7802y/

Changed in v2:
- Removed nct7802,reg-init
- Added registers initialization by names

Introduced in v1:
 - nct7802,reg-init

Signed-off-by: Constantine Shulyupin 
---
 .../devicetree/bindings/hwmon/nct7802.txt  | 31 ++
 1 file changed, 31 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/nct7802.txt

diff --git a/Documentation/devicetree/bindings/hwmon/nct7802.txt 
b/Documentation/devicetree/bindings/hwmon/nct7802.txt
new file mode 100644
index 000..d9f2fda
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/nct7802.txt
@@ -0,0 +1,31 @@
+Nuvoton NCT7802Y Hardware Monitoring IC
+
+Required node properties:
+
+ - "compatible": must be "nuvoton,nct7802"
+ - "reg": I2C bus address of the device
+
+Optional string properties:
+
+ - nuvoton,sensor1-type
+ - nuvoton,sensor2-type
+ - nuvoton,sensor3-type
+
+Allowed values for nuvoton,sensor*-type:
+ - "disabled"
+ - "thermal diode"
+ - "thermistor"
+ - "voltage"
+
+Except "nuvoton,sensor3-type" can't be "thermal diode".
+
+Example nct7802 node:
+
+nct7802 {
+   compatible = "nuvoton,nct7802";
+   reg = <0x2a>;
+   nuvoton,start = <0x01>;
+   nuvoton,sensor1-type = "thermistor";
+   nuvoton,sensor2-type = "disabled";
+   nuvoton,sensor3-type = "voltage";
+};
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5] Documentation: add Device tree bindings for hwmon/nct7802

2015-09-13 Thread Constantine Shulyupin
Add sensors' types configuration.

---
Changed on v5:
- Fixed typos

Changed on v4:
- Removed registers initialization by names
- Added properties nuvoton,sensor*-type

Changed in v3:
- Fixed vendor prefix
- Added short registers description,
  full registers description is available at
https://www.nuvoton.com/hq/products/cloud-computing/hardware-monitors/desktop-server-series/nct7802y/

Changed in v2:
- Removed nct7802,reg-init
- Added registers initialization by names

Introduced in v1:
 - nct7802,reg-init

Signed-off-by: Constantine Shulyupin <co...@makelinux.com>
---
 .../devicetree/bindings/hwmon/nct7802.txt  | 31 ++
 1 file changed, 31 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/nct7802.txt

diff --git a/Documentation/devicetree/bindings/hwmon/nct7802.txt 
b/Documentation/devicetree/bindings/hwmon/nct7802.txt
new file mode 100644
index 000..d9f2fda
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/nct7802.txt
@@ -0,0 +1,31 @@
+Nuvoton NCT7802Y Hardware Monitoring IC
+
+Required node properties:
+
+ - "compatible": must be "nuvoton,nct7802"
+ - "reg": I2C bus address of the device
+
+Optional string properties:
+
+ - nuvoton,sensor1-type
+ - nuvoton,sensor2-type
+ - nuvoton,sensor3-type
+
+Allowed values for nuvoton,sensor*-type:
+ - "disabled"
+ - "thermal diode"
+ - "thermistor"
+ - "voltage"
+
+Except "nuvoton,sensor3-type" can't be "thermal diode".
+
+Example nct7802 node:
+
+nct7802 {
+   compatible = "nuvoton,nct7802";
+   reg = <0x2a>;
+   nuvoton,start = <0x01>;
+   nuvoton,sensor1-type = "thermistor";
+   nuvoton,sensor2-type = "disabled";
+   nuvoton,sensor3-type = "voltage";
+};
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2] hwmon: (nct7802) hwmon: (nct7802) Add device tree support

2015-09-13 Thread Constantine Shulyupin
Introduced properties sensorX-type with string values
"disabled", "thermal diode", "thermistor" and "voltage".

Signed-off-by: Constantine Shulyupin <co...@makelinux.com>
---
Changed in v2:
- removed tempX_type
- introduced nuvoton,sensorX-type with string values

Changed in v1:
- Introduced tempX_type with numerical values
---
 drivers/hwmon/nct7802.c | 43 ---
 1 file changed, 40 insertions(+), 3 deletions(-)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index 3ce33d2..edd9063 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -1077,9 +1077,11 @@ static const struct regmap_config nct7802_regmap_config 
= {
.volatile_reg = nct7802_regmap_is_volatile,
 };
 
-static int nct7802_init_chip(struct nct7802_data *data)
+static int nct7802_init_chip(struct device_node *node,
+struct nct7802_data *data)
 {
int err;
+   int i;
 
/* Enable ADC */
err = regmap_update_bits(data->regmap, REG_START, 0x01, 0x01);
@@ -1092,7 +1094,34 @@ static int nct7802_init_chip(struct nct7802_data *data)
return err;
 
/* Enable Vcore and VCC voltage monitoring */
-   return regmap_update_bits(data->regmap, REG_VMON_ENABLE, 0x03, 0x03);
+   err =  regmap_update_bits(data->regmap, REG_VMON_ENABLE, 0x03, 0x03);
+   if (err)
+   return err;
+
+   for (i = 0; i < 3; i++) {
+   char propname[30];
+   const char *val;
+   int senor_type;
+
+   snprintf(propname, sizeof(propname), "nuvoton,sensor%d-type",
+i + 1);
+   err = of_property_read_string(node, propname, );
+   if (err < 0)
+   break;
+   if (!strcmp(val, "disabled"))
+   senor_type = 0;
+   else if (!strcmp(val, "thermal diode"))
+   senor_type = 1;
+   else if (!strcmp(val, "thermistor"))
+   senor_type = 2;
+   else if (!strcmp(val, "voltage"))
+   senor_type = 3;
+   else
+   return -EINVAL;
+   err = regmap_update_bits(data->regmap, REG_MODE,
+3 << 2 * i, senor_type << 2 * i);
+   }
+   return 0;
 }
 
 static int nct7802_probe(struct i2c_client *client,
@@ -1113,7 +1142,7 @@ static int nct7802_probe(struct i2c_client *client,
 
mutex_init(>access_lock);
 
-   ret = nct7802_init_chip(data);
+   ret = nct7802_init_chip(client->dev.of_node, data);
if (ret < 0)
return ret;
 
@@ -1133,10 +1162,18 @@ static const struct i2c_device_id nct7802_idtable[] = {
 };
 MODULE_DEVICE_TABLE(i2c, nct7802_idtable);
 
+#ifdef CONFIG_OF
+static const struct of_device_id nct7802_dt_match[] = {
+   { .compatible = "nuvoton,nct7802" },
+   { },
+};
+#endif
+
 static struct i2c_driver nct7802_driver = {
.class = I2C_CLASS_HWMON,
.driver = {
.name = DRVNAME,
+   .of_match_table = of_match_ptr(nct7802_dt_match),
},
.detect = nct7802_detect,
.probe = nct7802_probe,
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4] Documentation: add Device tree bindings for hwmon/nct7802

2015-09-08 Thread Constantine Shulyupin
Add sensors' types configuration.

---

Changed on v4:
- Removed registers initialization by names
- Added properties nuvoton,sensor*-type

Changed in v3:
- Fixed vendor prefix
- Added short registers description,
  full registers description is available at
https://www.nuvoton.com/hq/products/cloud-computing/hardware-monitors/desktop-server-series/nct7802y/

Changed in v2:
- Removed nct7802,reg-init
- Added registers initialization by names

Introduced in v1:
 - nct7802,reg-init

Signed-off-by: Constantine Shulyupin 
---
 .../devicetree/bindings/hwmon/nct7802.txt  | 31 ++
 1 file changed, 31 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/nct7802.txt

diff --git a/Documentation/devicetree/bindings/hwmon/nct7802.txt 
b/Documentation/devicetree/bindings/hwmon/nct7802.txt
new file mode 100644
index 000..20461f5
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/nct7802.txt
@@ -0,0 +1,31 @@
+Nuvoton NCT7802Y Hardware Monitoring IC
+
+Required node properties:
+
+ - "compatible": must be "nuvoton,nct7802"
+ - "reg": I2C bus address of the device
+
+Optional string properties:
+
+ - nuvoton,sensor1-type
+ - nuvoton,sensor2-type
+ - nuvoton,sensor3-type
+
+Allowed values for nuvoton,sensor*-type:
+ - "disabled"
+ - "thermal diode"
+ - "thermistor"
+ - "voltage"
+
+Except "nuvoton,sensor3-type" can't be "thermal diode".
+
+Example nct7802 node:
+
+nct7802 {
+   compatible = "nuvoton,nct7802";
+   reg = <0x2a>;
+   nuvoton,start = <0x01>;
+   nuvoton,moensor1-type = "thermistor";
+   nuvoton,moensor2-type = "disabled";
+   nuvoton,moensor3-type = "voltage";
+};
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3] Documentation: add Device tree bindings for hwmon/nct7802

2015-09-08 Thread Constantine Shulyupin
> Sure, but why do you need _raw_ register values?
>
> Why can you not encode this in the DT in a manner that describes what is
> connected to this device, then have the kernel figure out any particular
> values that need to be poked into registers?
>
> That'll be easier to read, and it's far more likely people will get
> things correct in a dts.
>
> Mark.

Theoretically it is possible to use function store_temp_type
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/drivers/hwmon/nct7802.c#n87
to set sensors types.
With ABI codes:
 3 - thermal diode
 4 - thermistor

But:
- Sensor type could be also voltage and is mapped to in_input
attributes. Generic code would be over complicated.
- For low level programmers and PCB engineers is much more comfortable
and error safe
to works with datasheets, registers and bits than with fancy "human
readable" configuration.
- Mapping between raw bits and ABI is not intuitive. More simple and
directed configuration is preferable.

-- 
Thanks
Constantine
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3] Documentation: add Device tree bindings for hwmon/nct7802

2015-09-08 Thread Constantine Shulyupin
>> Add add Device tree bindings for registers
>> which are not covered by hwmon ABI and are required to
>> configure specific HW.
>
> This doesn't really answer my question [1] of why you need these.
>
> We generally don't encode register values unless there's no other way to
> describe the device. Why can we not describe the physical properties of
> the device that make these values necessary?
>

> That said, as above I don't believe that these properties make sense
> as they are. I think this needs properties that describe the HW, rather
> than exposing the intricacies of the programming interface.

> Thanks,
> Mark.
>
> [1] http://lkml.kernel.org/r/20150907123531.GA11540@leverpostej
>

Sources of the driver:

Let's see to register MODE.
Excerpt from datasheet:

7.2.32 Mode Selection Register
Location : Index 22h
Type : Read/Write
Power on default value : 7Fh
BIT; NAME; FUNC.:
0,1 RTD1_MD : 00=Closed , 01=Current mode , 10=Thermistor mode ,
11=Voltage sense
2,3 RTD2_MD : 00=Closed , 01=Current mode , 10=Thermistor mode ,
11=Voltage sense
4,5 RTD3_MD : 00=Closed , 01=Reserved , 10=Thermistor mode , 11=Voltage sense
6 EnLTD : 1 indicates the LTD function enabled

The register defines sensors types (Closed, Current mode, Thermistor
mode, Voltage sense).
Essential sensors will not work properly with wrong configuration.
It is board or platform depended configuration. It should be
configured on boot only.
Usually hwmon drivers are managed with utility lm-sensors via
Documentation/hwmon/sysfs-interface. By design sensor type should be
defined by platform data and lm-sensors only displays it.

Also MODE registers defines visibility temperature and input attributes:

https://git.kernel.org/cgit/linux/kernel/git/mpe/linux-next.git/tree/drivers/hwmon/nct7802.c#n532

https://git.kernel.org/cgit/linux/kernel/git/mpe/linux-next.git/tree/drivers/hwmon/nct7802.c#n641

Mark, does above answers your question?
What do you propose?

-- 
Thanks
Constantine
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3] Documentation: add Device tree bindings for hwmon/nct7802

2015-09-08 Thread Constantine Shulyupin
>> Add add Device tree bindings for registers
>> which are not covered by hwmon ABI and are required to
>> configure specific HW.
>
> This doesn't really answer my question [1] of why you need these.
>
> We generally don't encode register values unless there's no other way to
> describe the device. Why can we not describe the physical properties of
> the device that make these values necessary?
>

> That said, as above I don't believe that these properties make sense
> as they are. I think this needs properties that describe the HW, rather
> than exposing the intricacies of the programming interface.

> Thanks,
> Mark.
>
> [1] http://lkml.kernel.org/r/20150907123531.GA11540@leverpostej
>

Sources of the driver:

Let's see to register MODE.
Excerpt from datasheet:

7.2.32 Mode Selection Register
Location : Index 22h
Type : Read/Write
Power on default value : 7Fh
BIT; NAME; FUNC.:
0,1 RTD1_MD : 00=Closed , 01=Current mode , 10=Thermistor mode ,
11=Voltage sense
2,3 RTD2_MD : 00=Closed , 01=Current mode , 10=Thermistor mode ,
11=Voltage sense
4,5 RTD3_MD : 00=Closed , 01=Reserved , 10=Thermistor mode , 11=Voltage sense
6 EnLTD : 1 indicates the LTD function enabled

The register defines sensors types (Closed, Current mode, Thermistor
mode, Voltage sense).
Essential sensors will not work properly with wrong configuration.
It is board or platform depended configuration. It should be
configured on boot only.
Usually hwmon drivers are managed with utility lm-sensors via
Documentation/hwmon/sysfs-interface. By design sensor type should be
defined by platform data and lm-sensors only displays it.

Also MODE registers defines visibility temperature and input attributes:

https://git.kernel.org/cgit/linux/kernel/git/mpe/linux-next.git/tree/drivers/hwmon/nct7802.c#n532

https://git.kernel.org/cgit/linux/kernel/git/mpe/linux-next.git/tree/drivers/hwmon/nct7802.c#n641

Mark, does above answers your question?
What do you propose?

-- 
Thanks
Constantine
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4] Documentation: add Device tree bindings for hwmon/nct7802

2015-09-08 Thread Constantine Shulyupin
Add sensors' types configuration.

---

Changed on v4:
- Removed registers initialization by names
- Added properties nuvoton,sensor*-type

Changed in v3:
- Fixed vendor prefix
- Added short registers description,
  full registers description is available at
https://www.nuvoton.com/hq/products/cloud-computing/hardware-monitors/desktop-server-series/nct7802y/

Changed in v2:
- Removed nct7802,reg-init
- Added registers initialization by names

Introduced in v1:
 - nct7802,reg-init

Signed-off-by: Constantine Shulyupin <co...@makelinux.com>
---
 .../devicetree/bindings/hwmon/nct7802.txt  | 31 ++
 1 file changed, 31 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/nct7802.txt

diff --git a/Documentation/devicetree/bindings/hwmon/nct7802.txt 
b/Documentation/devicetree/bindings/hwmon/nct7802.txt
new file mode 100644
index 000..20461f5
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/nct7802.txt
@@ -0,0 +1,31 @@
+Nuvoton NCT7802Y Hardware Monitoring IC
+
+Required node properties:
+
+ - "compatible": must be "nuvoton,nct7802"
+ - "reg": I2C bus address of the device
+
+Optional string properties:
+
+ - nuvoton,sensor1-type
+ - nuvoton,sensor2-type
+ - nuvoton,sensor3-type
+
+Allowed values for nuvoton,sensor*-type:
+ - "disabled"
+ - "thermal diode"
+ - "thermistor"
+ - "voltage"
+
+Except "nuvoton,sensor3-type" can't be "thermal diode".
+
+Example nct7802 node:
+
+nct7802 {
+   compatible = "nuvoton,nct7802";
+   reg = <0x2a>;
+   nuvoton,start = <0x01>;
+   nuvoton,moensor1-type = "thermistor";
+   nuvoton,moensor2-type = "disabled";
+   nuvoton,moensor3-type = "voltage";
+};
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3] Documentation: add Device tree bindings for hwmon/nct7802

2015-09-08 Thread Constantine Shulyupin
> Sure, but why do you need _raw_ register values?
>
> Why can you not encode this in the DT in a manner that describes what is
> connected to this device, then have the kernel figure out any particular
> values that need to be poked into registers?
>
> That'll be easier to read, and it's far more likely people will get
> things correct in a dts.
>
> Mark.

Theoretically it is possible to use function store_temp_type
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/drivers/hwmon/nct7802.c#n87
to set sensors types.
With ABI codes:
 3 - thermal diode
 4 - thermistor

But:
- Sensor type could be also voltage and is mapped to in_input
attributes. Generic code would be over complicated.
- For low level programmers and PCB engineers is much more comfortable
and error safe
to works with datasheets, registers and bits than with fancy "human
readable" configuration.
- Mapping between raw bits and ABI is not intuitive. More simple and
directed configuration is preferable.

-- 
Thanks
Constantine
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3] Documentation: add Device tree bindings for hwmon/nct7802

2015-09-07 Thread Constantine Shulyupin
Add add Device tree bindings for registers
which are not covered by hwmon ABI and are required to
configure specific HW.
---

Changed in v3:
- Fixed vendor prefix
- Added short registers description,
  full registers description is available at
https://www.nuvoton.com/hq/products/cloud-computing/hardware-monitors/desktop-server-series/nct7802y/

Changed in v2:
- Removed nct7802,reg-init
- Added registers initialization by names

Introduced in v1:
 - nct7802,reg-init

Signed-off-by: Constantine Shulyupin 
---
 .../devicetree/bindings/hwmon/nct7802.txt  | 28 ++
 1 file changed, 28 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/nct7802.txt

diff --git a/Documentation/devicetree/bindings/hwmon/nct7802.txt 
b/Documentation/devicetree/bindings/hwmon/nct7802.txt
new file mode 100644
index 000..5b4c3fe
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/nct7802.txt
@@ -0,0 +1,28 @@
+Nuvoton NCT7802Y Hardware Monitoring IC
+
+Required node properties:
+
+ - "compatible": must be "nuvoton,nct7802"
+ - "reg": I2C bus address of the device
+
+Optional properties:
+
+One byte registers:
+ - nuvoton,start - Start register at index 0x21
+ - nuvoton,mode - Mode register at index 0x22
+ - nuvoton,en_peci - PECI enable register at index 0x23
+ - nuvoton,en_fan - Fan Enable Register at index 0x24
+ - nuvoton,en_v - voltage monitor enable register
+ at index 0x25
+
+A detailed datasheet for registers and the device is
+available at Nuvoton web site.
+
+Example nct7802 node:
+
+nct7802 {
+   compatible = "nuvoton,nct7802";
+   reg = <0x2a>;
+   nuvoton,start = <0x01>;
+   nuvoton,mode = <0x7E>; // RTD1_MD = 2
+};
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3] Documentation: add Device tree bindings for hwmon/nct7802

2015-09-07 Thread Constantine Shulyupin
Add add Device tree bindings for registers
which are not covered by hwmon ABI and are required to
configure specific HW.
---

Changed in v3:
- Fixed vendor prefix
- Added short registers description,
  full registers description is available at
https://www.nuvoton.com/hq/products/cloud-computing/hardware-monitors/desktop-server-series/nct7802y/

Changed in v2:
- Removed nct7802,reg-init
- Added registers initialization by names

Introduced in v1:
 - nct7802,reg-init

Signed-off-by: Constantine Shulyupin <co...@makelinux.com>
---
 .../devicetree/bindings/hwmon/nct7802.txt  | 28 ++
 1 file changed, 28 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/nct7802.txt

diff --git a/Documentation/devicetree/bindings/hwmon/nct7802.txt 
b/Documentation/devicetree/bindings/hwmon/nct7802.txt
new file mode 100644
index 000..5b4c3fe
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/nct7802.txt
@@ -0,0 +1,28 @@
+Nuvoton NCT7802Y Hardware Monitoring IC
+
+Required node properties:
+
+ - "compatible": must be "nuvoton,nct7802"
+ - "reg": I2C bus address of the device
+
+Optional properties:
+
+One byte registers:
+ - nuvoton,start - Start register at index 0x21
+ - nuvoton,mode - Mode register at index 0x22
+ - nuvoton,en_peci - PECI enable register at index 0x23
+ - nuvoton,en_fan - Fan Enable Register at index 0x24
+ - nuvoton,en_v - voltage monitor enable register
+ at index 0x25
+
+A detailed datasheet for registers and the device is
+available at Nuvoton web site.
+
+Example nct7802 node:
+
+nct7802 {
+   compatible = "nuvoton,nct7802";
+   reg = <0x2a>;
+   nuvoton,start = <0x01>;
+   nuvoton,mode = <0x7E>; // RTD1_MD = 2
+};
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2] Documentation: add Device tree bindings for hwmon/nct7802

2015-09-06 Thread Constantine Shulyupin
Changed in v2:
- Removed nct7802,reg-init
- Added registers initialization by names

Introduced in v1:
 - nct7802,reg-init

Signed-off-by: Constantine Shulyupin 
---
---
 .../devicetree/bindings/hwmon/nct7802.txt  | 24 ++
 1 file changed, 24 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/nct7802.txt

diff --git a/Documentation/devicetree/bindings/hwmon/nct7802.txt 
b/Documentation/devicetree/bindings/hwmon/nct7802.txt
new file mode 100644
index 000..56214bf
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/nct7802.txt
@@ -0,0 +1,24 @@
+Nuvoton NCT7802Y Hardware Monitoring IC
+
+Required node properties:
+
+ - "compatible": must be "nuvoton,nct7802"
+ - "reg": I2C bus address of the device
+
+Optional properties:
+
+One byte registers:
+ - nct7802,Start
+ - nct7802,Mode
+ - nct7802,EnPECI
+ - nct7802,EnFan
+ - nct7802,EnV
+
+Example nct7802 node:
+
+nct7802 {
+   compatible = "nuvoton,nct7802";
+   reg = <0x2a>;
+   nct7802,Start = <0x01>;
+   nct7802,Mode = <0x7E>; // RTD1_MD = 2
+};
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2] Documentation: add Device tree bindings for hwmon/nct7802

2015-09-06 Thread Constantine Shulyupin
Changed in v2:
- Removed nct7802,reg-init
- Added registers initialization by names

Introduced in v1:
 - nct7802,reg-init

Signed-off-by: Constantine Shulyupin <co...@makelinux.com>
---
---
 .../devicetree/bindings/hwmon/nct7802.txt  | 24 ++
 1 file changed, 24 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/nct7802.txt

diff --git a/Documentation/devicetree/bindings/hwmon/nct7802.txt 
b/Documentation/devicetree/bindings/hwmon/nct7802.txt
new file mode 100644
index 000..56214bf
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/nct7802.txt
@@ -0,0 +1,24 @@
+Nuvoton NCT7802Y Hardware Monitoring IC
+
+Required node properties:
+
+ - "compatible": must be "nuvoton,nct7802"
+ - "reg": I2C bus address of the device
+
+Optional properties:
+
+One byte registers:
+ - nct7802,Start
+ - nct7802,Mode
+ - nct7802,EnPECI
+ - nct7802,EnFan
+ - nct7802,EnV
+
+Example nct7802 node:
+
+nct7802 {
+   compatible = "nuvoton,nct7802";
+   reg = <0x2a>;
+   nct7802,Start = <0x01>;
+   nct7802,Mode = <0x7E>; // RTD1_MD = 2
+};
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v1] Documentation: add Device tree bindings for hwmon/nct7802

2015-08-30 Thread Constantine Shulyupin
reg-init implementation is borowerd from
broadcom,c45-reg-init and marvell,reg-init.

Signed-off-by: Constantine Shulyupin 
---
---
 .../devicetree/bindings/hwmon/nct7802.txt  | 27 ++
 1 file changed, 27 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/nct7802.txt

diff --git a/Documentation/devicetree/bindings/hwmon/nct7802.txt 
b/Documentation/devicetree/bindings/hwmon/nct7802.txt
new file mode 100644
index 000..fa83628
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/nct7802.txt
@@ -0,0 +1,27 @@
+Nuvoton NCT7802Y Hardware Monitoring IC
+
+Required node properties:
+
+ - "compatible": must be "nuvoton,nct7802"
+ - "reg": I2C bus address of the device
+
+Optional properties:
+
+Numeric registors initialiaztion:
+
+- nct7802,reg-init : one of more sets of 4 cells.  The first cell
+  is the page address, the second a register address within the page,
+  the third cell contains a mask to be ANDed with the existing register
+  value, and the fourth cell is ORed with the result to yield the
+  new register value. If the third cell has a value of zero,
+  no read of the existing value is performed.
+
+Example nct7802 node:
+
+nct7802 {
+   compatible = "nuvoton,nct7802";
+   reg = <0x2a>;
+   nct7802,reg-init =
+   <0 0x21 0 0x01 > // START = 1
+   <0 0x22 0x03 0x02>; // RTD1_MD = 2
+};
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v1] Documentation: add Device tree bindings for hwmon/nct7802

2015-08-30 Thread Constantine Shulyupin
reg-init implementation is borowerd from
broadcom,c45-reg-init and marvell,reg-init.

Signed-off-by: Constantine Shulyupin co...@makelinux.com
---
---
 .../devicetree/bindings/hwmon/nct7802.txt  | 27 ++
 1 file changed, 27 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/nct7802.txt

diff --git a/Documentation/devicetree/bindings/hwmon/nct7802.txt 
b/Documentation/devicetree/bindings/hwmon/nct7802.txt
new file mode 100644
index 000..fa83628
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/nct7802.txt
@@ -0,0 +1,27 @@
+Nuvoton NCT7802Y Hardware Monitoring IC
+
+Required node properties:
+
+ - compatible: must be nuvoton,nct7802
+ - reg: I2C bus address of the device
+
+Optional properties:
+
+Numeric registors initialiaztion:
+
+- nct7802,reg-init : one of more sets of 4 cells.  The first cell
+  is the page address, the second a register address within the page,
+  the third cell contains a mask to be ANDed with the existing register
+  value, and the fourth cell is ORed with the result to yield the
+  new register value. If the third cell has a value of zero,
+  no read of the existing value is performed.
+
+Example nct7802 node:
+
+nct7802 {
+   compatible = nuvoton,nct7802;
+   reg = 0x2a;
+   nct7802,reg-init =
+   0 0x21 0 0x01  // START = 1
+   0 0x22 0x03 0x02; // RTD1_MD = 2
+};
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v1 RESEND] of: Add vendor prefix for Nuvoton

2015-08-05 Thread Constantine Shulyupin
Signed-off-by: Constantine Shulyupin 
---
 Documentation/devicetree/bindings/vendor-prefixes.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt 
b/Documentation/devicetree/bindings/vendor-prefixes.txt
index 181b53e..449805a 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.txt
+++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
@@ -149,6 +149,7 @@ netxeon Shenzhen Netxeon Technology CO., LTD
 newhaven   Newhaven Display International
 nintendo   Nintendo
 nokia  Nokia
+nuvotonNuvoton Technology Corporation
 nvidia NVIDIA
 nxpNXP Semiconductors
 onnn   ON Semiconductor Corp.
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v1 RESEND] of: Add vendor prefix for Nuvoton

2015-08-05 Thread Constantine Shulyupin
Signed-off-by: Constantine Shulyupin co...@makelinux.com
---
 Documentation/devicetree/bindings/vendor-prefixes.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt 
b/Documentation/devicetree/bindings/vendor-prefixes.txt
index 181b53e..449805a 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.txt
+++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
@@ -149,6 +149,7 @@ netxeon Shenzhen Netxeon Technology CO., LTD
 newhaven   Newhaven Display International
 nintendo   Nintendo
 nokia  Nokia
+nuvotonNuvoton Technology Corporation
 nvidia NVIDIA
 nxpNXP Semiconductors
 onnn   ON Semiconductor Corp.
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v1] of: Add vendor prefix for Nuvoton

2015-08-01 Thread Constantine Shulyupin
Signed-off-by: Constantine Shulyupin 
---
 Documentation/devicetree/bindings/vendor-prefixes.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt 
b/Documentation/devicetree/bindings/vendor-prefixes.txt
index 181b53e..449805a 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.txt
+++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
@@ -149,6 +149,7 @@ netxeon Shenzhen Netxeon Technology CO., LTD
 newhaven   Newhaven Display International
 nintendo   Nintendo
 nokia  Nokia
+nuvotonNuvoton Technology Corporation
 nvidia NVIDIA
 nxpNXP Semiconductors
 onnn   ON Semiconductor Corp.
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v1] of: Add vendor prefix for Nuvoton

2015-08-01 Thread Constantine Shulyupin
Signed-off-by: Constantine Shulyupin co...@makelinux.com
---
 Documentation/devicetree/bindings/vendor-prefixes.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt 
b/Documentation/devicetree/bindings/vendor-prefixes.txt
index 181b53e..449805a 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.txt
+++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
@@ -149,6 +149,7 @@ netxeon Shenzhen Netxeon Technology CO., LTD
 newhaven   Newhaven Display International
 nintendo   Nintendo
 nokia  Nokia
+nuvotonNuvoton Technology Corporation
 nvidia NVIDIA
 nxpNXP Semiconductors
 onnn   ON Semiconductor Corp.
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v1] hwmon: (nct7802) Add device tree support

2015-07-31 Thread Constantine Shulyupin
Signed-off-by: Constantine Shulyupin 
---
The first trial.
Question: how to configure local temp4 (EnLTD)?
Allow "temp4_type = <3>" (EnLTD=3-2=1) or "temp4_enable = <1>" or else?
---
 .../devicetree/bindings/hwmon/nct7802.txt  | 28 
 .../devicetree/bindings/vendor-prefixes.txt|  1 +
 drivers/hwmon/nct7802.c| 52 +-
 3 files changed, 71 insertions(+), 10 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/hwmon/nct7802.txt

diff --git a/Documentation/devicetree/bindings/hwmon/nct7802.txt 
b/Documentation/devicetree/bindings/hwmon/nct7802.txt
new file mode 100644
index 000..568d3aa
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/nct7802.txt
@@ -0,0 +1,28 @@
+Nuvoton NCT7802Y Hardware Monitoring IC
+
+Required node properties:
+
+ - "compatible": must be "nuvoton,nct7802"
+ - "reg": I2C bus address of the device
+
+Optional properties:
+
+ - temp1_type
+ - temp2_type
+ - temp3_type
+
+Valid values:
+
+ 0 - disabled
+ 3 - thermal diode
+ 4 - thermistor
+
+Example nct7802 node:
+
+nct7802 {
+   compatible = "nuvoton,nct7802";
+   reg = <0x2a>;
+   temp1_type = <4>;
+   temp2_type = <4>;
+   temp3_type = <4>;
+};
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt 
b/Documentation/devicetree/bindings/vendor-prefixes.txt
index 181b53e..821e000 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.txt
+++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
@@ -149,6 +149,7 @@ netxeon Shenzhen Netxeon Technology CO., LTD
 newhaven   Newhaven Display International
 nintendo   Nintendo
 nokia  Nokia
+nuvotonNuvoton
 nvidia NVIDIA
 nxpNXP Semiconductors
 onnn   ON Semiconductor Corp.
diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index 3ce33d2..2be995d 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -84,24 +84,30 @@ static ssize_t show_temp_type(struct device *dev, struct 
device_attribute *attr,
return sprintf(buf, "%u\n", (mode >> (2 * sattr->index) & 3) + 2);
 }
 
+int set_temp_type(struct nct7802_data *data, int index, u8 type)
+{
+   if (index == 2 && type != 4) /* RD3 */
+   return -EINVAL;
+   if ((type > 0 && type < 3) || type > 4)
+   return -EINVAL;
+   return regmap_update_bits(data->regmap, REG_MODE,
+ 3 << 2 * index,
+ (type ? type - 2 : 0) << 2 * index);
+}
+
 static ssize_t store_temp_type(struct device *dev,
   struct device_attribute *attr,
   const char *buf, size_t count)
 {
struct nct7802_data *data = dev_get_drvdata(dev);
struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
-   unsigned int type;
+   u8 type;
int err;
 
-   err = kstrtouint(buf, 0, );
+   err = kstrtou8(buf, 0, );
if (err < 0)
return err;
-   if (sattr->index == 2 && type != 4) /* RD3 */
-   return -EINVAL;
-   if (type < 3 || type > 4)
-   return -EINVAL;
-   err = regmap_update_bits(data->regmap, REG_MODE,
-   3 << 2 * sattr->index, (type - 2) << 2 * sattr->index);
+   err = set_temp_type(data, sattr->index, type);
return err ? : count;
 }
 
@@ -1077,9 +1083,11 @@ static const struct regmap_config nct7802_regmap_config 
= {
.volatile_reg = nct7802_regmap_is_volatile,
 };
 
-static int nct7802_init_chip(struct nct7802_data *data)
+static int nct7802_init_chip(struct device_node *node,
+struct nct7802_data *data)
 {
int err;
+   u32 temp_type;
 
/* Enable ADC */
err = regmap_update_bits(data->regmap, REG_START, 0x01, 0x01);
@@ -1091,6 +1099,22 @@ static int nct7802_init_chip(struct nct7802_data *data)
if (err)
return err;
 
+   if (of_property_read_u32(node, "temp1_type", _type) == 0) {
+   err = set_temp_type(data, 0, temp_type);
+   if (err)
+   return err;
+   }
+   if (of_property_read_u32(node, "temp2_type", _type) == 0) {
+   err = set_temp_type(data, 1, temp_type);
+   if (err)
+   return err;
+   }
+   if (of_property_read_u32(node, "temp3_type", _type) == 0) {
+   err = set_temp_type(data, 2, temp_type);
+   if (err)
+   return err;
+   }
+
/* Enable Vcore and VCC voltage monitoring */
return regmap_update_bits(data->regmap, REG_VMON_ENABLE, 0x03, 0x03);
 }
@@ -1113,7 +1137,7 @@ static int nct7802_pr

[PATCH v1] hwmon: (nct7802) Add device tree support

2015-07-31 Thread Constantine Shulyupin
Signed-off-by: Constantine Shulyupin co...@makelinux.com
---
The first trial.
Question: how to configure local temp4 (EnLTD)?
Allow temp4_type = 3 (EnLTD=3-2=1) or temp4_enable = 1 or else?
---
 .../devicetree/bindings/hwmon/nct7802.txt  | 28 
 .../devicetree/bindings/vendor-prefixes.txt|  1 +
 drivers/hwmon/nct7802.c| 52 +-
 3 files changed, 71 insertions(+), 10 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/hwmon/nct7802.txt

diff --git a/Documentation/devicetree/bindings/hwmon/nct7802.txt 
b/Documentation/devicetree/bindings/hwmon/nct7802.txt
new file mode 100644
index 000..568d3aa
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/nct7802.txt
@@ -0,0 +1,28 @@
+Nuvoton NCT7802Y Hardware Monitoring IC
+
+Required node properties:
+
+ - compatible: must be nuvoton,nct7802
+ - reg: I2C bus address of the device
+
+Optional properties:
+
+ - temp1_type
+ - temp2_type
+ - temp3_type
+
+Valid values:
+
+ 0 - disabled
+ 3 - thermal diode
+ 4 - thermistor
+
+Example nct7802 node:
+
+nct7802 {
+   compatible = nuvoton,nct7802;
+   reg = 0x2a;
+   temp1_type = 4;
+   temp2_type = 4;
+   temp3_type = 4;
+};
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt 
b/Documentation/devicetree/bindings/vendor-prefixes.txt
index 181b53e..821e000 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.txt
+++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
@@ -149,6 +149,7 @@ netxeon Shenzhen Netxeon Technology CO., LTD
 newhaven   Newhaven Display International
 nintendo   Nintendo
 nokia  Nokia
+nuvotonNuvoton
 nvidia NVIDIA
 nxpNXP Semiconductors
 onnn   ON Semiconductor Corp.
diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index 3ce33d2..2be995d 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -84,24 +84,30 @@ static ssize_t show_temp_type(struct device *dev, struct 
device_attribute *attr,
return sprintf(buf, %u\n, (mode  (2 * sattr-index)  3) + 2);
 }
 
+int set_temp_type(struct nct7802_data *data, int index, u8 type)
+{
+   if (index == 2  type != 4) /* RD3 */
+   return -EINVAL;
+   if ((type  0  type  3) || type  4)
+   return -EINVAL;
+   return regmap_update_bits(data-regmap, REG_MODE,
+ 3  2 * index,
+ (type ? type - 2 : 0)  2 * index);
+}
+
 static ssize_t store_temp_type(struct device *dev,
   struct device_attribute *attr,
   const char *buf, size_t count)
 {
struct nct7802_data *data = dev_get_drvdata(dev);
struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
-   unsigned int type;
+   u8 type;
int err;
 
-   err = kstrtouint(buf, 0, type);
+   err = kstrtou8(buf, 0, type);
if (err  0)
return err;
-   if (sattr-index == 2  type != 4) /* RD3 */
-   return -EINVAL;
-   if (type  3 || type  4)
-   return -EINVAL;
-   err = regmap_update_bits(data-regmap, REG_MODE,
-   3  2 * sattr-index, (type - 2)  2 * sattr-index);
+   err = set_temp_type(data, sattr-index, type);
return err ? : count;
 }
 
@@ -1077,9 +1083,11 @@ static const struct regmap_config nct7802_regmap_config 
= {
.volatile_reg = nct7802_regmap_is_volatile,
 };
 
-static int nct7802_init_chip(struct nct7802_data *data)
+static int nct7802_init_chip(struct device_node *node,
+struct nct7802_data *data)
 {
int err;
+   u32 temp_type;
 
/* Enable ADC */
err = regmap_update_bits(data-regmap, REG_START, 0x01, 0x01);
@@ -1091,6 +1099,22 @@ static int nct7802_init_chip(struct nct7802_data *data)
if (err)
return err;
 
+   if (of_property_read_u32(node, temp1_type, temp_type) == 0) {
+   err = set_temp_type(data, 0, temp_type);
+   if (err)
+   return err;
+   }
+   if (of_property_read_u32(node, temp2_type, temp_type) == 0) {
+   err = set_temp_type(data, 1, temp_type);
+   if (err)
+   return err;
+   }
+   if (of_property_read_u32(node, temp3_type, temp_type) == 0) {
+   err = set_temp_type(data, 2, temp_type);
+   if (err)
+   return err;
+   }
+
/* Enable Vcore and VCC voltage monitoring */
return regmap_update_bits(data-regmap, REG_VMON_ENABLE, 0x03, 0x03);
 }
@@ -1113,7 +1137,7 @@ static int nct7802_probe(struct i2c_client *client,
 
mutex_init(data-access_lock);
 
-   ret = nct7802_init_chip(data);
+   ret = nct7802_init_chip(client-dev.of_node, data);
if (ret  0)
return ret;
 
@@ -1133,10 +1157,18 @@ static const struct

[PATCH v5] hwmon: (nct7802) Add auto_point attributes

2015-07-27 Thread Constantine Shulyupin
Introduced REG_PWM, pwm[1..3]_auto_point[1..5]_temp,
pwm[1..3]_auto_point[1..5]_pwm, nct7802_auto_point_attrs,
nct7802_auto_point_group, updated nct7802_regmap_is_volatile

Signed-off-by: Constantine Shulyupin 
---

Changed in v5:
- removed URL and fixed typo
Changed in v4:
- fixed expression in nct7802_regmap_is_volatile
- added pwmX_auto_point to driver's documentation
Changed in v3:
- removed nct7802_auto_point_is_visible
- removed usage of sysfs_update_group
- introduced REG_PWM
- removed S_IWUSR from RO attributes
- added PWM registers to nct7802_regmap_is_volatile
Changed in v2:
- removed PWM_REG, TEMP_REG
- removed auto_point[1..4]_temp, auto_point[1..4]_pwm
  and auto_point_crit_temp
- introduced pwm[1..3]_auto_point[1..5]_temp
  and pwm[1..3]_auto_point[1..5]_pwm.
- introduced nct7802_auto_point_is_visible
- used sysfs_update_group in store_pwm_enable
---
 Documentation/hwmon/nct7802 |   3 +-
 drivers/hwmon/nct7802.c | 130 ++--
 2 files changed, 127 insertions(+), 6 deletions(-)

diff --git a/Documentation/hwmon/nct7802 b/Documentation/hwmon/nct7802
index 2e00f5e..5438deb 100644
--- a/Documentation/hwmon/nct7802
+++ b/Documentation/hwmon/nct7802
@@ -17,8 +17,7 @@ This driver implements support for the Nuvoton NCT7802Y 
hardware monitoring
 chip. NCT7802Y supports 6 temperature sensors, 5 voltage sensors, and 3 fan
 speed sensors.
 
-The chip also supports intelligent fan speed control. This functionality is
-not currently supported by the driver.
+Smart Fan??? speed control is available via pwmX_auto_point attributes.
 
 Tested Boards and BIOS Versions
 ---
diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index d018571..c1898ba 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -53,6 +53,7 @@ static const u8 REG_VOLTAGE_LIMIT_MSB_SHIFT[2][5] = {
 #define REG_PECI_ENABLE0x23
 #define REG_FAN_ENABLE 0x24
 #define REG_VMON_ENABLE0x25
+#define REG_PWM(x) (0x60 + (x))
 #define REG_SMARTFAN_EN(x)  (0x64 + (x) / 2)
 #define SMARTFAN_EN_SHIFT(x)((x) % 2 * 4)
 #define REG_VENDOR_ID  0xfd
@@ -130,6 +131,9 @@ static ssize_t show_pwm(struct device *dev, struct 
device_attribute *devattr,
unsigned int val;
int ret;
 
+   if (!attr->index)
+   return sprintf(buf, "255\n");
+
ret = regmap_read(data->regmap, attr->index, );
if (ret < 0)
return ret;
@@ -826,9 +830,12 @@ static SENSOR_DEVICE_ATTR(pwm2_mode, S_IRUGO, 
show_pwm_mode, NULL, 1);
 static SENSOR_DEVICE_ATTR(pwm3_mode, S_IRUGO, show_pwm_mode, NULL, 2);
 
 /* 7.2.91... Fan Control Output Value */
-static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x60);
-static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x61);
-static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x62);
+static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_pwm,
+ REG_PWM(0));
+static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm,
+ REG_PWM(1));
+static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_pwm,
+ REG_PWM(2));
 
 /* 7.2.95... Temperature to Fan mapping Relationships Register */
 static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
@@ -893,11 +900,125 @@ static struct attribute_group nct7802_pwm_group = {
.attrs = nct7802_pwm_attrs,
 };
 
+/* 7.2.115... 0x80-0x83, 0x84 Temperature (X-axis) transition */
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x80, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x81, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x82, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x83, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point5_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x84, 0);
+
+/* 7.2.120... 0x85-0x88 PWM (Y-axis) transition */
+static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x85);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x86);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point3_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x87);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point4_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x88);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point5_pwm, S_IRUGO, show_pwm, NULL, 0);
+
+/* 7.2.124 Table 2 X-axis Transition Point

[PATCH v5] hwmon: (nct7802) Add auto_point attributes

2015-07-27 Thread Constantine Shulyupin
Introduced REG_PWM, pwm[1..3]_auto_point[1..5]_temp,
pwm[1..3]_auto_point[1..5]_pwm, nct7802_auto_point_attrs,
nct7802_auto_point_group, updated nct7802_regmap_is_volatile

Signed-off-by: Constantine Shulyupin co...@makelinux.com
---

Changed in v5:
- removed URL and fixed typo
Changed in v4:
- fixed expression in nct7802_regmap_is_volatile
- added pwmX_auto_point to driver's documentation
Changed in v3:
- removed nct7802_auto_point_is_visible
- removed usage of sysfs_update_group
- introduced REG_PWM
- removed S_IWUSR from RO attributes
- added PWM registers to nct7802_regmap_is_volatile
Changed in v2:
- removed PWM_REG, TEMP_REG
- removed auto_point[1..4]_temp, auto_point[1..4]_pwm
  and auto_point_crit_temp
- introduced pwm[1..3]_auto_point[1..5]_temp
  and pwm[1..3]_auto_point[1..5]_pwm.
- introduced nct7802_auto_point_is_visible
- used sysfs_update_group in store_pwm_enable
---
 Documentation/hwmon/nct7802 |   3 +-
 drivers/hwmon/nct7802.c | 130 ++--
 2 files changed, 127 insertions(+), 6 deletions(-)

diff --git a/Documentation/hwmon/nct7802 b/Documentation/hwmon/nct7802
index 2e00f5e..5438deb 100644
--- a/Documentation/hwmon/nct7802
+++ b/Documentation/hwmon/nct7802
@@ -17,8 +17,7 @@ This driver implements support for the Nuvoton NCT7802Y 
hardware monitoring
 chip. NCT7802Y supports 6 temperature sensors, 5 voltage sensors, and 3 fan
 speed sensors.
 
-The chip also supports intelligent fan speed control. This functionality is
-not currently supported by the driver.
+Smart Fan??? speed control is available via pwmX_auto_point attributes.
 
 Tested Boards and BIOS Versions
 ---
diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index d018571..c1898ba 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -53,6 +53,7 @@ static const u8 REG_VOLTAGE_LIMIT_MSB_SHIFT[2][5] = {
 #define REG_PECI_ENABLE0x23
 #define REG_FAN_ENABLE 0x24
 #define REG_VMON_ENABLE0x25
+#define REG_PWM(x) (0x60 + (x))
 #define REG_SMARTFAN_EN(x)  (0x64 + (x) / 2)
 #define SMARTFAN_EN_SHIFT(x)((x) % 2 * 4)
 #define REG_VENDOR_ID  0xfd
@@ -130,6 +131,9 @@ static ssize_t show_pwm(struct device *dev, struct 
device_attribute *devattr,
unsigned int val;
int ret;
 
+   if (!attr-index)
+   return sprintf(buf, 255\n);
+
ret = regmap_read(data-regmap, attr-index, val);
if (ret  0)
return ret;
@@ -826,9 +830,12 @@ static SENSOR_DEVICE_ATTR(pwm2_mode, S_IRUGO, 
show_pwm_mode, NULL, 1);
 static SENSOR_DEVICE_ATTR(pwm3_mode, S_IRUGO, show_pwm_mode, NULL, 2);
 
 /* 7.2.91... Fan Control Output Value */
-static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x60);
-static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x61);
-static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x62);
+static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_pwm,
+ REG_PWM(0));
+static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm,
+ REG_PWM(1));
+static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_pwm,
+ REG_PWM(2));
 
 /* 7.2.95... Temperature to Fan mapping Relationships Register */
 static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
@@ -893,11 +900,125 @@ static struct attribute_group nct7802_pwm_group = {
.attrs = nct7802_pwm_attrs,
 };
 
+/* 7.2.115... 0x80-0x83, 0x84 Temperature (X-axis) transition */
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x80, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x81, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x82, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x83, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point5_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x84, 0);
+
+/* 7.2.120... 0x85-0x88 PWM (Y-axis) transition */
+static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x85);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x86);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point3_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x87);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point4_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x88);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point5_pwm, S_IRUGO, show_pwm, NULL, 0);
+
+/* 7.2.124 Table 2 X-axis Transition Point 1 Register */
+static

[PATCH v4] hwmon: (nct7802) Add autopoint attributes

2015-07-25 Thread Constantine Shulyupin
Introduced REG_PWM, pwm[1..3]_auto_point[1..5]_temp,
pwm[1..3]_auto_point[1..5]_pwm, nct7802_auto_point_attrs,
nct7802_auto_point_group, updated nct7802_regmap_is_volatile

Signed-off-by: Constantine Shulyupin 
---

Changed in v4:
- fixed expression in nct7802_regmap_is_volatile
- added pwmX_auto_temp to driver's documentation
Changed in v3:
- removed nct7802_auto_point_is_visible
- removed usage of sysfs_update_group
- introduced REG_PWM
- removed S_IWUSR from RO attributes
- added PWM registers to nct7802_regmap_is_volatile
Changed in v2:
- removed PWM_REG, TEMP_REG
- removed auto_point[1..4]_temp, auto_point[1..4]_pwm
  and auto_point_crit_temp
- introduced pwm[1..3]_auto_point[1..5]_temp
  and pwm[1..3]_auto_point[1..5]_pwm.
- introduced nct7802_auto_point_is_visible
- used sysfs_update_group in store_pwm_enable

Default values on my platform:

fan1_alarm:0pwm2_auto_point1_temp:25000
fan1_beep:0 pwm2_auto_point2_pwm:170
fan1_input:15   pwm2_auto_point2_temp:35000
fan1_min:0  pwm2_auto_point3_pwm:200
fan2_alarm:0pwm2_auto_point3_temp:45000
fan2_beep:0 pwm2_auto_point4_pwm:230
fan2_input:0pwm2_auto_point4_temp:55000
fan2_min:0  pwm2_auto_point5_pwm:255
fan3_alarm:0pwm2_auto_point5_temp:6
fan3_beep:0 pwm2_enable:1
fan3_input:0pwm2_mode:1
fan3_min:0  pwm3:127
in0_alarm:0 pwm3_auto_point1_pwm:140
in0_beep:0  pwm3_auto_point1_temp:25000
in0_input:3312  pwm3_auto_point2_pwm:170
in0_max:4092pwm3_auto_point2_temp:35000
in0_min:0   pwm3_auto_point3_pwm:200
in1_input:902   pwm3_auto_point3_temp:45000
in3_alarm:0 pwm3_auto_point4_pwm:230
in3_beep:0  pwm3_auto_point4_temp:55000
in3_input:1808  pwm3_auto_point5_pwm:255
in3_max:2046pwm3_auto_point5_temp:6
in3_min:0   pwm3_enable:1
in4_alarm:0 pwm3_mode:1
in4_beep:0  temp1_beep:0
in4_input:1508  temp1_crit:10
in4_max:2046temp1_crit_alarm:0
in4_min:0   temp1_fault:0
name:nct7802temp1_input:35500
pwm1:127temp1_max:85000
pwm1_auto_point1_pwm:140temp1_max_alarm:0
pwm1_auto_point1_temp:25000 temp1_min:0
pwm1_auto_point2_pwm:170temp1_min_alarm:0
pwm1_auto_point2_temp:35000 temp1_type:4
pwm1_auto_point3_pwm:200temp4_beep:0
pwm1_auto_point3_temp:45000 temp4_crit:10
pwm1_auto_point4_pwm:230temp4_crit_alarm:0
pwm1_auto_point4_temp:55000 temp4_input:39000
pwm1_auto_point5_pwm:255temp4_max:85000
pwm1_auto_point5_temp:6 temp4_max_alarm:0
pwm1_enable:1   temp4_min:0
pwm1_mode:1 temp4_min_alarm:0
pwm2:127temp6_beep:0
pwm2_auto_point1_pwm:140temp6_input:0

---
 Documentation/hwmon/nct7802 |   5 +-
 drivers/hwmon/nct7802.c | 130 ++--
 2 files changed, 128 insertions(+), 7 deletions(-)

diff --git a/Documentation/hwmon/nct7802 b/Documentation/hwmon/nct7802
index 2e00f5e..c5c25a5 100644
--- a/Documentation/hwmon/nct7802
+++ b/Documentation/hwmon/nct7802
@@ -5,7 +5,7 @@ Supported chips:
   * Nuvoton NCT7802Y
 Prefix: 'nct7802'
 Addresses scanned: I2C 0x28..0x2f
-Datasheet: Available from Nuvoton web site
+Datasheet: 
http://www.nuvoton.com/hq/products/cloud-computing/hardware-monitors/desktop-server-series/nct7802y/
 
 Authors:
 Guenter Roeck 
@@ -17,8 +17,7 @@ This driver implements support for the Nuvoton NCT7802Y 
hardware monitoring
 chip. NCT7802Y supports 6 temperature sensors, 5 voltage sensors, and 3 fan
 speed sensors.
 
-The chip also supports intelligent fan speed control. This functionality is
-not currently supported by the driver.
+Smart Fan™ speed control is avilabel via pwmX_auto_temp attributes.
 
 Tested Boards and BIOS Versions
 ---
diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index d018571..c1898ba 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -53,6 +53,7 @@ static const u8 REG_VOLTAGE_LIMIT_MSB_SHIFT[2][5] = {
 #define REG_PECI_ENABLE0x23
 #define REG_FAN_ENABLE 0x24
 #define REG_VMON_ENABLE0x25
+#define REG_PWM(x) (0x60 + (x))
 #define REG_SMARTFAN_EN(x)  (0x64 + (x) / 2)
 #define SMARTFAN_EN_SHIFT(x)((x) % 2 * 4)
 #define REG_VENDOR_ID  0xfd
@@ -130,6 +131,9 @@ static ssize_t show_pwm(struct device *dev, struct 
device_attribute *devattr,
unsigned int val;
int ret;
 
+   if (!attr->index)
+   return sprintf(

[PATCH v3] hwmon: (nct7802) Add autopoint attributes

2015-07-25 Thread Constantine Shulyupin
Introduced REG_PWM, pwm[1..3]_auto_point[1..5]_temp,
pwm[1..3]_auto_point[1..5]_pwm, nct7802_auto_point_attrs,
nct7802_auto_point_group, updated nct7802_regmap_is_volatile

---

Changed in v3:
- removed nct7802_auto_point_is_visible
- removed usage of sysfs_update_group
- introduced REG_PWM
- removed S_IWUSR from RO attributes
- added PWM registers to nct7802_regmap_is_volatile
Changed in v2:
- removed PWM_REG, TEMP_REG
- removed auto_point[1..4]_temp, auto_point[1..4]_pwm
  and auto_point_crit_temp
- introduced pwm[1..3]_auto_point[1..5]_temp
  and pwm[1..3]_auto_point[1..5]_pwm.
- introduced nct7802_auto_point_is_visible
- used sysfs_update_group in store_pwm_enable

Notes:
I think that better to leave function nct7802_auto_point_is_visible.
Autopoints attributes have default values and enabling autopoint doesn't
confuse the chip. The chip accepts changing autopoint (SmartFan)
registers after enabling autopoint mode.

I'll think about validating auto point settings latter.
The next fix I would like is to add OF support, which is more important.

BTW, Guenter, have you TODO list for the driver?

Signed-off-by: Constantine Shulyupin 
---
 drivers/hwmon/nct7802.c | 130 ++--
 1 file changed, 126 insertions(+), 4 deletions(-)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index f4908bb..c8a6eda 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -53,6 +53,7 @@ static const u8 REG_VOLTAGE_LIMIT_MSB_SHIFT[2][5] = {
 #define REG_PECI_ENABLE0x23
 #define REG_FAN_ENABLE 0x24
 #define REG_VMON_ENABLE0x25
+#define REG_PWM(x) (0x60 + (x))
 #define REG_SMARTFAN_EN(x)  (0x64 + (x) / 2)
 #define SMARTFAN_EN_SHIFT(x)((x) % 2 * 4)
 #define REG_VENDOR_ID  0xfd
@@ -130,6 +131,9 @@ static ssize_t show_pwm(struct device *dev, struct 
device_attribute *devattr,
unsigned int val;
int ret;
 
+   if (!attr->index)
+   return sprintf(buf, "255\n");
+
ret = regmap_read(data->regmap, attr->index, );
if (ret < 0)
return ret;
@@ -826,9 +830,12 @@ static SENSOR_DEVICE_ATTR(pwm2_mode, S_IRUGO, 
show_pwm_mode, NULL, 1);
 static SENSOR_DEVICE_ATTR(pwm3_mode, S_IRUGO, show_pwm_mode, NULL, 2);
 
 /* 7.2.91... Fan Control Output Value */
-static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x60);
-static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x61);
-static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x62);
+static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_pwm,
+ REG_PWM(0));
+static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm,
+ REG_PWM(1));
+static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_pwm,
+ REG_PWM(2));
 
 /* 7.2.95... Temperature to Fan mapping Relationships Register */
 static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
@@ -893,11 +900,125 @@ static struct attribute_group nct7802_pwm_group = {
.attrs = nct7802_pwm_attrs,
 };
 
+/* 7.2.115... 0x80-0x83, 0x84 Temperature (X-axis) transition */
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x80, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x81, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x82, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x83, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point5_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x84, 0);
+
+/* 7.2.120... 0x85-0x88 PWM (Y-axis) transition */
+static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x85);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x86);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point3_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x87);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point4_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x88);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point5_pwm, S_IRUGO, show_pwm, NULL, 0);
+
+/* 7.2.124 Table 2 X-axis Transition Point 1 Register */
+static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x90, 0);
+static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x91, 0);
+static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_t

[PATCH v4] hwmon: (nct7802) Add autopoint attributes

2015-07-25 Thread Constantine Shulyupin
Introduced REG_PWM, pwm[1..3]_auto_point[1..5]_temp,
pwm[1..3]_auto_point[1..5]_pwm, nct7802_auto_point_attrs,
nct7802_auto_point_group, updated nct7802_regmap_is_volatile

Signed-off-by: Constantine Shulyupin co...@makelinux.com
---

Changed in v4:
- fixed expression in nct7802_regmap_is_volatile
- added pwmX_auto_temp to driver's documentation
Changed in v3:
- removed nct7802_auto_point_is_visible
- removed usage of sysfs_update_group
- introduced REG_PWM
- removed S_IWUSR from RO attributes
- added PWM registers to nct7802_regmap_is_volatile
Changed in v2:
- removed PWM_REG, TEMP_REG
- removed auto_point[1..4]_temp, auto_point[1..4]_pwm
  and auto_point_crit_temp
- introduced pwm[1..3]_auto_point[1..5]_temp
  and pwm[1..3]_auto_point[1..5]_pwm.
- introduced nct7802_auto_point_is_visible
- used sysfs_update_group in store_pwm_enable

Default values on my platform:

fan1_alarm:0pwm2_auto_point1_temp:25000
fan1_beep:0 pwm2_auto_point2_pwm:170
fan1_input:15   pwm2_auto_point2_temp:35000
fan1_min:0  pwm2_auto_point3_pwm:200
fan2_alarm:0pwm2_auto_point3_temp:45000
fan2_beep:0 pwm2_auto_point4_pwm:230
fan2_input:0pwm2_auto_point4_temp:55000
fan2_min:0  pwm2_auto_point5_pwm:255
fan3_alarm:0pwm2_auto_point5_temp:6
fan3_beep:0 pwm2_enable:1
fan3_input:0pwm2_mode:1
fan3_min:0  pwm3:127
in0_alarm:0 pwm3_auto_point1_pwm:140
in0_beep:0  pwm3_auto_point1_temp:25000
in0_input:3312  pwm3_auto_point2_pwm:170
in0_max:4092pwm3_auto_point2_temp:35000
in0_min:0   pwm3_auto_point3_pwm:200
in1_input:902   pwm3_auto_point3_temp:45000
in3_alarm:0 pwm3_auto_point4_pwm:230
in3_beep:0  pwm3_auto_point4_temp:55000
in3_input:1808  pwm3_auto_point5_pwm:255
in3_max:2046pwm3_auto_point5_temp:6
in3_min:0   pwm3_enable:1
in4_alarm:0 pwm3_mode:1
in4_beep:0  temp1_beep:0
in4_input:1508  temp1_crit:10
in4_max:2046temp1_crit_alarm:0
in4_min:0   temp1_fault:0
name:nct7802temp1_input:35500
pwm1:127temp1_max:85000
pwm1_auto_point1_pwm:140temp1_max_alarm:0
pwm1_auto_point1_temp:25000 temp1_min:0
pwm1_auto_point2_pwm:170temp1_min_alarm:0
pwm1_auto_point2_temp:35000 temp1_type:4
pwm1_auto_point3_pwm:200temp4_beep:0
pwm1_auto_point3_temp:45000 temp4_crit:10
pwm1_auto_point4_pwm:230temp4_crit_alarm:0
pwm1_auto_point4_temp:55000 temp4_input:39000
pwm1_auto_point5_pwm:255temp4_max:85000
pwm1_auto_point5_temp:6 temp4_max_alarm:0
pwm1_enable:1   temp4_min:0
pwm1_mode:1 temp4_min_alarm:0
pwm2:127temp6_beep:0
pwm2_auto_point1_pwm:140temp6_input:0

---
 Documentation/hwmon/nct7802 |   5 +-
 drivers/hwmon/nct7802.c | 130 ++--
 2 files changed, 128 insertions(+), 7 deletions(-)

diff --git a/Documentation/hwmon/nct7802 b/Documentation/hwmon/nct7802
index 2e00f5e..c5c25a5 100644
--- a/Documentation/hwmon/nct7802
+++ b/Documentation/hwmon/nct7802
@@ -5,7 +5,7 @@ Supported chips:
   * Nuvoton NCT7802Y
 Prefix: 'nct7802'
 Addresses scanned: I2C 0x28..0x2f
-Datasheet: Available from Nuvoton web site
+Datasheet: 
http://www.nuvoton.com/hq/products/cloud-computing/hardware-monitors/desktop-server-series/nct7802y/
 
 Authors:
 Guenter Roeck li...@roeck-us.net
@@ -17,8 +17,7 @@ This driver implements support for the Nuvoton NCT7802Y 
hardware monitoring
 chip. NCT7802Y supports 6 temperature sensors, 5 voltage sensors, and 3 fan
 speed sensors.
 
-The chip also supports intelligent fan speed control. This functionality is
-not currently supported by the driver.
+Smart Fan™ speed control is avilabel via pwmX_auto_temp attributes.
 
 Tested Boards and BIOS Versions
 ---
diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index d018571..c1898ba 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -53,6 +53,7 @@ static const u8 REG_VOLTAGE_LIMIT_MSB_SHIFT[2][5] = {
 #define REG_PECI_ENABLE0x23
 #define REG_FAN_ENABLE 0x24
 #define REG_VMON_ENABLE0x25
+#define REG_PWM(x) (0x60 + (x))
 #define REG_SMARTFAN_EN(x)  (0x64 + (x) / 2)
 #define SMARTFAN_EN_SHIFT(x)((x) % 2 * 4)
 #define REG_VENDOR_ID  0xfd
@@ -130,6 +131,9 @@ static ssize_t show_pwm(struct device *dev, struct 
device_attribute *devattr,
unsigned int val;
int ret;
 
+   if (!attr-index

[PATCH v3] hwmon: (nct7802) Add autopoint attributes

2015-07-25 Thread Constantine Shulyupin
Introduced REG_PWM, pwm[1..3]_auto_point[1..5]_temp,
pwm[1..3]_auto_point[1..5]_pwm, nct7802_auto_point_attrs,
nct7802_auto_point_group, updated nct7802_regmap_is_volatile

---

Changed in v3:
- removed nct7802_auto_point_is_visible
- removed usage of sysfs_update_group
- introduced REG_PWM
- removed S_IWUSR from RO attributes
- added PWM registers to nct7802_regmap_is_volatile
Changed in v2:
- removed PWM_REG, TEMP_REG
- removed auto_point[1..4]_temp, auto_point[1..4]_pwm
  and auto_point_crit_temp
- introduced pwm[1..3]_auto_point[1..5]_temp
  and pwm[1..3]_auto_point[1..5]_pwm.
- introduced nct7802_auto_point_is_visible
- used sysfs_update_group in store_pwm_enable

Notes:
I think that better to leave function nct7802_auto_point_is_visible.
Autopoints attributes have default values and enabling autopoint doesn't
confuse the chip. The chip accepts changing autopoint (SmartFan)
registers after enabling autopoint mode.

I'll think about validating auto point settings latter.
The next fix I would like is to add OF support, which is more important.

BTW, Guenter, have you TODO list for the driver?

Signed-off-by: Constantine Shulyupin co...@makelinux.com
---
 drivers/hwmon/nct7802.c | 130 ++--
 1 file changed, 126 insertions(+), 4 deletions(-)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index f4908bb..c8a6eda 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -53,6 +53,7 @@ static const u8 REG_VOLTAGE_LIMIT_MSB_SHIFT[2][5] = {
 #define REG_PECI_ENABLE0x23
 #define REG_FAN_ENABLE 0x24
 #define REG_VMON_ENABLE0x25
+#define REG_PWM(x) (0x60 + (x))
 #define REG_SMARTFAN_EN(x)  (0x64 + (x) / 2)
 #define SMARTFAN_EN_SHIFT(x)((x) % 2 * 4)
 #define REG_VENDOR_ID  0xfd
@@ -130,6 +131,9 @@ static ssize_t show_pwm(struct device *dev, struct 
device_attribute *devattr,
unsigned int val;
int ret;
 
+   if (!attr-index)
+   return sprintf(buf, 255\n);
+
ret = regmap_read(data-regmap, attr-index, val);
if (ret  0)
return ret;
@@ -826,9 +830,12 @@ static SENSOR_DEVICE_ATTR(pwm2_mode, S_IRUGO, 
show_pwm_mode, NULL, 1);
 static SENSOR_DEVICE_ATTR(pwm3_mode, S_IRUGO, show_pwm_mode, NULL, 2);
 
 /* 7.2.91... Fan Control Output Value */
-static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x60);
-static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x61);
-static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x62);
+static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_pwm,
+ REG_PWM(0));
+static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm,
+ REG_PWM(1));
+static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_pwm,
+ REG_PWM(2));
 
 /* 7.2.95... Temperature to Fan mapping Relationships Register */
 static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
@@ -893,11 +900,125 @@ static struct attribute_group nct7802_pwm_group = {
.attrs = nct7802_pwm_attrs,
 };
 
+/* 7.2.115... 0x80-0x83, 0x84 Temperature (X-axis) transition */
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x80, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x81, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x82, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x83, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point5_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x84, 0);
+
+/* 7.2.120... 0x85-0x88 PWM (Y-axis) transition */
+static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x85);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x86);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point3_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x87);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point4_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x88);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point5_pwm, S_IRUGO, show_pwm, NULL, 0);
+
+/* 7.2.124 Table 2 X-axis Transition Point 1 Register */
+static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x90, 0);
+static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x91, 0);
+static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp

[PATCH v2] hwmon: (nct7802) Add autopoint attributes

2015-07-15 Thread Constantine Shulyupin
Introduced pwm[1..3]_auto_point[1..5]_temp, pwm[1..3]_auto_point[1..5]_pwm,
nct7802_auto_point_attrs, nct7802_auto_point_group.
nct7802_auto_point_is_visible,

---

Changed in v2:
- removed PWM_REG, TEMP_REG
- removed auto_point[1..4]_temp, auto_point[1..4]_pwm
  and auto_point_crit_temp
- introduced pwm[1..3]_auto_point[1..5]_temp
  and pwm[1..3]_auto_point[1..5]_pwm.
- introduced nct7802_auto_point_is_visible
- used sysfs_update_group in store_pwm_enable

Signed-off-by: Constantine Shulyupin 
---
 drivers/hwmon/nct7802.c | 179 +++-
 1 file changed, 162 insertions(+), 17 deletions(-)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index b8ca21b..32d06b7 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -130,6 +130,9 @@ static ssize_t show_pwm(struct device *dev, struct 
device_attribute *devattr,
unsigned int val;
int ret;
 
+   if (!attr->index)
+   return sprintf(buf, "255\n");
+
ret = regmap_read(data->regmap, attr->index, );
if (ret < 0)
return ret;
@@ -170,23 +173,7 @@ static ssize_t show_pwm_enable(struct device *dev,
 
 static ssize_t store_pwm_enable(struct device *dev,
struct device_attribute *attr,
-   const char *buf, size_t count)
-{
-   struct nct7802_data *data = dev_get_drvdata(dev);
-   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
-   u8 val;
-   int ret;
-
-   ret = kstrtou8(buf, 0, );
-   if (ret < 0)
-   return ret;
-   if (val < 1 || val > 2)
-   return -EINVAL;
-   ret = regmap_update_bits(data->regmap, REG_SMARTFAN_EN(sattr->index),
-1 << SMARTFAN_EN_SHIFT(sattr->index),
-(val - 1) << SMARTFAN_EN_SHIFT(sattr->index));
-   return ret ? : count;
-}
+   const char *buf, size_t count);
 
 static int nct7802_read_temp(struct nct7802_data *data,
 u8 reg_temp, u8 reg_temp_low, int *temp)
@@ -893,11 +880,169 @@ static struct attribute_group nct7802_pwm_group = {
.attrs = nct7802_pwm_attrs,
 };
 
+/* 7.2.115... 0x80-0x83, 0x84 Temperature (X-axis) transition */
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x80, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x81, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x82, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x83, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point5_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x84, 0);
+
+/* 7.2.120... 0x85-0x88 PWM (Y-axis) transition */
+static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x85);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x86);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point3_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x87);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point4_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x88);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point5_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, NULL, 0);
+
+/* 7.2.124 Table 2 X-axis Transition Point 1 Register */
+static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x90, 0);
+static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x91, 0);
+static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x92, 0);
+static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x93, 0);
+static SENSOR_DEVICE_ATTR_2(pwm2_auto_point5_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x94, 0);
+
+/* 7.2.129 Table 2 Y-axis Transition Point 1 Register */
+static SENSOR_DEVICE_ATTR(pwm2_auto_point1_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x95);
+static SENSOR_DEVICE_ATTR(pwm2_auto_point2_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x96);
+static SENSOR_DEVICE_ATTR(pwm2_auto_point3_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x97);
+static SENSOR_DEVICE_ATTR(pwm2_auto_point4_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x98);
+static SEN

[PATCH v2] hwmon: (nct7802) Add autopoint attributes

2015-07-15 Thread Constantine Shulyupin
Introduced pwm[1..3]_auto_point[1..5]_temp, pwm[1..3]_auto_point[1..5]_pwm,
nct7802_auto_point_attrs, nct7802_auto_point_group.
nct7802_auto_point_is_visible,

---

Changed in v2:
- removed PWM_REG, TEMP_REG
- removed auto_point[1..4]_temp, auto_point[1..4]_pwm
  and auto_point_crit_temp
- introduced pwm[1..3]_auto_point[1..5]_temp
  and pwm[1..3]_auto_point[1..5]_pwm.
- introduced nct7802_auto_point_is_visible
- used sysfs_update_group in store_pwm_enable

Signed-off-by: Constantine Shulyupin co...@makelinux.com
---
 drivers/hwmon/nct7802.c | 179 +++-
 1 file changed, 162 insertions(+), 17 deletions(-)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index b8ca21b..32d06b7 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -130,6 +130,9 @@ static ssize_t show_pwm(struct device *dev, struct 
device_attribute *devattr,
unsigned int val;
int ret;
 
+   if (!attr-index)
+   return sprintf(buf, 255\n);
+
ret = regmap_read(data-regmap, attr-index, val);
if (ret  0)
return ret;
@@ -170,23 +173,7 @@ static ssize_t show_pwm_enable(struct device *dev,
 
 static ssize_t store_pwm_enable(struct device *dev,
struct device_attribute *attr,
-   const char *buf, size_t count)
-{
-   struct nct7802_data *data = dev_get_drvdata(dev);
-   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
-   u8 val;
-   int ret;
-
-   ret = kstrtou8(buf, 0, val);
-   if (ret  0)
-   return ret;
-   if (val  1 || val  2)
-   return -EINVAL;
-   ret = regmap_update_bits(data-regmap, REG_SMARTFAN_EN(sattr-index),
-1  SMARTFAN_EN_SHIFT(sattr-index),
-(val - 1)  SMARTFAN_EN_SHIFT(sattr-index));
-   return ret ? : count;
-}
+   const char *buf, size_t count);
 
 static int nct7802_read_temp(struct nct7802_data *data,
 u8 reg_temp, u8 reg_temp_low, int *temp)
@@ -893,11 +880,169 @@ static struct attribute_group nct7802_pwm_group = {
.attrs = nct7802_pwm_attrs,
 };
 
+/* 7.2.115... 0x80-0x83, 0x84 Temperature (X-axis) transition */
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x80, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x81, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x82, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x83, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point5_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x84, 0);
+
+/* 7.2.120... 0x85-0x88 PWM (Y-axis) transition */
+static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x85);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x86);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point3_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x87);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point4_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x88);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point5_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, NULL, 0);
+
+/* 7.2.124 Table 2 X-axis Transition Point 1 Register */
+static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x90, 0);
+static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x91, 0);
+static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x92, 0);
+static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x93, 0);
+static SENSOR_DEVICE_ATTR_2(pwm2_auto_point5_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x94, 0);
+
+/* 7.2.129 Table 2 Y-axis Transition Point 1 Register */
+static SENSOR_DEVICE_ATTR(pwm2_auto_point1_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x95);
+static SENSOR_DEVICE_ATTR(pwm2_auto_point2_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x96);
+static SENSOR_DEVICE_ATTR(pwm2_auto_point3_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x97);
+static SENSOR_DEVICE_ATTR(pwm2_auto_point4_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x98);
+static SENSOR_DEVICE_ATTR(pwm2_auto_point5_pwm, S_IRUGO | S_IWUSR

[PATCH] hwmon: (nct7802) Add autopoint attributes

2015-07-11 Thread Constantine Shulyupin
Introduced pwm[1..3]_auto_point[1..5]_temp, pwm[1..3]_auto_point[1..5]_pwm,
nct7802_auto_point_attrs, nct7802_auto_point_group.
nct7802_auto_point_is_visible,

---

Changed in v2:
- Removed PWM_REG, TEMP_REG
- auto_point[1..4]_temp, auto_point[1..4]_pwm and auto_point_crit_temp
expanded and replaced with pwm[1..3]_auto_point[1..5]_temp
and pwm[1..3]_auto_point[1..5]_pwm.
- Introduced nct7802_auto_point_is_visible
- added used sysfs_update_group in store_pwm_enable

Signed-off-by: Constantine Shulyupin 
---
 drivers/hwmon/nct7802.c | 179 +++-
 1 file changed, 162 insertions(+), 17 deletions(-)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index 2f6bbe5..e1bc7a6 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -130,6 +130,9 @@ static ssize_t show_pwm(struct device *dev, struct 
device_attribute *devattr,
unsigned int val;
int ret;
 
+   if (!attr->index)
+   return sprintf(buf, "255\n");
+
ret = regmap_read(data->regmap, attr->index, );
if (ret < 0)
return ret;
@@ -170,23 +173,7 @@ static ssize_t show_pwm_enable(struct device *dev,
 
 static ssize_t store_pwm_enable(struct device *dev,
struct device_attribute *attr,
-   const char *buf, size_t count)
-{
-   struct nct7802_data *data = dev_get_drvdata(dev);
-   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
-   u8 val;
-   int ret;
-
-   ret = kstrtou8(buf, 0, );
-   if (ret < 0)
-   return ret;
-   if (val < 1 || val > 2)
-   return -EINVAL;
-   ret = regmap_update_bits(data->regmap, REG_SMARTFAN_EN(sattr->index),
-1 << SMARTFAN_EN_SHIFT(sattr->index),
-(val - 1) << SMARTFAN_EN_SHIFT(sattr->index));
-   return ret ? : count;
-}
+   const char *buf, size_t count);
 
 static int nct7802_read_temp(struct nct7802_data *data,
 u8 reg_temp, u8 reg_temp_low, int *temp)
@@ -890,11 +877,169 @@ static struct attribute_group nct7802_pwm_group = {
.attrs = nct7802_pwm_attrs,
 };
 
+/* 7.2.115... 0x80-0x83, 0x84 Temperature (X-axis) transition */
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x80, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x81, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x82, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x83, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point5_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x84, 0);
+
+/* 7.2.120... 0x85-0x88 PWM (Y-axis) transition */
+static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x85);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x86);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point3_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x87);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point4_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x88);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point5_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, NULL, 0);
+
+/* 7.2.124 Table 2 X-axis Transition Point 1 Register */
+static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x90, 0);
+static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x91, 0);
+static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x92, 0);
+static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x93, 0);
+static SENSOR_DEVICE_ATTR_2(pwm2_auto_point5_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x94, 0);
+
+/* 7.2.129 Table 2 Y-axis Transition Point 1 Register */
+static SENSOR_DEVICE_ATTR(pwm2_auto_point1_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x95);
+static SENSOR_DEVICE_ATTR(pwm2_auto_point2_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x96);
+static SENSOR_DEVICE_ATTR(pwm2_auto_point3_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x97);
+static SENSOR_DEVICE_ATTR(pwm2_auto_point4_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x98);
+static SEN

[PATCH] hwmon: (nct7802) Add autopoint attributes

2015-07-11 Thread Constantine Shulyupin
Introduced pwm[1..3]_auto_point[1..5]_temp, pwm[1..3]_auto_point[1..5]_pwm,
nct7802_auto_point_attrs, nct7802_auto_point_group.
nct7802_auto_point_is_visible,

---

Changed in v2:
- Removed PWM_REG, TEMP_REG
- auto_point[1..4]_temp, auto_point[1..4]_pwm and auto_point_crit_temp
expanded and replaced with pwm[1..3]_auto_point[1..5]_temp
and pwm[1..3]_auto_point[1..5]_pwm.
- Introduced nct7802_auto_point_is_visible
- added used sysfs_update_group in store_pwm_enable

Signed-off-by: Constantine Shulyupin co...@makelinux.com
---
 drivers/hwmon/nct7802.c | 179 +++-
 1 file changed, 162 insertions(+), 17 deletions(-)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index 2f6bbe5..e1bc7a6 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -130,6 +130,9 @@ static ssize_t show_pwm(struct device *dev, struct 
device_attribute *devattr,
unsigned int val;
int ret;
 
+   if (!attr-index)
+   return sprintf(buf, 255\n);
+
ret = regmap_read(data-regmap, attr-index, val);
if (ret  0)
return ret;
@@ -170,23 +173,7 @@ static ssize_t show_pwm_enable(struct device *dev,
 
 static ssize_t store_pwm_enable(struct device *dev,
struct device_attribute *attr,
-   const char *buf, size_t count)
-{
-   struct nct7802_data *data = dev_get_drvdata(dev);
-   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
-   u8 val;
-   int ret;
-
-   ret = kstrtou8(buf, 0, val);
-   if (ret  0)
-   return ret;
-   if (val  1 || val  2)
-   return -EINVAL;
-   ret = regmap_update_bits(data-regmap, REG_SMARTFAN_EN(sattr-index),
-1  SMARTFAN_EN_SHIFT(sattr-index),
-(val - 1)  SMARTFAN_EN_SHIFT(sattr-index));
-   return ret ? : count;
-}
+   const char *buf, size_t count);
 
 static int nct7802_read_temp(struct nct7802_data *data,
 u8 reg_temp, u8 reg_temp_low, int *temp)
@@ -890,11 +877,169 @@ static struct attribute_group nct7802_pwm_group = {
.attrs = nct7802_pwm_attrs,
 };
 
+/* 7.2.115... 0x80-0x83, 0x84 Temperature (X-axis) transition */
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x80, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x81, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x82, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x83, 0);
+static SENSOR_DEVICE_ATTR_2(pwm1_auto_point5_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x84, 0);
+
+/* 7.2.120... 0x85-0x88 PWM (Y-axis) transition */
+static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x85);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x86);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point3_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x87);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point4_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x88);
+static SENSOR_DEVICE_ATTR(pwm1_auto_point5_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, NULL, 0);
+
+/* 7.2.124 Table 2 X-axis Transition Point 1 Register */
+static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x90, 0);
+static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x91, 0);
+static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x92, 0);
+static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x93, 0);
+static SENSOR_DEVICE_ATTR_2(pwm2_auto_point5_temp, S_IRUGO | S_IWUSR,
+   show_temp, store_temp, 0x94, 0);
+
+/* 7.2.129 Table 2 Y-axis Transition Point 1 Register */
+static SENSOR_DEVICE_ATTR(pwm2_auto_point1_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x95);
+static SENSOR_DEVICE_ATTR(pwm2_auto_point2_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x96);
+static SENSOR_DEVICE_ATTR(pwm2_auto_point3_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x97);
+static SENSOR_DEVICE_ATTR(pwm2_auto_point4_pwm, S_IRUGO | S_IWUSR,
+ show_pwm, store_pwm, 0x98);
+static SENSOR_DEVICE_ATTR(pwm2_auto_point5_pwm, S_IRUGO | S_IWUSR

[PATCH] hwmon: (nct7802) Add autopoint attributes

2015-07-08 Thread Constantine Shulyupin
Introduced PWM_REG, TEMP_REG, auto_pointX_temp, auto_pointX_pwm,
nct7802_auto_point_attrs, nct7802_auto_point_group.

Signed-off-by: Constantine Shulyupin 
---
 drivers/hwmon/nct7802.c | 41 +
 1 file changed, 41 insertions(+)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index 2f6bbe5..a3f3063 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -153,6 +153,10 @@ static ssize_t store_pwm(struct device *dev, struct 
device_attribute *devattr,
return err ? : count;
 }
 
+#define PWM_REG(_name, _reg) \
+   SENSOR_DEVICE_ATTR(_name, S_IRUGO | S_IWUSR, \
+ show_pwm, store_pwm, _reg)
+
 static ssize_t show_pwm_enable(struct device *dev,
   struct device_attribute *attr, char *buf)
 {
@@ -404,6 +408,10 @@ static ssize_t store_temp(struct device *dev, struct 
device_attribute *attr,
return err ? : count;
 }
 
+#define TEMP_REG(_name, _high, _low) \
+   SENSOR_DEVICE_ATTR_2(_name, S_IRUGO | S_IWUSR, \
+   show_temp, store_temp, _high, _low)
+
 static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
char *buf)
 {
@@ -890,11 +898,44 @@ static struct attribute_group nct7802_pwm_group = {
.attrs = nct7802_pwm_attrs,
 };
 
+/* 7.2.115... 0x80-0x83, 0x84 Temperature (X-axis) transition */
+static TEMP_REG(auto_point1_temp, 0x80, 0);
+static TEMP_REG(auto_point2_temp, 0x81, 0);
+static TEMP_REG(auto_point3_temp, 0x82, 0);
+static TEMP_REG(auto_point4_temp, 0x83, 0);
+static TEMP_REG(auto_point_crit_temp, 0x84, 0);
+
+/* 7.2.120... 0x85-0x88 PWM (Y-axis) transition */
+static PWM_REG(auto_point1_pwm, 0x85);
+static PWM_REG(auto_point2_pwm, 0x86);
+static PWM_REG(auto_point3_pwm, 0x87);
+static PWM_REG(auto_point4_pwm, 0x88);
+
+static struct attribute *nct7802_auto_point_attrs[] = {
+   _dev_attr_auto_point1_temp.dev_attr.attr,
+   _dev_attr_auto_point2_temp.dev_attr.attr,
+   _dev_attr_auto_point3_temp.dev_attr.attr,
+   _dev_attr_auto_point4_temp.dev_attr.attr,
+   _dev_attr_auto_point_crit_temp.dev_attr.attr,
+
+   _dev_attr_auto_point1_pwm.dev_attr.attr,
+   _dev_attr_auto_point2_pwm.dev_attr.attr,
+   _dev_attr_auto_point3_pwm.dev_attr.attr,
+   _dev_attr_auto_point4_pwm.dev_attr.attr,
+
+   NULL
+};
+
+static struct attribute_group nct7802_auto_point_group = {
+   .attrs = nct7802_auto_point_attrs,
+};
+
 static const struct attribute_group *nct7802_groups[] = {
_temp_group,
_in_group,
_fan_group,
_pwm_group,
+   _auto_point_group,
NULL
 };
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] hwmon: (nct7802) Add autopoint attributes

2015-07-08 Thread Constantine Shulyupin
Introduced PWM_REG, TEMP_REG, auto_pointX_temp, auto_pointX_pwm,
nct7802_auto_point_attrs, nct7802_auto_point_group.

Signed-off-by: Constantine Shulyupin co...@makelinux.com
---
 drivers/hwmon/nct7802.c | 41 +
 1 file changed, 41 insertions(+)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index 2f6bbe5..a3f3063 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -153,6 +153,10 @@ static ssize_t store_pwm(struct device *dev, struct 
device_attribute *devattr,
return err ? : count;
 }
 
+#define PWM_REG(_name, _reg) \
+   SENSOR_DEVICE_ATTR(_name, S_IRUGO | S_IWUSR, \
+ show_pwm, store_pwm, _reg)
+
 static ssize_t show_pwm_enable(struct device *dev,
   struct device_attribute *attr, char *buf)
 {
@@ -404,6 +408,10 @@ static ssize_t store_temp(struct device *dev, struct 
device_attribute *attr,
return err ? : count;
 }
 
+#define TEMP_REG(_name, _high, _low) \
+   SENSOR_DEVICE_ATTR_2(_name, S_IRUGO | S_IWUSR, \
+   show_temp, store_temp, _high, _low)
+
 static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
char *buf)
 {
@@ -890,11 +898,44 @@ static struct attribute_group nct7802_pwm_group = {
.attrs = nct7802_pwm_attrs,
 };
 
+/* 7.2.115... 0x80-0x83, 0x84 Temperature (X-axis) transition */
+static TEMP_REG(auto_point1_temp, 0x80, 0);
+static TEMP_REG(auto_point2_temp, 0x81, 0);
+static TEMP_REG(auto_point3_temp, 0x82, 0);
+static TEMP_REG(auto_point4_temp, 0x83, 0);
+static TEMP_REG(auto_point_crit_temp, 0x84, 0);
+
+/* 7.2.120... 0x85-0x88 PWM (Y-axis) transition */
+static PWM_REG(auto_point1_pwm, 0x85);
+static PWM_REG(auto_point2_pwm, 0x86);
+static PWM_REG(auto_point3_pwm, 0x87);
+static PWM_REG(auto_point4_pwm, 0x88);
+
+static struct attribute *nct7802_auto_point_attrs[] = {
+   sensor_dev_attr_auto_point1_temp.dev_attr.attr,
+   sensor_dev_attr_auto_point2_temp.dev_attr.attr,
+   sensor_dev_attr_auto_point3_temp.dev_attr.attr,
+   sensor_dev_attr_auto_point4_temp.dev_attr.attr,
+   sensor_dev_attr_auto_point_crit_temp.dev_attr.attr,
+
+   sensor_dev_attr_auto_point1_pwm.dev_attr.attr,
+   sensor_dev_attr_auto_point2_pwm.dev_attr.attr,
+   sensor_dev_attr_auto_point3_pwm.dev_attr.attr,
+   sensor_dev_attr_auto_point4_pwm.dev_attr.attr,
+
+   NULL
+};
+
+static struct attribute_group nct7802_auto_point_group = {
+   .attrs = nct7802_auto_point_attrs,
+};
+
 static const struct attribute_group *nct7802_groups[] = {
nct7802_temp_group,
nct7802_in_group,
nct7802_fan_group,
nct7802_pwm_group,
+   nct7802_auto_point_group,
NULL
 };
 
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2] hwmon: (nct7802) Add pwmX_enable attribute

2015-07-07 Thread Constantine Shulyupin
Introduced REG_SMARTFAN_EN, SMARTFAN_EN_SHIFT, pwmX_enable,
show_pwm_enable, store_pwm_enable.

Signed-off-by: Constantine Shulyupin 

---
Change log:
Fixed in v2:
- Introduced REG_SMARTFAN_EN, SMARTFAN_EN_SHIFT

Signed-off-by: Constantine Shulyupin 
---
 drivers/hwmon/nct7802.c | 45 +
 1 file changed, 45 insertions(+)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index a0d9010..2f6bbe5 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -53,6 +53,8 @@ static const u8 REG_VOLTAGE_LIMIT_MSB_SHIFT[2][5] = {
 #define REG_PECI_ENABLE0x23
 #define REG_FAN_ENABLE 0x24
 #define REG_VMON_ENABLE0x25
+#define REG_SMARTFAN_EN(x)  (0x64 + (x) / 2)
+#define SMARTFAN_EN_SHIFT(x)((x) % 2 * 4)
 #define REG_VENDOR_ID  0xfd
 #define REG_CHIP_ID0xfe
 #define REG_VERSION_ID 0xff
@@ -151,6 +153,41 @@ static ssize_t store_pwm(struct device *dev, struct 
device_attribute *devattr,
return err ? : count;
 }
 
+static ssize_t show_pwm_enable(struct device *dev,
+  struct device_attribute *attr, char *buf)
+{
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+   unsigned int reg, enabled;
+   int ret;
+
+   ret = regmap_read(data->regmap, REG_SMARTFAN_EN(sattr->index), );
+   if (ret < 0)
+   return ret;
+   enabled = reg >> SMARTFAN_EN_SHIFT(sattr->index) & 1;
+   return sprintf(buf, "%u\n", enabled + 1);
+}
+
+static ssize_t store_pwm_enable(struct device *dev,
+   struct device_attribute *attr,
+   const char *buf, size_t count)
+{
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+   u8 val;
+   int ret;
+
+   ret = kstrtou8(buf, 0, );
+   if (ret < 0)
+   return ret;
+   if (val < 1 || val > 2)
+   return -EINVAL;
+   ret = regmap_update_bits(data->regmap, REG_SMARTFAN_EN(sattr->index),
+1 << SMARTFAN_EN_SHIFT(sattr->index),
+(val - 1) << SMARTFAN_EN_SHIFT(sattr->index));
+   return ret ? : count;
+}
+
 static int nct7802_read_temp(struct nct7802_data *data,
 u8 reg_temp, u8 reg_temp_low, int *temp)
 {
@@ -793,6 +830,11 @@ static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, 
show_pwm, store_pwm, 0x60);
 static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x61);
 static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x62);
 
+/* 7.2.95... Temperature to Fan mapping Relationships Register */
+static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable, 
store_pwm_enable, 0);
+static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, show_pwm_enable, 
store_pwm_enable, 1);
+static SENSOR_DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, show_pwm_enable, 
store_pwm_enable, 2);
+
 static struct attribute *nct7802_fan_attrs[] = {
_dev_attr_fan1_input.dev_attr.attr,
_dev_attr_fan1_min.dev_attr.attr,
@@ -832,10 +874,13 @@ static struct attribute_group nct7802_fan_group = {
 };
 
 static struct attribute *nct7802_pwm_attrs[] = {
+   _dev_attr_pwm1_enable.dev_attr.attr,
_dev_attr_pwm1_mode.dev_attr.attr,
_dev_attr_pwm1.dev_attr.attr,
+   _dev_attr_pwm2_enable.dev_attr.attr,
_dev_attr_pwm2_mode.dev_attr.attr,
_dev_attr_pwm2.dev_attr.attr,
+   _dev_attr_pwm3_enable.dev_attr.attr,
_dev_attr_pwm3_mode.dev_attr.attr,
_dev_attr_pwm3.dev_attr.attr,
NULL
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] hwmon: (nct7802) Add pwmX_enable attribute

2015-07-07 Thread Constantine Shulyupin
Introduced REG_SMARTFAN_EN_BASE, pwmX_enable,
show_pwm_enable, store_pwm_enable.

Signed-off-by: Constantine Shulyupin 
---
 drivers/hwmon/nct7802.c | 46 ++
 1 file changed, 46 insertions(+)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index a0d9010..a53e6e1 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -53,6 +53,7 @@ static const u8 REG_VOLTAGE_LIMIT_MSB_SHIFT[2][5] = {
 #define REG_PECI_ENABLE0x23
 #define REG_FAN_ENABLE 0x24
 #define REG_VMON_ENABLE0x25
+#define REG_SMARTFAN_EN_BASE   0x64
 #define REG_VENDOR_ID  0xfd
 #define REG_CHIP_ID0xfe
 #define REG_VERSION_ID 0xff
@@ -151,6 +152,43 @@ static ssize_t store_pwm(struct device *dev, struct 
device_attribute *devattr,
return err ? : count;
 }
 
+static ssize_t show_pwm_enable(struct device *dev,
+  struct device_attribute *attr, char *buf)
+{
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+   unsigned int reg, enabled, pwm;
+   int ret;
+
+   ret = regmap_read(data->regmap, REG_SMARTFAN_EN_BASE + sattr->index / 2,
+ );
+   if (ret < 0)
+   return ret;
+   enabled = reg >> (sattr->index % 2 * 4) & 1;
+   return sprintf(buf, "%u\n", enabled + 1);
+}
+
+static ssize_t store_pwm_enable(struct device *dev,
+   struct device_attribute *attr,
+   const char *buf, size_t count)
+{
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+   u8 val;
+   int ret;
+
+   ret = kstrtou8(buf, 0, );
+   if (ret < 0)
+   return ret;
+   if (val < 1 || val > 3)
+   return -EINVAL;
+   ret = regmap_update_bits(data->regmap,
+REG_SMARTFAN_EN_BASE + sattr->index / 2,
+1 << sattr->index % 2 * 4,
+(val - 1) << sattr->index % 2 * 4);
+   return ret ? : count;
+}
+
 static int nct7802_read_temp(struct nct7802_data *data,
 u8 reg_temp, u8 reg_temp_low, int *temp)
 {
@@ -793,6 +831,11 @@ static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, 
show_pwm, store_pwm, 0x60);
 static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x61);
 static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x62);
 
+/* 7.2.95... Temperature to Fan mapping Relationships Register */
+static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable, 
store_pwm_enable, 0);
+static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, show_pwm_enable, 
store_pwm_enable, 1);
+static SENSOR_DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, show_pwm_enable, 
store_pwm_enable, 2);
+
 static struct attribute *nct7802_fan_attrs[] = {
_dev_attr_fan1_input.dev_attr.attr,
_dev_attr_fan1_min.dev_attr.attr,
@@ -832,10 +875,13 @@ static struct attribute_group nct7802_fan_group = {
 };
 
 static struct attribute *nct7802_pwm_attrs[] = {
+   _dev_attr_pwm1_enable.dev_attr.attr,
_dev_attr_pwm1_mode.dev_attr.attr,
_dev_attr_pwm1.dev_attr.attr,
+   _dev_attr_pwm2_enable.dev_attr.attr,
_dev_attr_pwm2_mode.dev_attr.attr,
_dev_attr_pwm2.dev_attr.attr,
+   _dev_attr_pwm3_enable.dev_attr.attr,
_dev_attr_pwm3_mode.dev_attr.attr,
_dev_attr_pwm3.dev_attr.attr,
NULL
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] hwmon: (nct7802) Add pwmX_enable attribute

2015-07-07 Thread Constantine Shulyupin
Introduced REG_SMARTFAN_EN_BASE, pwmX_enable,
show_pwm_enable, store_pwm_enable.

Signed-off-by: Constantine Shulyupin co...@makelinux.com
---
 drivers/hwmon/nct7802.c | 46 ++
 1 file changed, 46 insertions(+)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index a0d9010..a53e6e1 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -53,6 +53,7 @@ static const u8 REG_VOLTAGE_LIMIT_MSB_SHIFT[2][5] = {
 #define REG_PECI_ENABLE0x23
 #define REG_FAN_ENABLE 0x24
 #define REG_VMON_ENABLE0x25
+#define REG_SMARTFAN_EN_BASE   0x64
 #define REG_VENDOR_ID  0xfd
 #define REG_CHIP_ID0xfe
 #define REG_VERSION_ID 0xff
@@ -151,6 +152,43 @@ static ssize_t store_pwm(struct device *dev, struct 
device_attribute *devattr,
return err ? : count;
 }
 
+static ssize_t show_pwm_enable(struct device *dev,
+  struct device_attribute *attr, char *buf)
+{
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+   unsigned int reg, enabled, pwm;
+   int ret;
+
+   ret = regmap_read(data-regmap, REG_SMARTFAN_EN_BASE + sattr-index / 2,
+ reg);
+   if (ret  0)
+   return ret;
+   enabled = reg  (sattr-index % 2 * 4)  1;
+   return sprintf(buf, %u\n, enabled + 1);
+}
+
+static ssize_t store_pwm_enable(struct device *dev,
+   struct device_attribute *attr,
+   const char *buf, size_t count)
+{
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+   u8 val;
+   int ret;
+
+   ret = kstrtou8(buf, 0, val);
+   if (ret  0)
+   return ret;
+   if (val  1 || val  3)
+   return -EINVAL;
+   ret = regmap_update_bits(data-regmap,
+REG_SMARTFAN_EN_BASE + sattr-index / 2,
+1  sattr-index % 2 * 4,
+(val - 1)  sattr-index % 2 * 4);
+   return ret ? : count;
+}
+
 static int nct7802_read_temp(struct nct7802_data *data,
 u8 reg_temp, u8 reg_temp_low, int *temp)
 {
@@ -793,6 +831,11 @@ static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, 
show_pwm, store_pwm, 0x60);
 static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x61);
 static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x62);
 
+/* 7.2.95... Temperature to Fan mapping Relationships Register */
+static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable, 
store_pwm_enable, 0);
+static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, show_pwm_enable, 
store_pwm_enable, 1);
+static SENSOR_DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, show_pwm_enable, 
store_pwm_enable, 2);
+
 static struct attribute *nct7802_fan_attrs[] = {
sensor_dev_attr_fan1_input.dev_attr.attr,
sensor_dev_attr_fan1_min.dev_attr.attr,
@@ -832,10 +875,13 @@ static struct attribute_group nct7802_fan_group = {
 };
 
 static struct attribute *nct7802_pwm_attrs[] = {
+   sensor_dev_attr_pwm1_enable.dev_attr.attr,
sensor_dev_attr_pwm1_mode.dev_attr.attr,
sensor_dev_attr_pwm1.dev_attr.attr,
+   sensor_dev_attr_pwm2_enable.dev_attr.attr,
sensor_dev_attr_pwm2_mode.dev_attr.attr,
sensor_dev_attr_pwm2.dev_attr.attr,
+   sensor_dev_attr_pwm3_enable.dev_attr.attr,
sensor_dev_attr_pwm3_mode.dev_attr.attr,
sensor_dev_attr_pwm3.dev_attr.attr,
NULL
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2] hwmon: (nct7802) Add pwmX_enable attribute

2015-07-07 Thread Constantine Shulyupin
Introduced REG_SMARTFAN_EN, SMARTFAN_EN_SHIFT, pwmX_enable,
show_pwm_enable, store_pwm_enable.

Signed-off-by: Constantine Shulyupin co...@makelinux.com

---
Change log:
Fixed in v2:
- Introduced REG_SMARTFAN_EN, SMARTFAN_EN_SHIFT

Signed-off-by: Constantine Shulyupin co...@makelinux.com
---
 drivers/hwmon/nct7802.c | 45 +
 1 file changed, 45 insertions(+)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index a0d9010..2f6bbe5 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -53,6 +53,8 @@ static const u8 REG_VOLTAGE_LIMIT_MSB_SHIFT[2][5] = {
 #define REG_PECI_ENABLE0x23
 #define REG_FAN_ENABLE 0x24
 #define REG_VMON_ENABLE0x25
+#define REG_SMARTFAN_EN(x)  (0x64 + (x) / 2)
+#define SMARTFAN_EN_SHIFT(x)((x) % 2 * 4)
 #define REG_VENDOR_ID  0xfd
 #define REG_CHIP_ID0xfe
 #define REG_VERSION_ID 0xff
@@ -151,6 +153,41 @@ static ssize_t store_pwm(struct device *dev, struct 
device_attribute *devattr,
return err ? : count;
 }
 
+static ssize_t show_pwm_enable(struct device *dev,
+  struct device_attribute *attr, char *buf)
+{
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+   unsigned int reg, enabled;
+   int ret;
+
+   ret = regmap_read(data-regmap, REG_SMARTFAN_EN(sattr-index), reg);
+   if (ret  0)
+   return ret;
+   enabled = reg  SMARTFAN_EN_SHIFT(sattr-index)  1;
+   return sprintf(buf, %u\n, enabled + 1);
+}
+
+static ssize_t store_pwm_enable(struct device *dev,
+   struct device_attribute *attr,
+   const char *buf, size_t count)
+{
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+   u8 val;
+   int ret;
+
+   ret = kstrtou8(buf, 0, val);
+   if (ret  0)
+   return ret;
+   if (val  1 || val  2)
+   return -EINVAL;
+   ret = regmap_update_bits(data-regmap, REG_SMARTFAN_EN(sattr-index),
+1  SMARTFAN_EN_SHIFT(sattr-index),
+(val - 1)  SMARTFAN_EN_SHIFT(sattr-index));
+   return ret ? : count;
+}
+
 static int nct7802_read_temp(struct nct7802_data *data,
 u8 reg_temp, u8 reg_temp_low, int *temp)
 {
@@ -793,6 +830,11 @@ static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, 
show_pwm, store_pwm, 0x60);
 static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x61);
 static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x62);
 
+/* 7.2.95... Temperature to Fan mapping Relationships Register */
+static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable, 
store_pwm_enable, 0);
+static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, show_pwm_enable, 
store_pwm_enable, 1);
+static SENSOR_DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, show_pwm_enable, 
store_pwm_enable, 2);
+
 static struct attribute *nct7802_fan_attrs[] = {
sensor_dev_attr_fan1_input.dev_attr.attr,
sensor_dev_attr_fan1_min.dev_attr.attr,
@@ -832,10 +874,13 @@ static struct attribute_group nct7802_fan_group = {
 };
 
 static struct attribute *nct7802_pwm_attrs[] = {
+   sensor_dev_attr_pwm1_enable.dev_attr.attr,
sensor_dev_attr_pwm1_mode.dev_attr.attr,
sensor_dev_attr_pwm1.dev_attr.attr,
+   sensor_dev_attr_pwm2_enable.dev_attr.attr,
sensor_dev_attr_pwm2_mode.dev_attr.attr,
sensor_dev_attr_pwm2.dev_attr.attr,
+   sensor_dev_attr_pwm3_enable.dev_attr.attr,
sensor_dev_attr_pwm3_mode.dev_attr.attr,
sensor_dev_attr_pwm3.dev_attr.attr,
NULL
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4] hwmon: (nct7802) Add pwm control

2015-07-05 Thread Constantine Shulyupin
Added fan output control registers.
Modes of operation are PWM (default) and DC.

Introduced show_pwm, store_pwm, nct7802_pwm_attrs, nct7802_pwm_group.

---
Change log:
Fixed in v2:
- renamed fanX_output to pwmX
- introduced nct7802_pwm_group and nct7802_pwm_attrs
- renamed show_dec to show_pwd
- used kstrtou8 instead kstrtouint
Fixed in v3:
- spilt functions declarations to fit 80 columns
- removed unnecessary initializations
- rearranged variable declarations
- shortened return expression
- renamed store_u8 to store_pwm
Fixed in v4:
- compilation error: missing val

Signed-off-by: Constantine Shulyupin 
---
 drivers/hwmon/nct7802.c | 47 +++
 1 file changed, 47 insertions(+)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index afa242d..56b6f7b 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -102,6 +102,36 @@ static ssize_t store_temp_type(struct device *dev,
return err ? : count;
 }
 
+static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr,
+   char *buf)
+{
+   struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   unsigned int val;
+   int ret;
+
+   ret = regmap_read(data->regmap, attr->index, );
+   if (ret < 0)
+   return ret;
+
+   return sprintf(buf, "%d\n", val);
+}
+
+static ssize_t store_pwm(struct device *dev, struct device_attribute *devattr,
+const char *buf, size_t count)
+{
+   struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   int err;
+   u8 val;
+
+   err = kstrtou8(buf, 0, );
+   if (err < 0)
+   return err;
+
+   err = regmap_write(data->regmap, attr->index, val);
+   return err ? : count;
+}
 
 static int nct7802_read_temp(struct nct7802_data *data,
 u8 reg_temp, u8 reg_temp_low, int *temp)
@@ -735,6 +765,11 @@ static SENSOR_DEVICE_ATTR_2(fan3_alarm, S_IRUGO, 
show_alarm, NULL, 0x1a, 2);
 static SENSOR_DEVICE_ATTR_2(fan3_beep, S_IRUGO | S_IWUSR, show_beep, 
store_beep,
0x5b, 2);
 
+/* 7.2.91... Fan Control Output Value */
+static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x60);
+static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x61);
+static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x62);
+
 static struct attribute *nct7802_fan_attrs[] = {
_dev_attr_fan1_input.dev_attr.attr,
_dev_attr_fan1_min.dev_attr.attr,
@@ -773,10 +808,22 @@ static struct attribute_group nct7802_fan_group = {
.is_visible = nct7802_fan_is_visible,
 };
 
+static struct attribute *nct7802_pwm_attrs[] = {
+   _dev_attr_pwm1.dev_attr.attr,
+   _dev_attr_pwm2.dev_attr.attr,
+   _dev_attr_pwm3.dev_attr.attr,
+   NULL
+};
+
+static struct attribute_group nct7802_pwm_group = {
+   .attrs = nct7802_pwm_attrs,
+};
+
 static const struct attribute_group *nct7802_groups[] = {
_temp_group,
_in_group,
_fan_group,
+   _pwm_group,
NULL
 };
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] hwmon: (nct7802) Add pwm mode

2015-07-05 Thread Constantine Shulyupin
Introduced: show_pwm_mode, pwm1_mode, pwm2_mode, pwm2_mode
Signed-off-by: Constantine Shulyupin 
---
 drivers/hwmon/nct7802.c | 26 ++
 1 file changed, 26 insertions(+)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index 56b6f7b..16e0d17 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -102,6 +102,24 @@ static ssize_t store_temp_type(struct device *dev,
return err ? : count;
 }
 
+static ssize_t show_pwm_mode(struct device *dev, struct device_attribute *attr,
+char *buf)
+{
+   struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   unsigned int regval;
+   int ret;
+
+   if (sattr->index > 1)
+   return sprintf(buf, "1\n");
+
+   ret = regmap_read(data->regmap, sattr->nr, );
+   if (ret < 0)
+   return ret;
+
+   return sprintf(buf, "%u\n", !(regval & (1 << sattr->index)));
+}
+
 static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr,
char *buf)
 {
@@ -765,6 +783,11 @@ static SENSOR_DEVICE_ATTR_2(fan3_alarm, S_IRUGO, 
show_alarm, NULL, 0x1a, 2);
 static SENSOR_DEVICE_ATTR_2(fan3_beep, S_IRUGO | S_IWUSR, show_beep, 
store_beep,
0x5b, 2);
 
+/* 7.2.89 Fan Control Output Type */
+static SENSOR_DEVICE_ATTR_2(pwm1_mode, S_IRUGO, show_pwm_mode, NULL, 0x5E, 0);
+static SENSOR_DEVICE_ATTR_2(pwm2_mode, S_IRUGO, show_pwm_mode, NULL, 0x5E, 1);
+static SENSOR_DEVICE_ATTR_2(pwm3_mode, S_IRUGO, show_pwm_mode, NULL, 0, 2);
+
 /* 7.2.91... Fan Control Output Value */
 static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x60);
 static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x61);
@@ -809,8 +832,11 @@ static struct attribute_group nct7802_fan_group = {
 };
 
 static struct attribute *nct7802_pwm_attrs[] = {
+   _dev_attr_pwm1_mode.dev_attr.attr,
_dev_attr_pwm1.dev_attr.attr,
+   _dev_attr_pwm2_mode.dev_attr.attr,
_dev_attr_pwm2.dev_attr.attr,
+   _dev_attr_pwm3_mode.dev_attr.attr,
_dev_attr_pwm3.dev_attr.attr,
NULL
 };
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2] hwmon: (nct7802) Add pwm mode

2015-07-05 Thread Constantine Shulyupin
Introduced: show_pwm_mode, pwm1_mode, pwm2_mode, pwm2_mode

---
Changelog:
Fixed in v2:
- used SENSOR_DEVICE_ATTR instead of SENSOR_DEVICE_ATTR_2 for pwmX_mode

Signed-off-by: Constantine Shulyupin 
---
 drivers/hwmon/nct7802.c | 26 ++
 1 file changed, 26 insertions(+)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index 56b6f7b..a0d9010 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -102,6 +102,24 @@ static ssize_t store_temp_type(struct device *dev,
return err ? : count;
 }
 
+static ssize_t show_pwm_mode(struct device *dev, struct device_attribute *attr,
+char *buf)
+{
+   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   unsigned int regval;
+   int ret;
+
+   if (sattr->index > 1)
+   return sprintf(buf, "1\n");
+
+   ret = regmap_read(data->regmap, 0x5E, );
+   if (ret < 0)
+   return ret;
+
+   return sprintf(buf, "%u\n", !(regval & (1 << sattr->index)));
+}
+
 static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr,
char *buf)
 {
@@ -765,6 +783,11 @@ static SENSOR_DEVICE_ATTR_2(fan3_alarm, S_IRUGO, 
show_alarm, NULL, 0x1a, 2);
 static SENSOR_DEVICE_ATTR_2(fan3_beep, S_IRUGO | S_IWUSR, show_beep, 
store_beep,
0x5b, 2);
 
+/* 7.2.89 Fan Control Output Type */
+static SENSOR_DEVICE_ATTR(pwm1_mode, S_IRUGO, show_pwm_mode, NULL, 0);
+static SENSOR_DEVICE_ATTR(pwm2_mode, S_IRUGO, show_pwm_mode, NULL, 1);
+static SENSOR_DEVICE_ATTR(pwm3_mode, S_IRUGO, show_pwm_mode, NULL, 2);
+
 /* 7.2.91... Fan Control Output Value */
 static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x60);
 static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x61);
@@ -809,8 +832,11 @@ static struct attribute_group nct7802_fan_group = {
 };
 
 static struct attribute *nct7802_pwm_attrs[] = {
+   _dev_attr_pwm1_mode.dev_attr.attr,
_dev_attr_pwm1.dev_attr.attr,
+   _dev_attr_pwm2_mode.dev_attr.attr,
_dev_attr_pwm2.dev_attr.attr,
+   _dev_attr_pwm3_mode.dev_attr.attr,
_dev_attr_pwm3.dev_attr.attr,
NULL
 };
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3] hwmon: (nct7802) Add pwm control

2015-07-05 Thread Constantine Shulyupin
Added fan output control registers.
Modes of operation are PWM (default) and DC.

Introduced show_pwm, store_pwm, nct7802_pwm_attrs, nct7802_pwm_group.

---
Change log:
Fixed in v2:
- renamed fanX_output to pwmX
- introduced nct7802_pwm_group and nct7802_pwm_attrs
- renamed show_dec to show_pwd
- used kstrtou8 instead kstrtouint
Fixed in v3:
- spilt functions declarations to fit 80 columns
- removed unnecessary initializations
- rearranged variable declarations
- shortened return expression
- renamed store_u8 to store_pwm

Signed-off-by: Constantine Shulyupin 
---
 drivers/hwmon/nct7802.c | 47 +++
 1 file changed, 47 insertions(+)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index afa242d..6382d4d 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -102,6 +102,36 @@ static ssize_t store_temp_type(struct device *dev,
return err ? : count;
 }
 
+static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr,
+   char *buf)
+{
+   struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   unsigned int;
+   int ret;
+
+   ret = regmap_read(data->regmap, attr->index, );
+   if (ret < 0)
+   return ret;
+
+   return sprintf(buf, "%d\n", val);
+}
+
+static ssize_t store_pwm(struct device *dev, struct device_attribute *devattr,
+const char *buf, size_t count)
+{
+   struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   int err;
+   u8 val;
+
+   err = kstrtou8(buf, 0, );
+   if (err < 0)
+   return err;
+
+   err = regmap_write(data->regmap, attr->index, val);
+   return err ? : count;
+}
 
 static int nct7802_read_temp(struct nct7802_data *data,
 u8 reg_temp, u8 reg_temp_low, int *temp)
@@ -735,6 +765,11 @@ static SENSOR_DEVICE_ATTR_2(fan3_alarm, S_IRUGO, 
show_alarm, NULL, 0x1a, 2);
 static SENSOR_DEVICE_ATTR_2(fan3_beep, S_IRUGO | S_IWUSR, show_beep, 
store_beep,
0x5b, 2);
 
+/* 7.2.91... Fan Control Output Value */
+static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x60);
+static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x61);
+static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x62);
+
 static struct attribute *nct7802_fan_attrs[] = {
_dev_attr_fan1_input.dev_attr.attr,
_dev_attr_fan1_min.dev_attr.attr,
@@ -773,10 +808,22 @@ static struct attribute_group nct7802_fan_group = {
.is_visible = nct7802_fan_is_visible,
 };
 
+static struct attribute *nct7802_pwm_attrs[] = {
+   _dev_attr_pwm1.dev_attr.attr,
+   _dev_attr_pwm2.dev_attr.attr,
+   _dev_attr_pwm3.dev_attr.attr,
+   NULL
+};
+
+static struct attribute_group nct7802_pwm_group = {
+   .attrs = nct7802_pwm_attrs,
+};
+
 static const struct attribute_group *nct7802_groups[] = {
_temp_group,
_in_group,
_fan_group,
+   _pwm_group,
NULL
 };
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2] hwmon: (nct7802) Add pwm mode

2015-07-05 Thread Constantine Shulyupin
Introduced: show_pwm_mode, pwm1_mode, pwm2_mode, pwm2_mode

---
Changelog:
Fixed in v2:
- used SENSOR_DEVICE_ATTR instead of SENSOR_DEVICE_ATTR_2 for pwmX_mode

Signed-off-by: Constantine Shulyupin co...@makelinux.com
---
 drivers/hwmon/nct7802.c | 26 ++
 1 file changed, 26 insertions(+)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index 56b6f7b..a0d9010 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -102,6 +102,24 @@ static ssize_t store_temp_type(struct device *dev,
return err ? : count;
 }
 
+static ssize_t show_pwm_mode(struct device *dev, struct device_attribute *attr,
+char *buf)
+{
+   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   unsigned int regval;
+   int ret;
+
+   if (sattr-index  1)
+   return sprintf(buf, 1\n);
+
+   ret = regmap_read(data-regmap, 0x5E, regval);
+   if (ret  0)
+   return ret;
+
+   return sprintf(buf, %u\n, !(regval  (1  sattr-index)));
+}
+
 static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr,
char *buf)
 {
@@ -765,6 +783,11 @@ static SENSOR_DEVICE_ATTR_2(fan3_alarm, S_IRUGO, 
show_alarm, NULL, 0x1a, 2);
 static SENSOR_DEVICE_ATTR_2(fan3_beep, S_IRUGO | S_IWUSR, show_beep, 
store_beep,
0x5b, 2);
 
+/* 7.2.89 Fan Control Output Type */
+static SENSOR_DEVICE_ATTR(pwm1_mode, S_IRUGO, show_pwm_mode, NULL, 0);
+static SENSOR_DEVICE_ATTR(pwm2_mode, S_IRUGO, show_pwm_mode, NULL, 1);
+static SENSOR_DEVICE_ATTR(pwm3_mode, S_IRUGO, show_pwm_mode, NULL, 2);
+
 /* 7.2.91... Fan Control Output Value */
 static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x60);
 static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x61);
@@ -809,8 +832,11 @@ static struct attribute_group nct7802_fan_group = {
 };
 
 static struct attribute *nct7802_pwm_attrs[] = {
+   sensor_dev_attr_pwm1_mode.dev_attr.attr,
sensor_dev_attr_pwm1.dev_attr.attr,
+   sensor_dev_attr_pwm2_mode.dev_attr.attr,
sensor_dev_attr_pwm2.dev_attr.attr,
+   sensor_dev_attr_pwm3_mode.dev_attr.attr,
sensor_dev_attr_pwm3.dev_attr.attr,
NULL
 };
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4] hwmon: (nct7802) Add pwm control

2015-07-05 Thread Constantine Shulyupin
Added fan output control registers.
Modes of operation are PWM (default) and DC.

Introduced show_pwm, store_pwm, nct7802_pwm_attrs, nct7802_pwm_group.

---
Change log:
Fixed in v2:
- renamed fanX_output to pwmX
- introduced nct7802_pwm_group and nct7802_pwm_attrs
- renamed show_dec to show_pwd
- used kstrtou8 instead kstrtouint
Fixed in v3:
- spilt functions declarations to fit 80 columns
- removed unnecessary initializations
- rearranged variable declarations
- shortened return expression
- renamed store_u8 to store_pwm
Fixed in v4:
- compilation error: missing val

Signed-off-by: Constantine Shulyupin co...@makelinux.com
---
 drivers/hwmon/nct7802.c | 47 +++
 1 file changed, 47 insertions(+)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index afa242d..56b6f7b 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -102,6 +102,36 @@ static ssize_t store_temp_type(struct device *dev,
return err ? : count;
 }
 
+static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr,
+   char *buf)
+{
+   struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   unsigned int val;
+   int ret;
+
+   ret = regmap_read(data-regmap, attr-index, val);
+   if (ret  0)
+   return ret;
+
+   return sprintf(buf, %d\n, val);
+}
+
+static ssize_t store_pwm(struct device *dev, struct device_attribute *devattr,
+const char *buf, size_t count)
+{
+   struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   int err;
+   u8 val;
+
+   err = kstrtou8(buf, 0, val);
+   if (err  0)
+   return err;
+
+   err = regmap_write(data-regmap, attr-index, val);
+   return err ? : count;
+}
 
 static int nct7802_read_temp(struct nct7802_data *data,
 u8 reg_temp, u8 reg_temp_low, int *temp)
@@ -735,6 +765,11 @@ static SENSOR_DEVICE_ATTR_2(fan3_alarm, S_IRUGO, 
show_alarm, NULL, 0x1a, 2);
 static SENSOR_DEVICE_ATTR_2(fan3_beep, S_IRUGO | S_IWUSR, show_beep, 
store_beep,
0x5b, 2);
 
+/* 7.2.91... Fan Control Output Value */
+static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x60);
+static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x61);
+static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x62);
+
 static struct attribute *nct7802_fan_attrs[] = {
sensor_dev_attr_fan1_input.dev_attr.attr,
sensor_dev_attr_fan1_min.dev_attr.attr,
@@ -773,10 +808,22 @@ static struct attribute_group nct7802_fan_group = {
.is_visible = nct7802_fan_is_visible,
 };
 
+static struct attribute *nct7802_pwm_attrs[] = {
+   sensor_dev_attr_pwm1.dev_attr.attr,
+   sensor_dev_attr_pwm2.dev_attr.attr,
+   sensor_dev_attr_pwm3.dev_attr.attr,
+   NULL
+};
+
+static struct attribute_group nct7802_pwm_group = {
+   .attrs = nct7802_pwm_attrs,
+};
+
 static const struct attribute_group *nct7802_groups[] = {
nct7802_temp_group,
nct7802_in_group,
nct7802_fan_group,
+   nct7802_pwm_group,
NULL
 };
 
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3] hwmon: (nct7802) Add pwm control

2015-07-05 Thread Constantine Shulyupin
Added fan output control registers.
Modes of operation are PWM (default) and DC.

Introduced show_pwm, store_pwm, nct7802_pwm_attrs, nct7802_pwm_group.

---
Change log:
Fixed in v2:
- renamed fanX_output to pwmX
- introduced nct7802_pwm_group and nct7802_pwm_attrs
- renamed show_dec to show_pwd
- used kstrtou8 instead kstrtouint
Fixed in v3:
- spilt functions declarations to fit 80 columns
- removed unnecessary initializations
- rearranged variable declarations
- shortened return expression
- renamed store_u8 to store_pwm

Signed-off-by: Constantine Shulyupin co...@makelinux.com
---
 drivers/hwmon/nct7802.c | 47 +++
 1 file changed, 47 insertions(+)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index afa242d..6382d4d 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -102,6 +102,36 @@ static ssize_t store_temp_type(struct device *dev,
return err ? : count;
 }
 
+static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr,
+   char *buf)
+{
+   struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   unsigned int;
+   int ret;
+
+   ret = regmap_read(data-regmap, attr-index, val);
+   if (ret  0)
+   return ret;
+
+   return sprintf(buf, %d\n, val);
+}
+
+static ssize_t store_pwm(struct device *dev, struct device_attribute *devattr,
+const char *buf, size_t count)
+{
+   struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   int err;
+   u8 val;
+
+   err = kstrtou8(buf, 0, val);
+   if (err  0)
+   return err;
+
+   err = regmap_write(data-regmap, attr-index, val);
+   return err ? : count;
+}
 
 static int nct7802_read_temp(struct nct7802_data *data,
 u8 reg_temp, u8 reg_temp_low, int *temp)
@@ -735,6 +765,11 @@ static SENSOR_DEVICE_ATTR_2(fan3_alarm, S_IRUGO, 
show_alarm, NULL, 0x1a, 2);
 static SENSOR_DEVICE_ATTR_2(fan3_beep, S_IRUGO | S_IWUSR, show_beep, 
store_beep,
0x5b, 2);
 
+/* 7.2.91... Fan Control Output Value */
+static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x60);
+static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x61);
+static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x62);
+
 static struct attribute *nct7802_fan_attrs[] = {
sensor_dev_attr_fan1_input.dev_attr.attr,
sensor_dev_attr_fan1_min.dev_attr.attr,
@@ -773,10 +808,22 @@ static struct attribute_group nct7802_fan_group = {
.is_visible = nct7802_fan_is_visible,
 };
 
+static struct attribute *nct7802_pwm_attrs[] = {
+   sensor_dev_attr_pwm1.dev_attr.attr,
+   sensor_dev_attr_pwm2.dev_attr.attr,
+   sensor_dev_attr_pwm3.dev_attr.attr,
+   NULL
+};
+
+static struct attribute_group nct7802_pwm_group = {
+   .attrs = nct7802_pwm_attrs,
+};
+
 static const struct attribute_group *nct7802_groups[] = {
nct7802_temp_group,
nct7802_in_group,
nct7802_fan_group,
+   nct7802_pwm_group,
NULL
 };
 
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] hwmon: (nct7802) Add pwm mode

2015-07-05 Thread Constantine Shulyupin
Introduced: show_pwm_mode, pwm1_mode, pwm2_mode, pwm2_mode
Signed-off-by: Constantine Shulyupin co...@makelinux.com
---
 drivers/hwmon/nct7802.c | 26 ++
 1 file changed, 26 insertions(+)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index 56b6f7b..16e0d17 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -102,6 +102,24 @@ static ssize_t store_temp_type(struct device *dev,
return err ? : count;
 }
 
+static ssize_t show_pwm_mode(struct device *dev, struct device_attribute *attr,
+char *buf)
+{
+   struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   unsigned int regval;
+   int ret;
+
+   if (sattr-index  1)
+   return sprintf(buf, 1\n);
+
+   ret = regmap_read(data-regmap, sattr-nr, regval);
+   if (ret  0)
+   return ret;
+
+   return sprintf(buf, %u\n, !(regval  (1  sattr-index)));
+}
+
 static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr,
char *buf)
 {
@@ -765,6 +783,11 @@ static SENSOR_DEVICE_ATTR_2(fan3_alarm, S_IRUGO, 
show_alarm, NULL, 0x1a, 2);
 static SENSOR_DEVICE_ATTR_2(fan3_beep, S_IRUGO | S_IWUSR, show_beep, 
store_beep,
0x5b, 2);
 
+/* 7.2.89 Fan Control Output Type */
+static SENSOR_DEVICE_ATTR_2(pwm1_mode, S_IRUGO, show_pwm_mode, NULL, 0x5E, 0);
+static SENSOR_DEVICE_ATTR_2(pwm2_mode, S_IRUGO, show_pwm_mode, NULL, 0x5E, 1);
+static SENSOR_DEVICE_ATTR_2(pwm3_mode, S_IRUGO, show_pwm_mode, NULL, 0, 2);
+
 /* 7.2.91... Fan Control Output Value */
 static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x60);
 static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x61);
@@ -809,8 +832,11 @@ static struct attribute_group nct7802_fan_group = {
 };
 
 static struct attribute *nct7802_pwm_attrs[] = {
+   sensor_dev_attr_pwm1_mode.dev_attr.attr,
sensor_dev_attr_pwm1.dev_attr.attr,
+   sensor_dev_attr_pwm2_mode.dev_attr.attr,
sensor_dev_attr_pwm2.dev_attr.attr,
+   sensor_dev_attr_pwm3_mode.dev_attr.attr,
sensor_dev_attr_pwm3.dev_attr.attr,
NULL
 };
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2] hwmon: (nct7802) Add pwm control

2015-07-03 Thread Constantine Shulyupin
Notes:

Some lines intentionally more than 80 characters because wrapping
this lines decreases readability.
The patch was checked with scripts/checkpatch.pl --max-line-length=88

Signed-off-by: Constantine Shulyupin 
---
 drivers/hwmon/nct7802.c | 47 +++
 1 file changed, 47 insertions(+)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index afa242d..104d8b9 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -102,6 +102,36 @@ static ssize_t store_temp_type(struct device *dev,
return err ? : count;
 }
 
+static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, 
char *buf)
+{
+   int ret = -1;
+   struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   unsigned int val = 0;
+
+   ret = regmap_read(data->regmap, attr->index, );
+   if (ret < 0)
+   return ret;
+
+   ret = sprintf(buf, "%d\n", val);
+   return ret;
+}
+
+static ssize_t store_u8(struct device *dev, struct device_attribute *devattr,
+   const char *buf, size_t count)
+{
+   struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   int err;
+   u8 val;
+
+   err = kstrtou8(buf, 0, );
+   if (err < 0)
+   return err;
+
+   err = regmap_write(data->regmap, attr->index, val);
+   return err ? : count;
+}
 
 static int nct7802_read_temp(struct nct7802_data *data,
 u8 reg_temp, u8 reg_temp_low, int *temp)
@@ -735,6 +765,11 @@ static SENSOR_DEVICE_ATTR_2(fan3_alarm, S_IRUGO, 
show_alarm, NULL, 0x1a, 2);
 static SENSOR_DEVICE_ATTR_2(fan3_beep, S_IRUGO | S_IWUSR, show_beep, 
store_beep,
0x5b, 2);
 
+/* 7.2.91... Fan Control Output Value */
+static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_u8, 0x60);
+static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_u8, 0x61);
+static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_u8, 0x62);
+
 static struct attribute *nct7802_fan_attrs[] = {
_dev_attr_fan1_input.dev_attr.attr,
_dev_attr_fan1_min.dev_attr.attr,
@@ -773,10 +808,22 @@ static struct attribute_group nct7802_fan_group = {
.is_visible = nct7802_fan_is_visible,
 };
 
+static struct attribute *nct7802_pwm_attrs[] = {
+   _dev_attr_pwm1.dev_attr.attr,
+   _dev_attr_pwm2.dev_attr.attr,
+   _dev_attr_pwm3.dev_attr.attr,
+   NULL
+};
+
+static struct attribute_group nct7802_pwm_group = {
+   .attrs = nct7802_pwm_attrs,
+};
+
 static const struct attribute_group *nct7802_groups[] = {
_temp_group,
_in_group,
_fan_group,
+   _pwm_group,
NULL
 };
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2] hwmon: (nct7802) Add pwm control

2015-07-03 Thread Constantine Shulyupin
Notes:

Some lines intentionally more than 80 characters because wrapping
this lines decreases readability.
The patch was checked with scripts/checkpatch.pl --max-line-length=88

Signed-off-by: Constantine Shulyupin 
---
 drivers/hwmon/nct7802.c | 47 +++
 1 file changed, 47 insertions(+)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index afa242d..104d8b9 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -102,6 +102,36 @@ static ssize_t store_temp_type(struct device *dev,
return err ? : count;
 }
 
+static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, 
char *buf)
+{
+   int ret = -1;
+   struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   unsigned int val = 0;
+
+   ret = regmap_read(data->regmap, attr->index, );
+   if (ret < 0)
+   return ret;
+
+   ret = sprintf(buf, "%d\n", val);
+   return ret;
+}
+
+static ssize_t store_u8(struct device *dev, struct device_attribute *devattr,
+   const char *buf, size_t count)
+{
+   struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   int err;
+   u8 val;
+
+   err = kstrtou8(buf, 0, );
+   if (err < 0)
+   return err;
+
+   err = regmap_write(data->regmap, attr->index, val);
+   return err ? : count;
+}
 
 static int nct7802_read_temp(struct nct7802_data *data,
 u8 reg_temp, u8 reg_temp_low, int *temp)
@@ -735,6 +765,11 @@ static SENSOR_DEVICE_ATTR_2(fan3_alarm, S_IRUGO, 
show_alarm, NULL, 0x1a, 2);
 static SENSOR_DEVICE_ATTR_2(fan3_beep, S_IRUGO | S_IWUSR, show_beep, 
store_beep,
0x5b, 2);
 
+/* 7.2.91... Fan Control Output Value */
+static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_u8, 0x60);
+static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_u8, 0x61);
+static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_u8, 0x62);
+
 static struct attribute *nct7802_fan_attrs[] = {
_dev_attr_fan1_input.dev_attr.attr,
_dev_attr_fan1_min.dev_attr.attr,
@@ -773,10 +808,22 @@ static struct attribute_group nct7802_fan_group = {
.is_visible = nct7802_fan_is_visible,
 };
 
+static struct attribute *nct7802_pwm_attrs[] = {
+   _dev_attr_pwm1.dev_attr.attr,
+   _dev_attr_pwm2.dev_attr.attr,
+   _dev_attr_pwm3.dev_attr.attr,
+   NULL
+};
+
+static struct attribute_group nct7802_pwm_group = {
+   .attrs = nct7802_pwm_attrs,
+};
+
 static const struct attribute_group *nct7802_groups[] = {
_temp_group,
_in_group,
_fan_group,
+   _pwm_group,
NULL
 };
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] hwmon: (nct7802) Add pwm control

2015-07-03 Thread Constantine Shulyupin
Notes:

Some lines intentionally more than 80 characters because wrapping
this lines decreases readability.
The patch was checked with scripts/checkpatch.pl --max-line-length=88

Signed-off-by: Constantine Shulyupin 
---
 drivers/hwmon/nct7802.c | 47 +++
 1 file changed, 47 insertions(+)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index afa242d..104d8b9 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -102,6 +102,36 @@ static ssize_t store_temp_type(struct device *dev,
return err ? : count;
 }
 
+static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, 
char *buf)
+{
+   int ret = -1;
+   struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   unsigned int val = 0;
+
+   ret = regmap_read(data->regmap, attr->index, );
+   if (ret < 0)
+   return ret;
+
+   ret = sprintf(buf, "%d\n", val);
+   return ret;
+}
+
+static ssize_t store_u8(struct device *dev, struct device_attribute *devattr,
+   const char *buf, size_t count)
+{
+   struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   int err;
+   u8 val;
+
+   err = kstrtou8(buf, 0, );
+   if (err < 0)
+   return err;
+
+   err = regmap_write(data->regmap, attr->index, val);
+   return err ? : count;
+}
 
 static int nct7802_read_temp(struct nct7802_data *data,
 u8 reg_temp, u8 reg_temp_low, int *temp)
@@ -735,6 +765,11 @@ static SENSOR_DEVICE_ATTR_2(fan3_alarm, S_IRUGO, 
show_alarm, NULL, 0x1a, 2);
 static SENSOR_DEVICE_ATTR_2(fan3_beep, S_IRUGO | S_IWUSR, show_beep, 
store_beep,
0x5b, 2);
 
+/* 7.2.91... Fan Control Output Value */
+static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_u8, 0x60);
+static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_u8, 0x61);
+static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_u8, 0x62);
+
 static struct attribute *nct7802_fan_attrs[] = {
_dev_attr_fan1_input.dev_attr.attr,
_dev_attr_fan1_min.dev_attr.attr,
@@ -773,10 +808,22 @@ static struct attribute_group nct7802_fan_group = {
.is_visible = nct7802_fan_is_visible,
 };
 
+static struct attribute *nct7802_pwm_attrs[] = {
+   _dev_attr_pwm1.dev_attr.attr,
+   _dev_attr_pwm2.dev_attr.attr,
+   _dev_attr_pwm3.dev_attr.attr,
+   NULL
+};
+
+static struct attribute_group nct7802_pwm_group = {
+   .attrs = nct7802_pwm_attrs,
+};
+
 static const struct attribute_group *nct7802_groups[] = {
_temp_group,
_in_group,
_fan_group,
+   _pwm_group,
NULL
 };
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] hwmon: (nct7802) Add pwm control

2015-07-03 Thread Constantine Shulyupin
Notes:

Some lines intentionally more than 80 characters because wrapping
this lines decreases readability.
The patch was checked with scripts/checkpatch.pl --max-line-length=88

Signed-off-by: Constantine Shulyupin co...@makelinux.com
---
 drivers/hwmon/nct7802.c | 47 +++
 1 file changed, 47 insertions(+)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index afa242d..104d8b9 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -102,6 +102,36 @@ static ssize_t store_temp_type(struct device *dev,
return err ? : count;
 }
 
+static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, 
char *buf)
+{
+   int ret = -1;
+   struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   unsigned int val = 0;
+
+   ret = regmap_read(data-regmap, attr-index, val);
+   if (ret  0)
+   return ret;
+
+   ret = sprintf(buf, %d\n, val);
+   return ret;
+}
+
+static ssize_t store_u8(struct device *dev, struct device_attribute *devattr,
+   const char *buf, size_t count)
+{
+   struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   int err;
+   u8 val;
+
+   err = kstrtou8(buf, 0, val);
+   if (err  0)
+   return err;
+
+   err = regmap_write(data-regmap, attr-index, val);
+   return err ? : count;
+}
 
 static int nct7802_read_temp(struct nct7802_data *data,
 u8 reg_temp, u8 reg_temp_low, int *temp)
@@ -735,6 +765,11 @@ static SENSOR_DEVICE_ATTR_2(fan3_alarm, S_IRUGO, 
show_alarm, NULL, 0x1a, 2);
 static SENSOR_DEVICE_ATTR_2(fan3_beep, S_IRUGO | S_IWUSR, show_beep, 
store_beep,
0x5b, 2);
 
+/* 7.2.91... Fan Control Output Value */
+static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_u8, 0x60);
+static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_u8, 0x61);
+static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_u8, 0x62);
+
 static struct attribute *nct7802_fan_attrs[] = {
sensor_dev_attr_fan1_input.dev_attr.attr,
sensor_dev_attr_fan1_min.dev_attr.attr,
@@ -773,10 +808,22 @@ static struct attribute_group nct7802_fan_group = {
.is_visible = nct7802_fan_is_visible,
 };
 
+static struct attribute *nct7802_pwm_attrs[] = {
+   sensor_dev_attr_pwm1.dev_attr.attr,
+   sensor_dev_attr_pwm2.dev_attr.attr,
+   sensor_dev_attr_pwm3.dev_attr.attr,
+   NULL
+};
+
+static struct attribute_group nct7802_pwm_group = {
+   .attrs = nct7802_pwm_attrs,
+};
+
 static const struct attribute_group *nct7802_groups[] = {
nct7802_temp_group,
nct7802_in_group,
nct7802_fan_group,
+   nct7802_pwm_group,
NULL
 };
 
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2] hwmon: (nct7802) Add pwm control

2015-07-03 Thread Constantine Shulyupin
Notes:

Some lines intentionally more than 80 characters because wrapping
this lines decreases readability.
The patch was checked with scripts/checkpatch.pl --max-line-length=88

Signed-off-by: Constantine Shulyupin co...@makelinux.com
---
 drivers/hwmon/nct7802.c | 47 +++
 1 file changed, 47 insertions(+)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index afa242d..104d8b9 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -102,6 +102,36 @@ static ssize_t store_temp_type(struct device *dev,
return err ? : count;
 }
 
+static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, 
char *buf)
+{
+   int ret = -1;
+   struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   unsigned int val = 0;
+
+   ret = regmap_read(data-regmap, attr-index, val);
+   if (ret  0)
+   return ret;
+
+   ret = sprintf(buf, %d\n, val);
+   return ret;
+}
+
+static ssize_t store_u8(struct device *dev, struct device_attribute *devattr,
+   const char *buf, size_t count)
+{
+   struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   int err;
+   u8 val;
+
+   err = kstrtou8(buf, 0, val);
+   if (err  0)
+   return err;
+
+   err = regmap_write(data-regmap, attr-index, val);
+   return err ? : count;
+}
 
 static int nct7802_read_temp(struct nct7802_data *data,
 u8 reg_temp, u8 reg_temp_low, int *temp)
@@ -735,6 +765,11 @@ static SENSOR_DEVICE_ATTR_2(fan3_alarm, S_IRUGO, 
show_alarm, NULL, 0x1a, 2);
 static SENSOR_DEVICE_ATTR_2(fan3_beep, S_IRUGO | S_IWUSR, show_beep, 
store_beep,
0x5b, 2);
 
+/* 7.2.91... Fan Control Output Value */
+static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_u8, 0x60);
+static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_u8, 0x61);
+static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_u8, 0x62);
+
 static struct attribute *nct7802_fan_attrs[] = {
sensor_dev_attr_fan1_input.dev_attr.attr,
sensor_dev_attr_fan1_min.dev_attr.attr,
@@ -773,10 +808,22 @@ static struct attribute_group nct7802_fan_group = {
.is_visible = nct7802_fan_is_visible,
 };
 
+static struct attribute *nct7802_pwm_attrs[] = {
+   sensor_dev_attr_pwm1.dev_attr.attr,
+   sensor_dev_attr_pwm2.dev_attr.attr,
+   sensor_dev_attr_pwm3.dev_attr.attr,
+   NULL
+};
+
+static struct attribute_group nct7802_pwm_group = {
+   .attrs = nct7802_pwm_attrs,
+};
+
 static const struct attribute_group *nct7802_groups[] = {
nct7802_temp_group,
nct7802_in_group,
nct7802_fan_group,
+   nct7802_pwm_group,
NULL
 };
 
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2] hwmon: (nct7802) Add pwm control

2015-07-03 Thread Constantine Shulyupin
Notes:

Some lines intentionally more than 80 characters because wrapping
this lines decreases readability.
The patch was checked with scripts/checkpatch.pl --max-line-length=88

Signed-off-by: Constantine Shulyupin co...@makelinux.com
---
 drivers/hwmon/nct7802.c | 47 +++
 1 file changed, 47 insertions(+)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index afa242d..104d8b9 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -102,6 +102,36 @@ static ssize_t store_temp_type(struct device *dev,
return err ? : count;
 }
 
+static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, 
char *buf)
+{
+   int ret = -1;
+   struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   unsigned int val = 0;
+
+   ret = regmap_read(data-regmap, attr-index, val);
+   if (ret  0)
+   return ret;
+
+   ret = sprintf(buf, %d\n, val);
+   return ret;
+}
+
+static ssize_t store_u8(struct device *dev, struct device_attribute *devattr,
+   const char *buf, size_t count)
+{
+   struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   int err;
+   u8 val;
+
+   err = kstrtou8(buf, 0, val);
+   if (err  0)
+   return err;
+
+   err = regmap_write(data-regmap, attr-index, val);
+   return err ? : count;
+}
 
 static int nct7802_read_temp(struct nct7802_data *data,
 u8 reg_temp, u8 reg_temp_low, int *temp)
@@ -735,6 +765,11 @@ static SENSOR_DEVICE_ATTR_2(fan3_alarm, S_IRUGO, 
show_alarm, NULL, 0x1a, 2);
 static SENSOR_DEVICE_ATTR_2(fan3_beep, S_IRUGO | S_IWUSR, show_beep, 
store_beep,
0x5b, 2);
 
+/* 7.2.91... Fan Control Output Value */
+static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_u8, 0x60);
+static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_u8, 0x61);
+static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_u8, 0x62);
+
 static struct attribute *nct7802_fan_attrs[] = {
sensor_dev_attr_fan1_input.dev_attr.attr,
sensor_dev_attr_fan1_min.dev_attr.attr,
@@ -773,10 +808,22 @@ static struct attribute_group nct7802_fan_group = {
.is_visible = nct7802_fan_is_visible,
 };
 
+static struct attribute *nct7802_pwm_attrs[] = {
+   sensor_dev_attr_pwm1.dev_attr.attr,
+   sensor_dev_attr_pwm2.dev_attr.attr,
+   sensor_dev_attr_pwm3.dev_attr.attr,
+   NULL
+};
+
+static struct attribute_group nct7802_pwm_group = {
+   .attrs = nct7802_pwm_attrs,
+};
+
 static const struct attribute_group *nct7802_groups[] = {
nct7802_temp_group,
nct7802_in_group,
nct7802_fan_group,
+   nct7802_pwm_group,
NULL
 };
 
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] hwmon: (nct7802) Add fan output control

2015-07-02 Thread Constantine Shulyupin
Notes:

Some lines intentionally more than 80 characters because wrapping
this lines decreases readability.
The patch was checked with scripts/checkpatch.pl --max-line-length=88

Following code is not typecasting.
It is inline struct attribute_group definition using compound literal.
(See https://gcc.gnu.org/onlinedocs/gcc-3.2.2/gcc/Compound-Literals.html)

static const struct attribute_group *nct7802_groups[] = {
...
&(const struct attribute_group){ .attrs = fan_output_attributes },
...

Reference:

Nuvoton Hardware Monitoring IC NCT7802Y
7.2.91 Fan Control 1 Output Value
Location : Index 60h

7.2.92 Fan Control 2 Output Value
Location : Index 61h

7.2.93 Fan Control 3 Output Value
Location : Index 62h

Signed-off-by: Constantine Shulyupin 
---
 drivers/hwmon/nct7802.c | 45 +
 1 file changed, 45 insertions(+)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index afa242d..56d3547 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -102,6 +102,38 @@ static ssize_t store_temp_type(struct device *dev,
return err ? : count;
 }
 
+static ssize_t show_dec(struct device *dev, struct device_attribute *devattr, 
char *buf)
+{
+   int ret = -1;
+   struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   unsigned int val = 0;
+
+   ret = regmap_read(data->regmap, attr->index, );
+   if (ret < 0)
+   return ret;
+
+   ret = sprintf(buf, "%d\n", val);
+   return ret;
+}
+
+static ssize_t store_u8(struct device *dev, struct device_attribute *devattr,
+   const char *buf, size_t count)
+{
+   struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   int err;
+   unsigned int val;
+
+   err = kstrtouint(buf, 0, );
+   if (err < 0)
+   return err;
+   if (val > 0xFF)
+   return -EINVAL;
+
+   err = regmap_write(data->regmap, attr->index, val);
+   return err ? : count;
+}
 
 static int nct7802_read_temp(struct nct7802_data *data,
 u8 reg_temp, u8 reg_temp_low, int *temp)
@@ -735,6 +767,11 @@ static SENSOR_DEVICE_ATTR_2(fan3_alarm, S_IRUGO, 
show_alarm, NULL, 0x1a, 2);
 static SENSOR_DEVICE_ATTR_2(fan3_beep, S_IRUGO | S_IWUSR, show_beep, 
store_beep,
0x5b, 2);
 
+/* 7.2.91... Fan Control Output Value */
+static SENSOR_DEVICE_ATTR(fan1_output, S_IRUGO | S_IWUSR, show_dec, store_u8, 
0x60);
+static SENSOR_DEVICE_ATTR(fan2_output, S_IRUGO | S_IWUSR, show_dec, store_u8, 
0x61);
+static SENSOR_DEVICE_ATTR(fan3_output, S_IRUGO | S_IWUSR, show_dec, store_u8, 
0x62);
+
 static struct attribute *nct7802_fan_attrs[] = {
_dev_attr_fan1_input.dev_attr.attr,
_dev_attr_fan1_min.dev_attr.attr,
@@ -773,10 +810,18 @@ static struct attribute_group nct7802_fan_group = {
.is_visible = nct7802_fan_is_visible,
 };
 
+static struct attribute *fan_output_attributes[] = {
+   _dev_attr_fan1_output.dev_attr.attr,
+   _dev_attr_fan2_output.dev_attr.attr,
+   _dev_attr_fan3_output.dev_attr.attr,
+   NULL
+};
+
 static const struct attribute_group *nct7802_groups[] = {
_temp_group,
_in_group,
_fan_group,
+   &(const struct attribute_group){ .attrs = fan_output_attributes },
NULL
 };
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] hwmon: (nct7802) Add fan output control

2015-07-02 Thread Constantine Shulyupin
Notes:

Some lines intentionally more than 80 characters because wrapping
this lines decreases readability.
The patch was checked with scripts/checkpatch.pl --max-line-length=88

Following code is not typecasting.
It is inline struct attribute_group definition using compound literal.
(See https://gcc.gnu.org/onlinedocs/gcc-3.2.2/gcc/Compound-Literals.html)

static const struct attribute_group *nct7802_groups[] = {
...
(const struct attribute_group){ .attrs = fan_output_attributes },
...

Reference:

Nuvoton Hardware Monitoring IC NCT7802Y
7.2.91 Fan Control 1 Output Value
Location : Index 60h

7.2.92 Fan Control 2 Output Value
Location : Index 61h

7.2.93 Fan Control 3 Output Value
Location : Index 62h

Signed-off-by: Constantine Shulyupin co...@makelinux.com
---
 drivers/hwmon/nct7802.c | 45 +
 1 file changed, 45 insertions(+)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index afa242d..56d3547 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -102,6 +102,38 @@ static ssize_t store_temp_type(struct device *dev,
return err ? : count;
 }
 
+static ssize_t show_dec(struct device *dev, struct device_attribute *devattr, 
char *buf)
+{
+   int ret = -1;
+   struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   unsigned int val = 0;
+
+   ret = regmap_read(data-regmap, attr-index, val);
+   if (ret  0)
+   return ret;
+
+   ret = sprintf(buf, %d\n, val);
+   return ret;
+}
+
+static ssize_t store_u8(struct device *dev, struct device_attribute *devattr,
+   const char *buf, size_t count)
+{
+   struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   int err;
+   unsigned int val;
+
+   err = kstrtouint(buf, 0, val);
+   if (err  0)
+   return err;
+   if (val  0xFF)
+   return -EINVAL;
+
+   err = regmap_write(data-regmap, attr-index, val);
+   return err ? : count;
+}
 
 static int nct7802_read_temp(struct nct7802_data *data,
 u8 reg_temp, u8 reg_temp_low, int *temp)
@@ -735,6 +767,11 @@ static SENSOR_DEVICE_ATTR_2(fan3_alarm, S_IRUGO, 
show_alarm, NULL, 0x1a, 2);
 static SENSOR_DEVICE_ATTR_2(fan3_beep, S_IRUGO | S_IWUSR, show_beep, 
store_beep,
0x5b, 2);
 
+/* 7.2.91... Fan Control Output Value */
+static SENSOR_DEVICE_ATTR(fan1_output, S_IRUGO | S_IWUSR, show_dec, store_u8, 
0x60);
+static SENSOR_DEVICE_ATTR(fan2_output, S_IRUGO | S_IWUSR, show_dec, store_u8, 
0x61);
+static SENSOR_DEVICE_ATTR(fan3_output, S_IRUGO | S_IWUSR, show_dec, store_u8, 
0x62);
+
 static struct attribute *nct7802_fan_attrs[] = {
sensor_dev_attr_fan1_input.dev_attr.attr,
sensor_dev_attr_fan1_min.dev_attr.attr,
@@ -773,10 +810,18 @@ static struct attribute_group nct7802_fan_group = {
.is_visible = nct7802_fan_is_visible,
 };
 
+static struct attribute *fan_output_attributes[] = {
+   sensor_dev_attr_fan1_output.dev_attr.attr,
+   sensor_dev_attr_fan2_output.dev_attr.attr,
+   sensor_dev_attr_fan3_output.dev_attr.attr,
+   NULL
+};
+
 static const struct attribute_group *nct7802_groups[] = {
nct7802_temp_group,
nct7802_in_group,
nct7802_fan_group,
+   (const struct attribute_group){ .attrs = fan_output_attributes },
NULL
 };
 
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3] hwmon: (nct7802) add temperature sensor type attribute

2015-07-01 Thread Constantine Shulyupin
From: const 

Sensor type:
3 diode (current mode), MD=1
4 thermistor, MD=2

Reference:
Nuvoton Hardware Monitoring IC NCT7802Y
7.2.32 Mode Selection Register
Location : Index 22h

Signed-off-by: Constantine Shulyupin 
---
 drivers/hwmon/nct7802.c | 72 -
 1 file changed, 60 insertions(+), 12 deletions(-)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index 1341e1f..afa242d 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -49,7 +49,7 @@ static const u8 REG_VOLTAGE_LIMIT_MSB_SHIFT[2][5] = {
 #define REG_VOLTAGE_LOW0x0f
 #define REG_FANCOUNT_LOW   0x13
 #define REG_START  0x21
-#define REG_MODE   0x22
+#define REG_MODE   0x22 /* 7.2.32 Mode Selection Register */
 #define REG_PECI_ENABLE0x23
 #define REG_FAN_ENABLE 0x24
 #define REG_VMON_ENABLE0x25
@@ -66,6 +66,43 @@ struct nct7802_data {
struct mutex access_lock; /* for multi-byte read and write operations */
 };
 
+static ssize_t show_temp_type(struct device *dev, struct device_attribute 
*attr,
+ char *buf)
+{
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+   unsigned int mode;
+   int ret;
+
+   ret = regmap_read(data->regmap, REG_MODE, );
+   if (ret < 0)
+   return ret;
+
+   return sprintf(buf, "%u\n", (mode >> (2 * sattr->index) & 3) + 2);
+}
+
+static ssize_t store_temp_type(struct device *dev,
+  struct device_attribute *attr,
+  const char *buf, size_t count)
+{
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+   unsigned int type;
+   int err;
+
+   err = kstrtouint(buf, 0, );
+   if (err < 0)
+   return err;
+   if (sattr->index == 2 && type != 4) /* RD3 */
+   return -EINVAL;
+   if (type < 3 || type > 4)
+   return -EINVAL;
+   err = regmap_update_bits(data->regmap, REG_MODE,
+   3 << 2 * sattr->index, (type - 2) << 2 * sattr->index);
+   return err ? : count;
+}
+
+
 static int nct7802_read_temp(struct nct7802_data *data,
 u8 reg_temp, u8 reg_temp_low, int *temp)
 {
@@ -377,6 +414,8 @@ store_beep(struct device *dev, struct device_attribute 
*attr, const char *buf,
return err ? : count;
 }
 
+static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR,
+ show_temp_type, store_temp_type, 0);
 static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0x01,
REG_TEMP_LSB);
 static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp,
@@ -386,6 +425,8 @@ static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, 
show_temp,
 static SENSOR_DEVICE_ATTR_2(temp1_crit, S_IRUGO | S_IWUSR, show_temp,
store_temp, 0x3a, 0);
 
+static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR,
+ show_temp_type, store_temp_type, 1);
 static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0x02,
REG_TEMP_LSB);
 static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp,
@@ -395,6 +436,8 @@ static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, 
show_temp,
 static SENSOR_DEVICE_ATTR_2(temp2_crit, S_IRUGO | S_IWUSR, show_temp,
store_temp, 0x3b, 0);
 
+static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR,
+ show_temp_type, store_temp_type, 2);
 static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0x03,
REG_TEMP_LSB);
 static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp,
@@ -475,6 +518,7 @@ static SENSOR_DEVICE_ATTR_2(temp6_beep, S_IRUGO | S_IWUSR, 
show_beep,
store_beep, 0x5c, 5);
 
 static struct attribute *nct7802_temp_attrs[] = {
+   _dev_attr_temp1_type.dev_attr.attr,
_dev_attr_temp1_input.dev_attr.attr,
_dev_attr_temp1_min.dev_attr.attr,
_dev_attr_temp1_max.dev_attr.attr,
@@ -485,7 +529,8 @@ static struct attribute *nct7802_temp_attrs[] = {
_dev_attr_temp1_fault.dev_attr.attr,
_dev_attr_temp1_beep.dev_attr.attr,
 
-   _dev_attr_temp2_input.dev_attr.attr, /* 9 */
+   _dev_attr_temp2_type.dev_attr.attr,  /* 10 */
+   _dev_attr_temp2_input.dev_attr.attr,
_dev_attr_temp2_min.dev_attr.attr,
_dev_attr_temp2_max.dev_attr.attr,
_dev_attr_temp2_crit.dev_attr.attr,
@@ -495,7 +540,8 @@ static struct attribute *nct7802_temp_attrs[] = {
_dev_attr_temp2_fault.dev_attr.attr,
_dev_attr_temp2_beep.dev_attr.

[PATCH v3] hwmon: (nct7802) add temperature sensor type attribute

2015-07-01 Thread Constantine Shulyupin
From: const co...@makelinux.com

Sensor type:
3 diode (current mode), MD=1
4 thermistor, MD=2

Reference:
Nuvoton Hardware Monitoring IC NCT7802Y
7.2.32 Mode Selection Register
Location : Index 22h

Signed-off-by: Constantine Shulyupin co...@makelinux.com
---
 drivers/hwmon/nct7802.c | 72 -
 1 file changed, 60 insertions(+), 12 deletions(-)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index 1341e1f..afa242d 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -49,7 +49,7 @@ static const u8 REG_VOLTAGE_LIMIT_MSB_SHIFT[2][5] = {
 #define REG_VOLTAGE_LOW0x0f
 #define REG_FANCOUNT_LOW   0x13
 #define REG_START  0x21
-#define REG_MODE   0x22
+#define REG_MODE   0x22 /* 7.2.32 Mode Selection Register */
 #define REG_PECI_ENABLE0x23
 #define REG_FAN_ENABLE 0x24
 #define REG_VMON_ENABLE0x25
@@ -66,6 +66,43 @@ struct nct7802_data {
struct mutex access_lock; /* for multi-byte read and write operations */
 };
 
+static ssize_t show_temp_type(struct device *dev, struct device_attribute 
*attr,
+ char *buf)
+{
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+   unsigned int mode;
+   int ret;
+
+   ret = regmap_read(data-regmap, REG_MODE, mode);
+   if (ret  0)
+   return ret;
+
+   return sprintf(buf, %u\n, (mode  (2 * sattr-index)  3) + 2);
+}
+
+static ssize_t store_temp_type(struct device *dev,
+  struct device_attribute *attr,
+  const char *buf, size_t count)
+{
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+   unsigned int type;
+   int err;
+
+   err = kstrtouint(buf, 0, type);
+   if (err  0)
+   return err;
+   if (sattr-index == 2  type != 4) /* RD3 */
+   return -EINVAL;
+   if (type  3 || type  4)
+   return -EINVAL;
+   err = regmap_update_bits(data-regmap, REG_MODE,
+   3  2 * sattr-index, (type - 2)  2 * sattr-index);
+   return err ? : count;
+}
+
+
 static int nct7802_read_temp(struct nct7802_data *data,
 u8 reg_temp, u8 reg_temp_low, int *temp)
 {
@@ -377,6 +414,8 @@ store_beep(struct device *dev, struct device_attribute 
*attr, const char *buf,
return err ? : count;
 }
 
+static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR,
+ show_temp_type, store_temp_type, 0);
 static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0x01,
REG_TEMP_LSB);
 static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp,
@@ -386,6 +425,8 @@ static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, 
show_temp,
 static SENSOR_DEVICE_ATTR_2(temp1_crit, S_IRUGO | S_IWUSR, show_temp,
store_temp, 0x3a, 0);
 
+static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR,
+ show_temp_type, store_temp_type, 1);
 static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0x02,
REG_TEMP_LSB);
 static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp,
@@ -395,6 +436,8 @@ static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, 
show_temp,
 static SENSOR_DEVICE_ATTR_2(temp2_crit, S_IRUGO | S_IWUSR, show_temp,
store_temp, 0x3b, 0);
 
+static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR,
+ show_temp_type, store_temp_type, 2);
 static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0x03,
REG_TEMP_LSB);
 static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp,
@@ -475,6 +518,7 @@ static SENSOR_DEVICE_ATTR_2(temp6_beep, S_IRUGO | S_IWUSR, 
show_beep,
store_beep, 0x5c, 5);
 
 static struct attribute *nct7802_temp_attrs[] = {
+   sensor_dev_attr_temp1_type.dev_attr.attr,
sensor_dev_attr_temp1_input.dev_attr.attr,
sensor_dev_attr_temp1_min.dev_attr.attr,
sensor_dev_attr_temp1_max.dev_attr.attr,
@@ -485,7 +529,8 @@ static struct attribute *nct7802_temp_attrs[] = {
sensor_dev_attr_temp1_fault.dev_attr.attr,
sensor_dev_attr_temp1_beep.dev_attr.attr,
 
-   sensor_dev_attr_temp2_input.dev_attr.attr, /* 9 */
+   sensor_dev_attr_temp2_type.dev_attr.attr,  /* 10 */
+   sensor_dev_attr_temp2_input.dev_attr.attr,
sensor_dev_attr_temp2_min.dev_attr.attr,
sensor_dev_attr_temp2_max.dev_attr.attr,
sensor_dev_attr_temp2_crit.dev_attr.attr,
@@ -495,7 +540,8 @@ static struct attribute *nct7802_temp_attrs[] = {
sensor_dev_attr_temp2_fault.dev_attr.attr

[PATCH v2] hwmon: (nct7802) add temperature sensor type attribute

2015-06-29 Thread Constantine Shulyupin
From: const 

Sensor type:
3 diode (current mode), MD=1
4 thermistor, MD=2

Reference:
Nuvoton Hardware Monitoring IC NCT7802Y
7.2.32 Mode Selection Register
Location : Index 22h

Signed-off-by: Constantine Shulyupin 
---
 drivers/hwmon/nct7802.c | 81 +
 1 file changed, 69 insertions(+), 12 deletions(-)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index 1341e1f..8f0a573 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -49,7 +49,7 @@ static const u8 REG_VOLTAGE_LIMIT_MSB_SHIFT[2][5] = {
 #define REG_VOLTAGE_LOW0x0f
 #define REG_FANCOUNT_LOW   0x13
 #define REG_START  0x21
-#define REG_MODE   0x22
+#define REG_MODE   0x22 /* 7.2.32 Mode Selection Register */
 #define REG_PECI_ENABLE0x23
 #define REG_FAN_ENABLE 0x24
 #define REG_VMON_ENABLE0x25
@@ -66,6 +66,43 @@ struct nct7802_data {
struct mutex access_lock; /* for multi-byte read and write operations */
 };
 
+static ssize_t show_temp_type(struct device *dev, struct device_attribute 
*attr,
+ char *buf)
+{
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+   unsigned int mode;
+   int ret;
+
+   ret = regmap_read(data->regmap, REG_MODE, );
+   if (ret < 0)
+   return ret;
+
+   return sprintf(buf, "%u\n", (mode >> (2 * sattr->index) & 3) + 2);
+}
+
+static ssize_t store_temp_type(struct device *dev,
+  struct device_attribute *attr,
+  const char *buf, size_t count)
+{
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+   unsigned int type;
+   int err;
+
+   err = kstrtouint(buf, 0, );
+   if (err < 0)
+   return err;
+   if (sattr->index == 2 && type != 4) /* RD3 */
+   return -EINVAL;
+   if (type < 3 || type > 4)
+   return -EINVAL;
+   err = regmap_update_bits(data->regmap, REG_MODE,
+   3 << 2 * sattr->index, (type - 2) << 2 * sattr->index);
+   return err ? : count;
+}
+
+
 static int nct7802_read_temp(struct nct7802_data *data,
 u8 reg_temp, u8 reg_temp_low, int *temp)
 {
@@ -377,6 +414,8 @@ store_beep(struct device *dev, struct device_attribute 
*attr, const char *buf,
return err ? : count;
 }
 
+static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR,
+ show_temp_type, store_temp_type, 0);
 static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0x01,
REG_TEMP_LSB);
 static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp,
@@ -386,6 +425,8 @@ static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, 
show_temp,
 static SENSOR_DEVICE_ATTR_2(temp1_crit, S_IRUGO | S_IWUSR, show_temp,
store_temp, 0x3a, 0);
 
+static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR,
+ show_temp_type, store_temp_type, 1);
 static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0x02,
REG_TEMP_LSB);
 static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp,
@@ -395,6 +436,8 @@ static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, 
show_temp,
 static SENSOR_DEVICE_ATTR_2(temp2_crit, S_IRUGO | S_IWUSR, show_temp,
store_temp, 0x3b, 0);
 
+static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR,
+ show_temp_type, store_temp_type, 2);
 static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0x03,
REG_TEMP_LSB);
 static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp,
@@ -475,6 +518,7 @@ static SENSOR_DEVICE_ATTR_2(temp6_beep, S_IRUGO | S_IWUSR, 
show_beep,
store_beep, 0x5c, 5);
 
 static struct attribute *nct7802_temp_attrs[] = {
+   _dev_attr_temp1_type.dev_attr.attr,
_dev_attr_temp1_input.dev_attr.attr,
_dev_attr_temp1_min.dev_attr.attr,
_dev_attr_temp1_max.dev_attr.attr,
@@ -485,7 +529,9 @@ static struct attribute *nct7802_temp_attrs[] = {
_dev_attr_temp1_fault.dev_attr.attr,
_dev_attr_temp1_beep.dev_attr.attr,
 
-   _dev_attr_temp2_input.dev_attr.attr, /* 9 */
+   /* 10: */
+   _dev_attr_temp2_type.dev_attr.attr,
+   _dev_attr_temp2_input.dev_attr.attr,
_dev_attr_temp2_min.dev_attr.attr,
_dev_attr_temp2_max.dev_attr.attr,
_dev_attr_temp2_crit.dev_attr.attr,
@@ -495,7 +541,9 @@ static struct attribute *nct7802_temp_attrs[] = {
_dev_attr_temp2_fault.dev_attr.attr,
_dev_attr_temp2_beep.dev_attr.

[PATCH v2] hwmon: (nct7802) add temperature sensor type attribute

2015-06-29 Thread Constantine Shulyupin
From: const co...@makelinux.com

Sensor type:
3 diode (current mode), MD=1
4 thermistor, MD=2

Reference:
Nuvoton Hardware Monitoring IC NCT7802Y
7.2.32 Mode Selection Register
Location : Index 22h

Signed-off-by: Constantine Shulyupin co...@makelinux.com
---
 drivers/hwmon/nct7802.c | 81 +
 1 file changed, 69 insertions(+), 12 deletions(-)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index 1341e1f..8f0a573 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -49,7 +49,7 @@ static const u8 REG_VOLTAGE_LIMIT_MSB_SHIFT[2][5] = {
 #define REG_VOLTAGE_LOW0x0f
 #define REG_FANCOUNT_LOW   0x13
 #define REG_START  0x21
-#define REG_MODE   0x22
+#define REG_MODE   0x22 /* 7.2.32 Mode Selection Register */
 #define REG_PECI_ENABLE0x23
 #define REG_FAN_ENABLE 0x24
 #define REG_VMON_ENABLE0x25
@@ -66,6 +66,43 @@ struct nct7802_data {
struct mutex access_lock; /* for multi-byte read and write operations */
 };
 
+static ssize_t show_temp_type(struct device *dev, struct device_attribute 
*attr,
+ char *buf)
+{
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+   unsigned int mode;
+   int ret;
+
+   ret = regmap_read(data-regmap, REG_MODE, mode);
+   if (ret  0)
+   return ret;
+
+   return sprintf(buf, %u\n, (mode  (2 * sattr-index)  3) + 2);
+}
+
+static ssize_t store_temp_type(struct device *dev,
+  struct device_attribute *attr,
+  const char *buf, size_t count)
+{
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+   unsigned int type;
+   int err;
+
+   err = kstrtouint(buf, 0, type);
+   if (err  0)
+   return err;
+   if (sattr-index == 2  type != 4) /* RD3 */
+   return -EINVAL;
+   if (type  3 || type  4)
+   return -EINVAL;
+   err = regmap_update_bits(data-regmap, REG_MODE,
+   3  2 * sattr-index, (type - 2)  2 * sattr-index);
+   return err ? : count;
+}
+
+
 static int nct7802_read_temp(struct nct7802_data *data,
 u8 reg_temp, u8 reg_temp_low, int *temp)
 {
@@ -377,6 +414,8 @@ store_beep(struct device *dev, struct device_attribute 
*attr, const char *buf,
return err ? : count;
 }
 
+static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR,
+ show_temp_type, store_temp_type, 0);
 static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0x01,
REG_TEMP_LSB);
 static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp,
@@ -386,6 +425,8 @@ static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, 
show_temp,
 static SENSOR_DEVICE_ATTR_2(temp1_crit, S_IRUGO | S_IWUSR, show_temp,
store_temp, 0x3a, 0);
 
+static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR,
+ show_temp_type, store_temp_type, 1);
 static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0x02,
REG_TEMP_LSB);
 static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp,
@@ -395,6 +436,8 @@ static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, 
show_temp,
 static SENSOR_DEVICE_ATTR_2(temp2_crit, S_IRUGO | S_IWUSR, show_temp,
store_temp, 0x3b, 0);
 
+static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR,
+ show_temp_type, store_temp_type, 2);
 static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0x03,
REG_TEMP_LSB);
 static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp,
@@ -475,6 +518,7 @@ static SENSOR_DEVICE_ATTR_2(temp6_beep, S_IRUGO | S_IWUSR, 
show_beep,
store_beep, 0x5c, 5);
 
 static struct attribute *nct7802_temp_attrs[] = {
+   sensor_dev_attr_temp1_type.dev_attr.attr,
sensor_dev_attr_temp1_input.dev_attr.attr,
sensor_dev_attr_temp1_min.dev_attr.attr,
sensor_dev_attr_temp1_max.dev_attr.attr,
@@ -485,7 +529,9 @@ static struct attribute *nct7802_temp_attrs[] = {
sensor_dev_attr_temp1_fault.dev_attr.attr,
sensor_dev_attr_temp1_beep.dev_attr.attr,
 
-   sensor_dev_attr_temp2_input.dev_attr.attr, /* 9 */
+   /* 10: */
+   sensor_dev_attr_temp2_type.dev_attr.attr,
+   sensor_dev_attr_temp2_input.dev_attr.attr,
sensor_dev_attr_temp2_min.dev_attr.attr,
sensor_dev_attr_temp2_max.dev_attr.attr,
sensor_dev_attr_temp2_crit.dev_attr.attr,
@@ -495,7 +541,9 @@ static struct attribute *nct7802_temp_attrs[] = {
sensor_dev_attr_temp2_fault.dev_attr.attr

[PATCH] hwmon: (nct7802) add temperature sensor type attribute

2015-06-27 Thread Constantine Shulyupin
From: const 

0, 3 - Temperature attributes are hidden
1 - Current mode
2 - Thermistor mode

Reference:
Nuvoton Hardware Monitoring IC NCT7802Y
7.2.32 Mode Selection Register
Location : Index 22h

Signed-off-by: Constantine Shulyupin 
---
 drivers/hwmon/nct7802.c | 53 -
 1 file changed, 52 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index 60cf5d1..444eedf 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -49,7 +49,7 @@ static const u8 REG_VOLTAGE_LIMIT_MSB_SHIFT[2][5] = {
 #define REG_VOLTAGE_LOW0x0f
 #define REG_FANCOUNT_LOW   0x13
 #define REG_START  0x21
-#define REG_MODE   0x22
+#define REG_MODE   0x22 /* 7.2.32 Mode Selection Register */
 #define REG_PECI_ENABLE0x23
 #define REG_FAN_ENABLE 0x24
 #define REG_VMON_ENABLE0x25
@@ -725,7 +725,58 @@ static struct attribute_group nct7802_fan_group = {
.is_visible = nct7802_fan_is_visible,
 };
 
+static ssize_t show_temp_type(struct device *dev, struct device_attribute 
*attr,
+   char *buf)
+{
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+   unsigned int val;
+   int ret;
+
+   ret = regmap_read(data->regmap, REG_MODE, );
+   if (ret < 0)
+   return ret;
+
+   return sprintf(buf, "%u\n", val >> (2 * sattr->index) & 3);
+}
+
+static ssize_t store_temp_type(struct device *dev,
+   struct device_attribute *attr, const char *buf, size_t count)
+{
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+   unsigned int val;
+   int err;
+
+   err = kstrtouint(buf, 0, );
+   if (err < 0)
+   return err;
+   if (val > 0xF)
+   return -EINVAL;
+
+   err = regmap_update_bits(data->regmap, REG_MODE,
+   3 << 2 * sattr->index, val << 2 * sattr->index);
+   sysfs_update_group(>kobj, _temp_group);
+   return err ? : count;
+}
+
+/* 7.2.32 Mode Selection Register */
+static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR,
+   show_temp_type, store_temp_type, 0);
+static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR,
+   show_temp_type, store_temp_type, 1);
+static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR,
+   show_temp_type, store_temp_type, 2);
+
+static struct attribute *general_attributes[] = {
+   _dev_attr_temp1_type.dev_attr.attr,
+   _dev_attr_temp2_type.dev_attr.attr,
+   _dev_attr_temp3_type.dev_attr.attr,
+   NULL
+};
+
 static const struct attribute_group *nct7802_groups[] = {
+   &(const struct attribute_group){ .attrs = general_attributes },
_temp_group,
_in_group,
_fan_group,
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] hwmon: (nct7802) add temperature sensor type attribute

2015-06-27 Thread Constantine Shulyupin
From: const 

0, 3 - Temperature attributes are hidden
1 - Current mode
2 - Thermistor mode

Reference:
Nuvoton Hardware Monitoring IC NCT7802Y
7.2.32 Mode Selection Register
Location : Index 22h

Signed-off-by: Constantine Shulyupin 
---
 drivers/hwmon/nct7802.c | 53 -
 scripts/checkpatch.pl   |  2 +-
 2 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index 60cf5d1..444eedf 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -49,7 +49,7 @@ static const u8 REG_VOLTAGE_LIMIT_MSB_SHIFT[2][5] = {
 #define REG_VOLTAGE_LOW0x0f
 #define REG_FANCOUNT_LOW   0x13
 #define REG_START  0x21
-#define REG_MODE   0x22
+#define REG_MODE   0x22 /* 7.2.32 Mode Selection Register */
 #define REG_PECI_ENABLE0x23
 #define REG_FAN_ENABLE 0x24
 #define REG_VMON_ENABLE0x25
@@ -725,7 +725,58 @@ static struct attribute_group nct7802_fan_group = {
.is_visible = nct7802_fan_is_visible,
 };
 
+static ssize_t show_temp_type(struct device *dev, struct device_attribute 
*attr,
+   char *buf)
+{
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+   unsigned int val;
+   int ret;
+
+   ret = regmap_read(data->regmap, REG_MODE, );
+   if (ret < 0)
+   return ret;
+
+   return sprintf(buf, "%u\n", val >> (2 * sattr->index) & 3);
+}
+
+static ssize_t store_temp_type(struct device *dev,
+   struct device_attribute *attr, const char *buf, size_t count)
+{
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+   unsigned int val;
+   int err;
+
+   err = kstrtouint(buf, 0, );
+   if (err < 0)
+   return err;
+   if (val > 0xF)
+   return -EINVAL;
+
+   err = regmap_update_bits(data->regmap, REG_MODE,
+   3 << 2 * sattr->index, val << 2 * sattr->index);
+   sysfs_update_group(>kobj, _temp_group);
+   return err ? : count;
+}
+
+/* 7.2.32 Mode Selection Register */
+static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR,
+   show_temp_type, store_temp_type, 0);
+static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR,
+   show_temp_type, store_temp_type, 1);
+static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR,
+   show_temp_type, store_temp_type, 2);
+
+static struct attribute *general_attributes[] = {
+   _dev_attr_temp1_type.dev_attr.attr,
+   _dev_attr_temp2_type.dev_attr.attr,
+   _dev_attr_temp3_type.dev_attr.attr,
+   NULL
+};
+
 static const struct attribute_group *nct7802_groups[] = {
+   &(const struct attribute_group){ .attrs = general_attributes },
_temp_group,
_in_group,
_fan_group,
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 4f484ac..bf9a680 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -14,7 +14,7 @@ my $V = '0.32';
 
 use Getopt::Long qw(:config no_auto_abbrev);
 
-my $LINELENGTH=120;
+my $LINELENGTH=80;
 
 my $quiet = 0;
 my $tree = 1;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] hwmon: (nct7802) add temperature sensor type attribute

2015-06-27 Thread Constantine Shulyupin
From: const co...@makelinux.com

0, 3 - Temperature attributes are hidden
1 - Current mode
2 - Thermistor mode

Reference:
Nuvoton Hardware Monitoring IC NCT7802Y
7.2.32 Mode Selection Register
Location : Index 22h

Signed-off-by: Constantine Shulyupin co...@makelinux.com
---
 drivers/hwmon/nct7802.c | 53 -
 scripts/checkpatch.pl   |  2 +-
 2 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index 60cf5d1..444eedf 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -49,7 +49,7 @@ static const u8 REG_VOLTAGE_LIMIT_MSB_SHIFT[2][5] = {
 #define REG_VOLTAGE_LOW0x0f
 #define REG_FANCOUNT_LOW   0x13
 #define REG_START  0x21
-#define REG_MODE   0x22
+#define REG_MODE   0x22 /* 7.2.32 Mode Selection Register */
 #define REG_PECI_ENABLE0x23
 #define REG_FAN_ENABLE 0x24
 #define REG_VMON_ENABLE0x25
@@ -725,7 +725,58 @@ static struct attribute_group nct7802_fan_group = {
.is_visible = nct7802_fan_is_visible,
 };
 
+static ssize_t show_temp_type(struct device *dev, struct device_attribute 
*attr,
+   char *buf)
+{
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+   unsigned int val;
+   int ret;
+
+   ret = regmap_read(data-regmap, REG_MODE, val);
+   if (ret  0)
+   return ret;
+
+   return sprintf(buf, %u\n, val  (2 * sattr-index)  3);
+}
+
+static ssize_t store_temp_type(struct device *dev,
+   struct device_attribute *attr, const char *buf, size_t count)
+{
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+   unsigned int val;
+   int err;
+
+   err = kstrtouint(buf, 0, val);
+   if (err  0)
+   return err;
+   if (val  0xF)
+   return -EINVAL;
+
+   err = regmap_update_bits(data-regmap, REG_MODE,
+   3  2 * sattr-index, val  2 * sattr-index);
+   sysfs_update_group(dev-kobj, nct7802_temp_group);
+   return err ? : count;
+}
+
+/* 7.2.32 Mode Selection Register */
+static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR,
+   show_temp_type, store_temp_type, 0);
+static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR,
+   show_temp_type, store_temp_type, 1);
+static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR,
+   show_temp_type, store_temp_type, 2);
+
+static struct attribute *general_attributes[] = {
+   sensor_dev_attr_temp1_type.dev_attr.attr,
+   sensor_dev_attr_temp2_type.dev_attr.attr,
+   sensor_dev_attr_temp3_type.dev_attr.attr,
+   NULL
+};
+
 static const struct attribute_group *nct7802_groups[] = {
+   (const struct attribute_group){ .attrs = general_attributes },
nct7802_temp_group,
nct7802_in_group,
nct7802_fan_group,
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 4f484ac..bf9a680 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -14,7 +14,7 @@ my $V = '0.32';
 
 use Getopt::Long qw(:config no_auto_abbrev);
 
-my $LINELENGTH=120;
+my $LINELENGTH=80;
 
 my $quiet = 0;
 my $tree = 1;
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] hwmon: (nct7802) add temperature sensor type attribute

2015-06-27 Thread Constantine Shulyupin
From: const co...@makelinux.com

0, 3 - Temperature attributes are hidden
1 - Current mode
2 - Thermistor mode

Reference:
Nuvoton Hardware Monitoring IC NCT7802Y
7.2.32 Mode Selection Register
Location : Index 22h

Signed-off-by: Constantine Shulyupin co...@makelinux.com
---
 drivers/hwmon/nct7802.c | 53 -
 1 file changed, 52 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index 60cf5d1..444eedf 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -49,7 +49,7 @@ static const u8 REG_VOLTAGE_LIMIT_MSB_SHIFT[2][5] = {
 #define REG_VOLTAGE_LOW0x0f
 #define REG_FANCOUNT_LOW   0x13
 #define REG_START  0x21
-#define REG_MODE   0x22
+#define REG_MODE   0x22 /* 7.2.32 Mode Selection Register */
 #define REG_PECI_ENABLE0x23
 #define REG_FAN_ENABLE 0x24
 #define REG_VMON_ENABLE0x25
@@ -725,7 +725,58 @@ static struct attribute_group nct7802_fan_group = {
.is_visible = nct7802_fan_is_visible,
 };
 
+static ssize_t show_temp_type(struct device *dev, struct device_attribute 
*attr,
+   char *buf)
+{
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+   unsigned int val;
+   int ret;
+
+   ret = regmap_read(data-regmap, REG_MODE, val);
+   if (ret  0)
+   return ret;
+
+   return sprintf(buf, %u\n, val  (2 * sattr-index)  3);
+}
+
+static ssize_t store_temp_type(struct device *dev,
+   struct device_attribute *attr, const char *buf, size_t count)
+{
+   struct nct7802_data *data = dev_get_drvdata(dev);
+   struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+   unsigned int val;
+   int err;
+
+   err = kstrtouint(buf, 0, val);
+   if (err  0)
+   return err;
+   if (val  0xF)
+   return -EINVAL;
+
+   err = regmap_update_bits(data-regmap, REG_MODE,
+   3  2 * sattr-index, val  2 * sattr-index);
+   sysfs_update_group(dev-kobj, nct7802_temp_group);
+   return err ? : count;
+}
+
+/* 7.2.32 Mode Selection Register */
+static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR,
+   show_temp_type, store_temp_type, 0);
+static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR,
+   show_temp_type, store_temp_type, 1);
+static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR,
+   show_temp_type, store_temp_type, 2);
+
+static struct attribute *general_attributes[] = {
+   sensor_dev_attr_temp1_type.dev_attr.attr,
+   sensor_dev_attr_temp2_type.dev_attr.attr,
+   sensor_dev_attr_temp3_type.dev_attr.attr,
+   NULL
+};
+
 static const struct attribute_group *nct7802_groups[] = {
+   (const struct attribute_group){ .attrs = general_attributes },
nct7802_temp_group,
nct7802_in_group,
nct7802_fan_group,
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] hwmon: (nct7802) fix visibility of temp3

2015-06-26 Thread Constantine Shulyupin
From: const 

Excerpt from datasheet:
7.2.32 Mode Selection Register
RTD3_MD : 00=Closed , 01=Reserved , 10=Thermistor mode , 11=Voltage sense

Show temp3 only in Thermistor mode

Signed-off-by: Constantine Shulyupin 
---
 drivers/hwmon/nct7802.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index 5418417..dcca5fc 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -649,7 +649,7 @@ static umode_t nct7802_temp_is_visible(struct kobject *kobj,
if (index >= 9 && index < 18 &&
(reg & 0x0c) != 0x04 && (reg & 0x0c) != 0x08)   /* RD2 */
return 0;
-   if (index >= 18 && index < 27 && (reg & 0x30) != 0x10)  /* RD3 */
+   if (index >= 18 && index < 27 && (reg & 0x30) != 0x20)  /* RD3 */
return 0;
if (index >= 27 && index < 35)  /* local */
return attr->mode;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] hwmon: (nct7802) fix visibility of temp3

2015-06-26 Thread Constantine Shulyupin
From: const co...@ctera.com

Excerpt from datasheet:
7.2.32 Mode Selection Register
RTD3_MD : 00=Closed , 01=Reserved , 10=Thermistor mode , 11=Voltage sense

Show temp3 only in Thermistor mode

Signed-off-by: Constantine Shulyupin co...@makelinux.com
---
 drivers/hwmon/nct7802.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index 5418417..dcca5fc 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -649,7 +649,7 @@ static umode_t nct7802_temp_is_visible(struct kobject *kobj,
if (index = 9  index  18 
(reg  0x0c) != 0x04  (reg  0x0c) != 0x08)   /* RD2 */
return 0;
-   if (index = 18  index  27  (reg  0x30) != 0x10)  /* RD3 */
+   if (index = 18  index  27  (reg  0x30) != 0x20)  /* RD3 */
return 0;
if (index = 27  index  35)  /* local */
return attr-mode;
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] fix nct7802_temp_is_visible

2015-06-24 Thread Constantine Shulyupin
From: const 

Fixed registers are invisible only when registers' mode is 0

Signed-off-by: Constantine Shulyupin 
---
 drivers/hwmon/nct7802.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index ec56782..65e40c2 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -541,13 +541,11 @@ static umode_t nct7802_temp_is_visible(struct kobject 
*kobj,
if (err < 0)
return 0;
 
-   if (index < 9 &&
-   (reg & 03) != 0x01 && (reg & 0x03) != 0x02) /* RD1 */
+   if (index < 9 && !(reg & 0x03)) /* RD1 */
return 0;
-   if (index >= 9 && index < 18 &&
-   (reg & 0x0c) != 0x04 && (reg & 0x0c) != 0x08)   /* RD2 */
+   if (index >= 9 && index < 18 && !(reg & 0x0c))  /* RD2 */
return 0;
-   if (index >= 18 && index < 27 && (reg & 0x30) != 0x10)  /* RD3 */
+   if (index >= 18 && index < 27 && !(reg & 0x30)) /* RD3 */
return 0;
if (index >= 27 && index < 35)  /* local */
return attr->mode;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] fix nct7802_temp_is_visible

2015-06-24 Thread Constantine Shulyupin
From: const co...@makelinux.com

Fixed registers are invisible only when registers' mode is 0

Signed-off-by: Constantine Shulyupin co...@makelinux.com
---
 drivers/hwmon/nct7802.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index ec56782..65e40c2 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -541,13 +541,11 @@ static umode_t nct7802_temp_is_visible(struct kobject 
*kobj,
if (err  0)
return 0;
 
-   if (index  9 
-   (reg  03) != 0x01  (reg  0x03) != 0x02) /* RD1 */
+   if (index  9  !(reg  0x03)) /* RD1 */
return 0;
-   if (index = 9  index  18 
-   (reg  0x0c) != 0x04  (reg  0x0c) != 0x08)   /* RD2 */
+   if (index = 9  index  18  !(reg  0x0c))  /* RD2 */
return 0;
-   if (index = 18  index  27  (reg  0x30) != 0x10)  /* RD3 */
+   if (index = 18  index  27  !(reg  0x30)) /* RD3 */
return 0;
if (index = 27  index  35)  /* local */
return attr-mode;
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


  1   2   >